Re: [PATCH] sqlite: retrieve SQL syntax errors

From: Date: Fri, 02 Sep 2005 18:35:11 +0000
Subject: Re: [PATCH] sqlite: retrieve SQL syntax errors
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-18658@lists.php.net to get a copy of this message
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 -----
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:
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).


« previous php.internals (#18658) next »