Skip to content

Commit 7fbe444

Browse files
committed
review
1 parent 9290e97 commit 7fbe444

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

ext/pdo_sqlite/pdo_sqlite.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static int php_sqlite_collation_callback(void *context, int string1_len, const v
379379
if (!Z_ISUNDEF(retval)) {
380380
if (Z_TYPE(retval) != IS_LONG) {
381381
zend_string *func_name = get_active_function_or_method_name();
382-
zend_type_error("%s(): Return value of the callback must be of type int, %s returned",
382+
zend_type_error("%s(): Return value of the collation callback must be of type int, %s returned",
383383
ZSTR_VAL(func_name), zend_zval_value_name(&retval));
384384
zend_string_release(func_name);
385385
return FAILURE;

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,12 +824,18 @@ static int authorizer(void *autharg, int access_type, const char *arg1, const ch
824824
ZEND_ASSERT(EG(exception));
825825
} else {
826826
if (Z_TYPE(retval) != IS_LONG) {
827-
zend_throw_exception_ex(php_pdo_get_exception(), 0, "The authorizer callback returned an invalid type: expected int");
827+
zend_string *func_name = get_active_function_or_method_name();
828+
zend_type_error("%s(): Return value of the authorizer callback must be of type int, %s returned",
829+
ZSTR_VAL(func_name), zend_zval_value_name(&retval));
830+
zend_string_release(func_name);
828831
} else {
829832
authreturn = Z_LVAL(retval);
830833

831834
if (authreturn != SQLITE_OK && authreturn != SQLITE_IGNORE && authreturn != SQLITE_DENY) {
832-
zend_throw_exception_ex(php_pdo_get_exception(), 0, "The authorizer callback returned an invalid value: %d", authreturn);
835+
zend_string *func_name = get_active_function_or_method_name();
836+
zend_value_error("%s(): Return value of the authorizer callback must be one of Pdo\\Sqlite::OK, Pdo\\Sqlite::DENY, or Pdo\\Sqlite::IGNORE",
837+
ZSTR_VAL(func_name));
838+
zend_string_release(func_name);
833839
authreturn = SQLITE_DENY;
834840
}
835841
}

ext/pdo_sqlite/tests/subclasses/pdosqlite_setauthorizer.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ $db->setAuthorizer(function () {
5050

5151
try {
5252
var_dump($db->query('SELECT 1;'));
53-
} catch (\Exception $e) {
53+
} catch (\Error $e) {
5454
echo $e->getMessage() . "\n";
5555
}
5656

@@ -60,7 +60,7 @@ $db->setAuthorizer(function () {
6060

6161
try {
6262
var_dump($db->query('SELECT 1;'));
63-
} catch (\Exception $e) {
63+
} catch (\Error $e) {
6464
echo $e->getMessage() . "\n";
6565
}
6666

@@ -97,5 +97,5 @@ string(28) "sqlite_master,rootpage,main,"
9797
string(4) "READ"
9898
string(28) "sqlite_master,rootpage,main,"
9999
int(1)
100-
The authorizer callback returned an invalid type: expected int
101-
The authorizer callback returned an invalid value: 4200
100+
PDO::query(): Return value of the authorizer callback must be of type int, string returned
101+
PDO::query(): Return value of the authorizer callback must be one of Pdo\Sqlite::OK, Pdo\Sqlite::DENY, or Pdo\Sqlite::IGNORE

0 commit comments

Comments
 (0)