com php-src: Addendum to #73234: Assume param types are nullable: ext/pdo/pdo_sql_parser.c ext/pdo/pdo_sql_parser.r e ext/pdo/tests/pdo_018.phpt
ext/pdo_mysql/test s/pdo_mysql_stmt_bindparam.phpt ext/pdo_mysql/tests /pecl_bug_5802.phpt
| From: | Adam Baratz | Date: | Wed, 12 Oct 2016 15:59:01 +0000 |
| Subject: | com php-src: Addendum to #73234: Assume param types are nullable: ext/pdo/pdo_sql_parser.c ext/pdo/pdo_sql_parser.r e ext/pdo/tests/pdo_018.phpt ext/pdo_mysql/test s/pdo_mysql_stmt_bindparam.phpt ext/pdo_mysql/tests /pecl_bug_5802.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94957@lists.php.net to get a copy of this message | ||
Commit: 0eeb06bf175793296cf7aff3e23e0b7893ef9f30
Author: Adam Baratz <adambaratz@php.net> Wed, 12 Oct 2016 11:58:46 -0400
Parents: cba18b61c1db14490a2f5be734d60028a777eeb5
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0eeb06bf175793296cf7aff3e23e0b7893ef9f30
Log:
Addendum to #73234: Assume param types are nullable
Bugs:
https://bugs.php.net/73234
Changed paths:
M ext/pdo/pdo_sql_parser.c
M ext/pdo/pdo_sql_parser.re
M ext/pdo/tests/pdo_018.phpt
M ext/pdo_mysql/tests/pdo_mysql_stmt_bindparam.phpt
M ext/pdo_mysql/tests/pecl_bug_5802.phpt
Diff:
diff --git a/ext/pdo/pdo_sql_parser.c b/ext/pdo/pdo_sql_parser.c
index 1156d9f...1b2afb9 100644
--- a/ext/pdo/pdo_sql_parser.c
+++ b/ext/pdo/pdo_sql_parser.c
@@ -554,9 +554,15 @@ safe:
}
plc->freeq = 1;
} else {
+ enum pdo_param_type param_type = param->param_type;
zend_string *buf = NULL;
- switch (param->param_type) {
+ /* assume all types are nullable */
+ if (Z_TYPE_P(parameter) == IS_NULL) {
+ param_type = PDO_PARAM_NULL;
+ }
+
+ switch (param_type) {
case PDO_PARAM_BOOL:
plc->quoted = zend_is_true(parameter) ? "1" : "0";
plc->qlen = sizeof("1")-1;
@@ -581,7 +587,7 @@ safe:
buf = zval_get_string(parameter);
if (!stmt->dbh->methods->quoter(stmt->dbh, ZSTR_VAL(buf),
ZSTR_LEN(buf), &plc->quoted, &plc->qlen,
- param->param_type)) {
+ param_type)) {
/* bork */
ret = -1;
strncpy(stmt->error_code, stmt->dbh->error_code, 6);
diff --git a/ext/pdo/pdo_sql_parser.re b/ext/pdo/pdo_sql_parser.re
index 7528830..604ec59 100644
--- a/ext/pdo/pdo_sql_parser.re
+++ b/ext/pdo/pdo_sql_parser.re
@@ -240,9 +240,15 @@ safe:
}
plc->freeq = 1;
} else {
+ enum pdo_param_type param_type = param->param_type;
zend_string *buf = NULL;
- switch (param->param_type) {
+ /* assume all types are nullable */
+ if (Z_TYPE_P(parameter) == IS_NULL) {
+ param_type = PDO_PARAM_NULL;
+ }
+
+ switch (param_type) {
case PDO_PARAM_BOOL:
plc->quoted = zend_is_true(parameter) ? "1" : "0";
plc->qlen = sizeof("1")-1;
@@ -267,7 +273,7 @@ safe:
buf = zval_get_string(parameter);
if (!stmt->dbh->methods->quoter(stmt->dbh, ZSTR_VAL(buf),
ZSTR_LEN(buf), &plc->quoted, &plc->qlen,
- param->param_type)) {
+ param_type)) {
/* bork */
ret = -1;
strncpy(stmt->error_code, stmt->dbh->error_code, 6);
diff --git a/ext/pdo/tests/pdo_018.phpt b/ext/pdo/tests/pdo_018.phpt
index 9bb0d1c..80e3453 100644
--- a/ext/pdo/tests/pdo_018.phpt
+++ b/ext/pdo/tests/pdo_018.phpt
@@ -106,16 +106,22 @@ unset($stmt);
echo "===INSERT===\n";
$stmt = $db->prepare('INSERT INTO test VALUES(:id, :classtype, :val)');
+$stmt->bindParam(':id', $idx);
+$stmt->bindParam(':classtype', $ctype);
+$stmt->bindParam(':val', $val);
foreach($objs as $idx => $obj)
{
$ctype = $ctypes[get_class($obj)];
-
- $stmt->bindValue(':id', $idx);
- $stmt->bindValue(':classtype', $ctype, $ctype === null ? PDO::PARAM_NULL :
PDO::PARAM_INT);
- $stmt->bindValue(':val', method_exists($obj, 'serialize') ?
$obj->serialize() : '');
-
- $stmt->execute();
+ if (method_exists($obj, 'serialize'))
+ {
+ $val = $obj->serialize();
+ }
+ else
+ {
+ $val = '';
+ }
+ $stmt->execute();
}
unset($stmt);
diff --git a/ext/pdo_mysql/tests/pdo_mysql_stmt_bindparam.phpt
b/ext/pdo_mysql/tests/pdo_mysql_stmt_bindparam.phpt
index f5afe2c..70b2f3f 100644
--- a/ext/pdo_mysql/tests/pdo_mysql_stmt_bindparam.phpt
+++ b/ext/pdo_mysql/tests/pdo_mysql_stmt_bindparam.phpt
@@ -51,7 +51,7 @@ MySQLPDOTest::skip();
printf("NULL...\n");
$stmt = $db->prepare('INSERT INTO test(id, label) VALUES (100, ?)');
$label = null;
- if (!$stmt->bindParam(1, $label, PDO::PARAM_NULL))
+ if (!$stmt->bindParam(1, $label))
printf("[%03d + 4] Cannot bind parameter, %s %s\n", $offset,
$stmt->errorCode(), var_export($stmt->errorInfo(), true));
diff --git a/ext/pdo_mysql/tests/pecl_bug_5802.phpt b/ext/pdo_mysql/tests/pecl_bug_5802.phpt
index e8f8a7e..04aa2c9 100644
--- a/ext/pdo_mysql/tests/pecl_bug_5802.phpt
+++ b/ext/pdo_mysql/tests/pecl_bug_5802.phpt
@@ -20,7 +20,7 @@ $stmt->bindParam(':bar', $bar);
$stmt->execute() or var_dump($stmt->errorInfo());
$bar = null;
-$stmt->bindParam(':bar', $bar, PDO::PARAM_NULL);
+$stmt->bindParam(':bar', $bar);
$stmt->execute() or var_dump($stmt->errorInfo());
$bar = 'qaz';