cakephp / cakephp/phinx

Add a check to the PDOAdapter to make sure a statement is returned instead of false

Open
#1,227 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug sqlite
Dominant language
PHP
Stars
4.5k
Forks
884
PR merge metrics
No merged PRs in 30d

Description

Example problematic code:

https://github.com/cakephp/phinx/blob/master/src/Phinx/Db/Adapter/PdoAdapter.php#L186

I had a SQL operation that was failing because the sqlite adapter was inserting too many rows and failing. The only error returned was the completely unhelpful "cannot call operation on boolean", because the prepare statement failed and was returning false. The fix.

$stmt = $this->getConnection()->prepare($sql);
if (!$stmt) {
    $pdo = $this->getConnection();
     throw new \Exception($pdo->errorCode() . implode($pdo->errorInfo()));
}

I'd do a pull request if I knew what sort of exceptions were wanted for this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/Phinx/Db/Adapter/PdoAdapter.php around line 186 and inspect how PDO prepare failures are handled. Review the project's exception conventions before choosing the appropriate exception and include the PDO error information; done means a failed SQLite operation reports its database error instead of attempting to call an operation on false.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sqlite
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.