Skip to content

Commit 64e3e93

Browse files
committed
Further fixes wrt. bug #72668
Not only SQLite3::querySingle(), but also SQLite3::query() and SQLite3Stmt::execute() were affected.
1 parent 0c34d51 commit 64e3e93

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,9 @@ PHP_METHOD(sqlite3, query)
578578
break;
579579
}
580580
default:
581-
php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
581+
if (!EG(exception)) {
582+
php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
583+
}
582584
sqlite3_finalize(stmt_obj->stmt);
583585
stmt_obj->initialised = 0;
584586
zval_dtor(return_value);
@@ -690,7 +692,9 @@ PHP_METHOD(sqlite3, querySingle)
690692
break;
691693
}
692694
default:
693-
php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
695+
if (!EG(exception)) {
696+
php_sqlite3_error(db_obj, "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db));
697+
}
694698
RETVAL_FALSE;
695699
}
696700
sqlite3_finalize(stmt);
@@ -1637,7 +1641,9 @@ PHP_METHOD(sqlite3stmt, execute)
16371641
sqlite3_reset(stmt_obj->stmt);
16381642

16391643
default:
1640-
php_sqlite3_error(stmt_obj->db_obj, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt)));
1644+
if (!EG(exception)) {
1645+
php_sqlite3_error(stmt_obj->db_obj, "Unable to execute statement: %s", sqlite3_errmsg(sqlite3_db_handle(stmt_obj->stmt)));
1646+
}
16411647
zval_dtor(return_value);
16421648
RETURN_FALSE;
16431649
}

ext/sqlite3/tests/bug72668.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Bug #72668 (Spurious warning when exception is thrown in user defined function)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('sqlite3')) die('skip'); ?>
6+
--FILE--
7+
<?php
8+
function my_udf_md5($string) {
9+
throw new \Exception("test exception\n");
10+
}
11+
12+
$db = new SQLite3(':memory:');
13+
$db->createFunction('my_udf_md5', 'my_udf_md5');
14+
15+
try {
16+
$result = $db->query('SELECT my_udf_md5("test")');
17+
var_dump($result);
18+
}
19+
catch(\Exception $e) {
20+
echo "Exception: ".$e->getMessage();
21+
}
22+
try {
23+
$result = $db->querySingle('SELECT my_udf_md5("test")');
24+
var_dump($result);
25+
}
26+
catch(\Exception $e) {
27+
echo "Exception: ".$e->getMessage();
28+
}
29+
$statement = $db->prepare('SELECT my_udf_md5("test")');
30+
try {
31+
$result = $statement->execute();
32+
var_dump($result);
33+
}
34+
catch(\Exception $e) {
35+
echo "Exception: ".$e->getMessage();
36+
}
37+
?>
38+
--EXPECT--
39+
Exception: test exception
40+
Exception: test exception
41+
Exception: test exception

0 commit comments

Comments
 (0)