-
Notifications
You must be signed in to change notification settings - Fork 7.9k
PDO Unconditional errors #6212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDO Unconditional errors #6212
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please apply the bug fix separately (together with corresponding test changes)?
And please also apply at least "Inverse logic in do_fetch() to reduce a level of indentation" separately, as the indentation changes makes it hard to understand the diff. |
19bc7ab
to
1f276da
Compare
ebdc73b
to
9d79ad6
Compare
b03e59e
to
32b0b47
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass ... this is huge
Pushing review changed before the ZPP variadic revert which I'm doing now |
5e67d6d
to
0ae6ecb
Compare
pdo_stmt_verify_mode() never returns FAILURE (aka -1) and thus this path was never hit
Promote a couple of confirmed cases to unconditional error Fix error messages
Promote a couple of confirmed cases to unconditional error Fix error messages
… the ODBC driver And ammend PDO::quote() test to take into account drivers which do not support the feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good
ext/pdo/pdo_stmt.c
Outdated
@@ -1963,6 +2009,8 @@ PHP_METHOD(PDOStatement, debugDumpParams) | |||
ZEND_PARSE_PARAMETERS_NONE(); | |||
|
|||
PHP_STMT_GET_OBJ; | |||
|
|||
/* TODO: Change to assertion? */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not confident it can't fail, e.g. >&-
is used.
@@ -62,6 +63,7 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa | |||
param->name = zend_string_init(name, strlen(name), 0); | |||
return 1; | |||
} | |||
/* TODO Error? */ | |||
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this happens if you use an out of bounds parameter number? I think generally it would make sense for things like this to throw, but we need to be careful that native & emulated prepared statements have the same behavior. I don't know whether both go through this codepath.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think those trigger if the param name/number is not present. I would imagine they both go through this code path as this is something internal to PDO which is not exposed, as all PDO bind param/value methods go through this. Or do emulated prepared statements somehow override the PDO methods?
Indentation Error message Use variadic number position for pdo_stmt_setup_fetch_mode() param cehcks Use values from *args directly instead of preassigning them in pdo_stmt_setup_fetch_mode() Drop todo comment
0ae6ecb
to
e4a13d0
Compare
Indent (again) Drop unnecessary cehck Improve title + SKIPIF for PDO SQLite test
ext/pdo/pdo_dbh.c
Outdated
); | ||
PDO_HANDLE_DBH_ERR(); | ||
RETURN_FALSE; | ||
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be ?array, %s given", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be ?array, %s given", | |
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be of type ?array, %s given", |
ext/pdo/pdo_dbh.c
Outdated
"ctor_args must be an array" | ||
); | ||
PDO_HANDLE_DBH_ERR(); | ||
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be ?array, %s given", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be ?array, %s given", | |
zend_type_error("PDO::ATTR_STATEMENT_CLASS ctor_args must be of type ?array, %s given", |
ext/pdo/pdo_stmt.c
Outdated
/* Figure out correct class */ | ||
if (arg2) { | ||
if (Z_TYPE_P(arg2) != IS_STRING) { | ||
zend_argument_type_error(2, "must be string, %s given", zend_zval_type_name(arg2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_argument_type_error(2, "must be string, %s given", zend_zval_type_name(arg2)); | |
zend_argument_type_error(2, "must be of type string, %s given", zend_zval_type_name(arg2)); |
ext/pdo/pdo_stmt.c
Outdated
if (arg2) { | ||
// Reuse convert_to_long(arg2); ? | ||
if (Z_TYPE_P(arg2) != IS_LONG) { | ||
zend_argument_type_error(2, "must be int, %s given", zend_zval_type_name(arg2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_argument_type_error(2, "must be int, %s given", zend_zval_type_name(arg2)); | |
zend_argument_type_error(2, "must be of type int, %s given", zend_zval_type_name(arg2)); |
ext/pdo/pdo_stmt.c
Outdated
return false; | ||
} | ||
if (Z_TYPE(args[0]) != IS_LONG) { | ||
zend_argument_type_error(arg1_arg_num, "must be int, %s given", zend_zval_type_name(&args[0])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_argument_type_error(arg1_arg_num, "must be int, %s given", zend_zval_type_name(&args[0])); | |
zend_argument_type_error(arg1_arg_num, "must be of type int, %s given", zend_zval_type_name(&args[0])); |
ext/pdo/pdo_stmt.c
Outdated
return false; | ||
} | ||
if (Z_TYPE(args[0]) != IS_STRING) { | ||
zend_argument_type_error(arg1_arg_num, "must be string, %s given", zend_zval_type_name(&args[0])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_argument_type_error(arg1_arg_num, "must be string, %s given", zend_zval_type_name(&args[0])); | |
zend_argument_type_error(arg1_arg_num, "must be of type string, %s given", zend_zval_type_name(&args[0])); |
ext/pdo/pdo_stmt.c
Outdated
retval = FAILURE; | ||
} else if (Z_TYPE(args[1]) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL(args[1]))) { | ||
ZVAL_ARR(&stmt->fetch.cls.ctor_args, zend_array_dup(Z_ARRVAL(args[1]))); | ||
zend_argument_type_error(constructor_arg_num, "must be ?array, %s given", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_argument_type_error(constructor_arg_num, "must be ?array, %s given", | |
zend_argument_type_error(constructor_arg_num, "must be of type ?array, %s given", |
ext/pdo/pdo_stmt.c
Outdated
if (SUCCESS == retval) { | ||
ZVAL_COPY(&stmt->fetch.into, &args[0]); | ||
if (Z_TYPE(args[0]) != IS_OBJECT) { | ||
zend_argument_type_error(arg1_arg_num, "must be object, %s given", zend_zval_type_name(&args[0])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_argument_type_error(arg1_arg_num, "must be object, %s given", zend_zval_type_name(&args[0])); | |
zend_argument_type_error(arg1_arg_num, "must be object, %s given", zend_zval_type_name(&args[0])); |
zend_argument_type_error(arg1_arg_num, "must be object, %s given", zend_zval_type_name(&args[0])); | |
zend_argument_type_error(arg1_arg_num, "must be of type object, %s given", zend_zval_type_name(&args[0])); |
ext/pdo/pdo_stmt.c
Outdated
@@ -1857,18 +1891,27 @@ PHP_METHOD(PDOStatement, setFetchMode) | |||
zval *args = NULL; | |||
uint32_t num_args = 0; | |||
|
|||
/* Support null for constructor arguments for BC */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment now a bit out of place
ext/pdo/pdo_dbh.c
Outdated
#define PDO_LONG_PARAM_CHECK \ | ||
if (Z_TYPE_P(value) != IS_LONG && Z_TYPE_P(value) != IS_STRING && Z_TYPE_P(value) != IS_FALSE && Z_TYPE_P(value) != IS_TRUE) { \ | ||
pdo_raise_impl_error(dbh, NULL, "HY000", "attribute value must be an integer"); \ | ||
PDO_HANDLE_DBH_ERR(); \ | ||
zend_type_error("Attribute value must be int for selected attribute, %s given", zend_zval_type_name(value)); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_type_error("Attribute value must be int for selected attribute, %s given", zend_zval_type_name(value)); \ | |
zend_type_error("Attribute value must be of type int for selected attribute, %s given", zend_zval_type_name(value)); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG assuming CI happy.
A couple of unrelated refactoring changes that I made should be able to land on their own if it makes the PR too noisy.
Used only PDO MySQL for tests so hopefully not too many more drivers complain.