]> granicus.if.org Git - php/commitdiff
Addendum to #73234: Assume param types are nullable
authorAdam Baratz <adambaratz@php.net>
Wed, 12 Oct 2016 15:58:46 +0000 (11:58 -0400)
committerAdam Baratz <adambaratz@php.net>
Wed, 12 Oct 2016 15:59:01 +0000 (11:59 -0400)
ext/pdo/pdo_sql_parser.c
ext/pdo/pdo_sql_parser.re
ext/pdo/tests/pdo_018.phpt
ext/pdo_mysql/tests/pdo_mysql_stmt_bindparam.phpt
ext/pdo_mysql/tests/pecl_bug_5802.phpt

index 1156d9fe03d92dbe189a820778b8c3225374ad19..1b2afb9a6cf462a74a8e064669e47ee8e99c17a2 100644 (file)
@@ -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);
index 7528830dae4121be4ed59c946bc6448af186ceaf..604ec59304cf69f0f9bca2e9af8c8ffe68870f4d 100644 (file)
@@ -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);
index 9bb0d1c7a1521fa0c32f09c24e6367287514bb66..80e34532872f21f8fc4ef1bc1138137456fd2205 100644 (file)
@@ -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);
index f5afe2cc061f0aed6ad95e2bd577354644b4910d..70b2f3fa2505ece3b580dd29904731cb751670a7 100644 (file)
@@ -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));
 
index e8f8a7e4bb3185405b18b8a9676426a81f6d0a90..04aa2c9552a735c07991ec2d9fced29dc2ea3b49 100644 (file)
@@ -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';