[PATCH] sqlite: retrieve SQL syntax errors

php.internals

Nuno Lopes

21 years ago
Hi, I've made a simple patch to allow a user to retrieve the SQL syntax error occured in either sqlite_exec(), sqlite_query() or sqlite_unbuffered_query(). Untill now this wasn't possible, because sqlite_last_error() doesn't handle SQL syntax errors. The patch adds an additional parameter to those 3 functions (OO and non-OO versions) to retrieve the error. Patch: http://mega.ist.utl.pt/~ncpl/php_sqlite.txt Example: <? $idx = sqlite_open(':memory:'); @sqlite_exec($idx, 'SELECT column', $error); echo $error; ?> I hope this can enter in PHP 5.1.0, as it is a fairly simple patch. Nuno P.S.: the patch also fixes a bug in the SQLiteDatabase constructor, where the $errorstr variable wasn't filled (because it wasn't beeing passed by reference).

Ilia A.

21 years ago
I've just tried to replicate the problem and it appears to work fine: $db = sqlite_open(":memory:"); sqlite_exec($db, "SELECT ***"); var_dump(sqlite_error_string(sqlite_last_error($db))); prints "SQL logic error or missing database" Ilia Nuno Lopes wrote:

Nuno Lopes

21 years ago
OK, I probably didn't explain the problem well. So let me separate the problems: the bug: <? $idx = new SQLiteDatabase(':memory:', 0, $errstr); echo $errstr; ?> prints: Notice: Undefined variable: errstr in /cvs/php-src/sqlite.php on line 2 Notice: Undefined variable: errstr in /cvs/php-src/sqlite.php on line 3 ----- the "feature request": <? $db = sqlite_open(":memory:"); sqlite_exec($db, "SELECT column"); var_dump(sqlite_error_string(sqlite_last_error($db))); ?> prints "SQL logic error or missing database", but you don't have a clue of what error is. with my patch, you can retrieve the error (in the additional variable) you get in the Warning message ("no such column: column"). Nuno ----- Original Message -----

Ilia A.

21 years ago
> the "feature request": > > <? > $db = sqlite_open(":memory:"); > sqlite_exec($db, "SELECT column"); > var_dump(sqlite_error_string(sqlite_last_error($db))); > ?> > > prints "SQL logic error or missing database", but you don't have a clue > of what error is. > with my patch, you can retrieve the error (in the additional variable) > you get in the Warning message ("no such column: column").
Aha, I see... that is indeed useful. +1 Ilia

Jani Taskinen

21 years ago
On Fri, 2 Sep 2005, Ilia Alshanetsky wrote:
>> the "feature request": >> >> <? >> $db = sqlite_open(":memory:"); >> sqlite_exec($db, "SELECT column"); >> var_dump(sqlite_error_string(sqlite_last_error($db))); >> ?> >> >> prints "SQL logic error or missing database", but you don't have a clue >> of what error is. >> with my patch, you can retrieve the error (in the additional variable) >> you get in the Warning message ("no such column: column"). > > Aha, I see... that is indeed useful. +1
Just commit it.. --Jani

Nuno Lopes

20 years ago
> > the "feature request": >> >> <? >> $db = sqlite_open(":memory:"); >> sqlite_exec($db, "SELECT column"); >> var_dump(sqlite_error_string(sqlite_last_error($db))); >> ?> >> >> prints "SQL logic error or missing database", but you don't have a clue >> of what error is. >> with my patch, you can retrieve the error (in the additional variable) >> you get in the Warning message ("no such column: column"). > > Aha, I see... that is indeed useful. +1 > > Ilia
I don't have php-src karma, so can you please commit the patch? Thanks, Nuno P.S.: http://mega.ist.utl.pt/~ncpl/php_sqlite.txt

Ilia A.

20 years ago
Applied to CVS, thanks for the patch and the reminder :-) Ilia

Nuno Lopes

20 years ago
Thanks for reviewing and applying my patch ;) Nuno ----- Original Message -----