When a driver reports an error during EVT_ALLOC (and some over EVTs),
make sure we handle it as usual, i.e. warn or throw.

This requires some adjustments in PDO PgSQL to stop manually doing
this through an impl error.

Unfortunately the PDO PgSQL error messages regress because of this,
as they now include a completely arbitrary error code. There doesn't
seem to be an ability to skip it right now.
This commit is contained in:
Nikita Popov 2020-12-10 15:51:17 +01:00
parent dde5572937
commit 15b51a215a
9 changed files with 21 additions and 12 deletions

2
NEWS
View file

@ -52,6 +52,8 @@ PHP NEWS
. Fixed bug #76815 (PDOStatement cannot be GCed/closeCursor-ed when a . Fixed bug #76815 (PDOStatement cannot be GCed/closeCursor-ed when a
PROCEDURE resultset SIGNAL). (Nikita) PROCEDURE resultset SIGNAL). (Nikita)
. Fixed bug #79872 (Can't execute query with pending result sets). (Nikita) . Fixed bug #79872 (Can't execute query with pending result sets). (Nikita)
. Fixed bug #79131 (PDO does not throw an exception when parameter values are
missing). (Nikita)
- Phar: - Phar:
. Fixed bug #73809 (Phar Zip parse crash - mmap fail). (cmb) . Fixed bug #73809 (Phar Zip parse crash - mmap fail). (cmb)

View file

@ -341,8 +341,8 @@ static bool really_register_bound_param(struct pdo_bound_param_data *param, pdo_
* a reference to param, as it resides in transient storage only * a reference to param, as it resides in transient storage only
* at this time. */ * at this time. */
if (stmt->methods->param_hook) { if (stmt->methods->param_hook) {
if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_NORMALIZE if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_NORMALIZE)) {
)) { PDO_HANDLE_STMT_ERR();
if (param->name) { if (param->name) {
zend_string_release_ex(param->name, 0); zend_string_release_ex(param->name, 0);
param->name = NULL; param->name = NULL;
@ -367,8 +367,8 @@ static bool really_register_bound_param(struct pdo_bound_param_data *param, pdo_
/* tell the driver we just created a parameter */ /* tell the driver we just created a parameter */
if (stmt->methods->param_hook) { if (stmt->methods->param_hook) {
if (!stmt->methods->param_hook(stmt, pparam, PDO_PARAM_EVT_ALLOC if (!stmt->methods->param_hook(stmt, pparam, PDO_PARAM_EVT_ALLOC)) {
)) { PDO_HANDLE_STMT_ERR();
/* undo storage allocation; the hash will free the parameter /* undo storage allocation; the hash will free the parameter
* name if required */ * name if required */
if (pparam->name) { if (pparam->name) {
@ -479,6 +479,7 @@ PHP_METHOD(PDOStatement, execute)
} }
if (ret && !dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_POST)) { if (ret && !dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_POST)) {
PDO_HANDLE_STMT_ERR();
RETURN_FALSE; RETURN_FALSE;
} }

View file

@ -64,7 +64,7 @@ require __DIR__ . '/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory(); $db = MySQLPDOTest::factory();
$db->exec('DROP TABLE IF EXISTS test'); $db->exec('DROP TABLE IF EXISTS test');
?> ?>
--EXPECT-- --EXPECTF--
array(1) { array(1) {
[0]=> [0]=>
array(2) { array(2) {
@ -75,6 +75,8 @@ array(1) {
} }
} }
now the same with native PS now the same with native PS
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in %s on line %d
[005] Execute has failed, 'HY093' array ( [005] Execute has failed, 'HY093' array (
0 => 'HY093', 0 => 'HY093',
1 => NULL, 1 => NULL,

View file

@ -72,7 +72,8 @@ require __DIR__ . '/mysql_pdo_test.inc';
$db = MySQLPDOTest::factory(); $db = MySQLPDOTest::factory();
$db->exec('DROP TABLE IF EXISTS test'); $db->exec('DROP TABLE IF EXISTS test');
?> ?>
--EXPECT-- --EXPECTF--
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in %s on line %d
[003] Execute has failed, 'HY093' array ( [003] Execute has failed, 'HY093' array (
0 => 'HY093', 0 => 'HY093',
1 => NULL, 1 => NULL,

View file

@ -282,7 +282,8 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
ZEND_ATOL(param->paramno, namevar + 1); ZEND_ATOL(param->paramno, namevar + 1);
param->paramno--; param->paramno--;
} else { } else {
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", ZSTR_VAL(param->name)); pdo_pgsql_error_stmt_msg(
stmt, PGRES_FATAL_ERROR, "HY093", ZSTR_VAL(param->name));
return 0; return 0;
} }
} }
@ -294,7 +295,8 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
return 1; return 1;
} }
if (!zend_hash_index_exists(stmt->bound_param_map, param->paramno)) { if (!zend_hash_index_exists(stmt->bound_param_map, param->paramno)) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined"); pdo_pgsql_error_stmt_msg(
stmt, PGRES_FATAL_ERROR, "HY093", "parameter was not defined");
return 0; return 0;
} }
case PDO_PARAM_EVT_EXEC_POST: case PDO_PARAM_EVT_EXEC_POST:

View file

@ -79,7 +79,8 @@ extern int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const
#define pdo_pgsql_error(d,e,z) _pdo_pgsql_error(d, NULL, e, z, NULL, __FILE__, __LINE__) #define pdo_pgsql_error(d,e,z) _pdo_pgsql_error(d, NULL, e, z, NULL, __FILE__, __LINE__)
#define pdo_pgsql_error_msg(d,e,m) _pdo_pgsql_error(d, NULL, e, NULL, m, __FILE__, __LINE__) #define pdo_pgsql_error_msg(d,e,m) _pdo_pgsql_error(d, NULL, e, NULL, m, __FILE__, __LINE__)
#define pdo_pgsql_error_stmt(s,e,z) _pdo_pgsql_error(s->dbh, s, e, z, NULL, __FILE__, __LINE__) #define pdo_pgsql_error_stmt(s,e,z) _pdo_pgsql_error(s->dbh, s, e, z, NULL, __FILE__, __LINE__)
#define pdo_pgsql_error_stmt_msg(s,e,m) _pdo_pgsql_error(s->dbh, s, e, NULL, m, __FILE__, __LINE__) #define pdo_pgsql_error_stmt_msg(stmt, e, sqlstate, msg) \
_pdo_pgsql_error(stmt->dbh, stmt, e, sqlstate, msg, __FILE__, __LINE__)
extern const struct pdo_stmt_methods pgsql_stmt_methods; extern const struct pdo_stmt_methods pgsql_stmt_methods;

View file

@ -19,6 +19,6 @@ var_dump($stmt->bindValue(':test', 1, PDO::PARAM_INT));
echo "Done\n"; echo "Done\n";
?> ?>
--EXPECTF-- --EXPECTF--
Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: :test in %sbug36727.php on line %d Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: 7 :test in %s on line %d
bool(false) bool(false)
Done Done

View file

@ -39,5 +39,5 @@ $test();
?> ?>
--EXPECT-- --EXPECT--
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined SQLSTATE[HY093]: Invalid parameter number: 7 parameter was not defined
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

View file

@ -18,4 +18,4 @@ $statement->execute([ 'test', 'test', 'test' ]);
?> ?>
--EXPECTF-- --EXPECTF--
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in %sbug71573.php on line %d Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: 7 parameter was not defined in %s on line %d