From: hugo dot pl at gmail dot com
Operating system: Linux
PHP version: 5.0.2
PHP Bug Type: SQLite related
Bug description: SQLite OO interface with Exceptions (patch included)
Description:
------------
Hi, (english is not my natural language)
I'm sending a patch to SQLite module (is here the right place to do it?).
It's add Exceptions to OO interface of SQLite module when a error occur
executing a query.
Affected methods:
query()
singleQuery()
unbufferedQuery()
arrayQuery()
If any error occur when executing the query a exception of type
SQLiteException is throw. The message of the exeception is the same
returned from SQLite, library (description of the sql error).
I made this patch because I'm doing a frontend to SQLite and I need
descriptive message about errors on SQL queries and I can't find how to
catch the query syntax error messages trowed by SQLite library (actually
this messages are only show in warning messages).
Ex.:
If a do the query:
$db->query("SELECT FROM anytable");
I cant catch the SQLite message saying that exists a syntax error near
"FROM anytable"... with tha actual interface I can get only the generic
message "SQL logic error or missing database" returned by
sqlite_error_string(sqlite_last_error()).
I think that the function sqlite_last_error() should return a error string
like mysql_error(), not a error code, because the error string returned by
sqlite_error_string is not too usefull,
I'm send the fle ext/sqlite/sqlite.c with modification based on PHP-5.0.2,
if anyone accept this patch, nice, will be my first patch, otherwise I wish
at least hear another ideia to solve the "problem".
Reproduce code:
---------------
<pre>
<?php
// Patch test-case
// our bugged query
$query = 'SELASDF sdaF SDaf ';
// Test OO interface (all *query methods must trow a exception)
$db = new SQLiteDatabase("teste.db");
$aMethods = array('query', 'singleQuery', 'unbufferedQuery',
'arrayQuery');
$n = count($aMethods);
echo "Testing OO interface...\n";
foreach ($aMethods as $method)
{
try
{
eval('@$db->'.$method.'($query);');
echo '$db::', $method, "(); // fail!\n";
}
catch (SQLiteException $e)
{
echo '$db::', $method, "(); // Ok!\n";
}
try
{
eval('$r = @$db->'.$method.'($query);');
echo '$r = $db::', $method, "(); // fail!\n";
}
catch (SQLiteException $e)
{
echo '$r = $db::', $method, "(); // Ok!\n";
}
}
echo "All done.... :)\n";
?>
Expected result:
----------------
Testing OO interface...
$db::query(); // Ok!
$r = $db::query(); // Ok!
$db::singleQuery(); // Ok!
$r = $db::singleQuery(); // Ok!
$db::unbufferedQuery(); // Ok!
$r = $db::unbufferedQuery(); // Ok!
$db::arrayQuery(); // Ok!
$r = $db::arrayQuery(); // Ok!
All done.... :)
Actual result:
--------------
Testing OO interface...
$db::query(); // fail!
$r = $db::query(); // fail!
$db::singleQuery(); // fail!
$r = $db::singleQuery(); // fail!
$db::unbufferedQuery(); // fail!
$r = $db::unbufferedQuery(); // fail!
$db::arrayQuery(); // fail!
$r = $db::arrayQuery(); // fail!
All done.... :)
--
Edit bug report at http://bugs.php.net/?id=31342&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31342&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=31342&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=31342&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31342&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31342&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31342&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31342&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31342&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31342&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31342&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=31342&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=31342&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31342&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31342&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31342&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31342&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31342&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31342&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31342&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31342&r=mysqlcfg