Add a check to the PDOAdapter to make sure a statement is returned instead of false
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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