mirror of
https://github.com/php/php-src.git
synced 2024-11-24 10:24:11 +08:00
Allow drivers to omit error code
And thus generate error messages that match what PDO emulation would generate. This fixes the error message regression from the previous commit.
This commit is contained in:
parent
15b51a215a
commit
a5527577e7
@ -155,7 +155,8 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */
|
||||
if (dbh->methods->fetch_err(dbh, stmt, &info)) {
|
||||
zval *item;
|
||||
|
||||
if ((item = zend_hash_index_find(Z_ARRVAL(info), 1)) != NULL) {
|
||||
if ((item = zend_hash_index_find(Z_ARRVAL(info), 1)) != NULL
|
||||
&& Z_TYPE_P(item) == IS_LONG) {
|
||||
native_code = Z_LVAL_P(item);
|
||||
}
|
||||
|
||||
@ -165,8 +166,10 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */
|
||||
}
|
||||
}
|
||||
|
||||
if (supp) {
|
||||
if (native_code && supp) {
|
||||
message = strpprintf(0, "SQLSTATE[%s]: %s: " ZEND_LONG_FMT " %s", *pdo_err, msg, native_code, supp);
|
||||
} else if (supp) {
|
||||
message = strpprintf(0, "SQLSTATE[%s]: %s: %s", *pdo_err, msg, supp);
|
||||
} else {
|
||||
message = strpprintf(0, "SQLSTATE[%s]: %s", *pdo_err, msg);
|
||||
}
|
||||
|
@ -114,6 +114,10 @@ static int pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in
|
||||
|
||||
if (einfo->errcode) {
|
||||
add_next_index_long(info, einfo->errcode);
|
||||
} else {
|
||||
add_next_index_null(info);
|
||||
}
|
||||
if (einfo->errmsg) {
|
||||
add_next_index_string(info, einfo->errmsg);
|
||||
}
|
||||
|
||||
|
@ -282,8 +282,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
|
||||
ZEND_ATOL(param->paramno, namevar + 1);
|
||||
param->paramno--;
|
||||
} else {
|
||||
pdo_pgsql_error_stmt_msg(
|
||||
stmt, PGRES_FATAL_ERROR, "HY093", ZSTR_VAL(param->name));
|
||||
pdo_pgsql_error_stmt_msg(stmt, 0, "HY093", ZSTR_VAL(param->name));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -295,8 +294,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
|
||||
return 1;
|
||||
}
|
||||
if (!zend_hash_index_exists(stmt->bound_param_map, param->paramno)) {
|
||||
pdo_pgsql_error_stmt_msg(
|
||||
stmt, PGRES_FATAL_ERROR, "HY093", "parameter was not defined");
|
||||
pdo_pgsql_error_stmt_msg(stmt, 0, "HY093", "parameter was not defined");
|
||||
return 0;
|
||||
}
|
||||
case PDO_PARAM_EVT_EXEC_POST:
|
||||
|
@ -19,6 +19,6 @@ var_dump($stmt->bindValue(':test', 1, PDO::PARAM_INT));
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: 7 :test in %s on line %d
|
||||
Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: :test in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
|
@ -39,5 +39,5 @@ $test();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
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
|
||||
|
@ -18,4 +18,4 @@ $statement->execute([ 'test', 'test', 'test' ]);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: 7 parameter was not defined in %s on line %d
|
||||
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in %s on line %d
|
||||
|
Loading…
Reference in New Issue
Block a user