Skip to content

Commit

Permalink
Further fixes wrt. bug #72668
Browse files Browse the repository at this point in the history
Not only SQLite3::querySingle(), but also SQLite3::query() and
SQLite3Stmt::execute() were affected.
  • Loading branch information
cmb69 committed Jul 25, 2016
1 parent 0c34d51 commit 64e3e93
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ PHP_METHOD(sqlite3, query)
break;
}
default:
php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
if (!EG(exception)) {
php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
}
sqlite3_finalize(stmt_obj->stmt);
stmt_obj->initialised = 0;
zval_dtor(return_value);
Expand Down Expand Up @@ -690,7 +692,9 @@ PHP_METHOD(sqlite3, querySingle)
break;
}
default:
php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
if (!EG(exception)) {
php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
}
RETVAL_FALSE;
}
sqlite3_finalize(stmt);
Expand Down Expand Up @@ -1637,7 +1641,9 @@ PHP_METHOD(sqlite3stmt, execute)
sqlite3_reset(stmt_obj->stmt);

default:
php_sqlite3_error(stmt_obj->db_obj, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt)));
if (!EG(exception)) {
php_sqlite3_error(stmt_obj->db_obj, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt)));
}
zval_dtor(return_value);
RETURN_FALSE;
}
Expand Down
41 changes: 41 additions & 0 deletions ext/sqlite3/tests/bug72668.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
Bug #72668 (Spurious warning when exception is thrown in user defined function)
--SKIPIF--
<?php
if (!extension_loaded('sqlite3')) die('skip'); ?>
--FILE--
<?php
function my_udf_md5($string) {
throw new \Exception("test exception\n");
}

$db = new SQLite3(':memory:');
$db->createFunction('my_udf_md5', 'my_udf_md5');

try {
$result = $db->query('SELECT my_udf_md5("test")');
var_dump($result);
}
catch(\Exception $e) {
echo "Exception: ".$e->getMessage();
}
try {
$result = $db->querySingle('SELECT my_udf_md5("test")');
var_dump($result);
}
catch(\Exception $e) {
echo "Exception: ".$e->getMessage();
}
$statement = $db->prepare('SELECT my_udf_md5("test")');
try {
$result = $statement->execute();
var_dump($result);
}
catch(\Exception $e) {
echo "Exception: ".$e->getMessage();
}
?>
--EXPECT--
Exception: test exception
Exception: test exception
Exception: test exception

0 comments on commit 64e3e93

Please sign in to comment.