From: Ulf Wendel Date: Fri, 4 Jan 2008 18:17:13 +0000 (+0000) Subject: Added: X-Git-Tag: RELEASE_2_0_0a1~1031 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d435cd76dfff66bdad19b85bc0d7b8d54ed1696f;p=php Added: mysqli_fetch_assoc_zerofill.phpt checks for UNSIGNED ZEROFILL mysqli_stmt_bind_result_zerofill.phpt checks for UNSIGNED ZEROFILL mysqli_stmt_bing_call_user_func.phpt Needs to be refined once http://bugs.php.net/bug.php?id=43568 has been closed and a decision has been made on call_user_func_array(). There seems to be a BC break between 5_2 -> 5_3 . Johannes has an eye on it Modified: mysqli_change_user_insert_id.phpt skip test for buggy MySQL Server versions mysqli_insert_id.phpt added additional checks --- diff --git a/ext/mysqli/tests/mysqli_change_user_insert_id.phpt b/ext/mysqli/tests/mysqli_change_user_insert_id.phpt index 243eab039f..51ff25f8a0 100644 --- a/ext/mysqli/tests/mysqli_change_user_insert_id.phpt +++ b/ext/mysqli/tests/mysqli_change_user_insert_id.phpt @@ -5,6 +5,15 @@ mysqli_change_user() - LAST_INSERT_ID() require_once('skipif.inc'); require_once('skipifemb.inc'); require_once('skipifconnectfailure.inc'); +require_once('connect.inc'); +if (!$IS_MYSQLND) { + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die("skip Can't test server version, might hit known bug http://bugs.mysql.com/bug.php?id=30472"); + if (mysqli_get_client_version($link) < 50123) + /* TODO - check wich version got the patch */ + die(sprintf("skip libmysql %s should have bug http://bugs.mysql.com/bug.php?id=30472", mysqli_get_client_version($link))); + mysqli_close($link); +} ?> --FILE-- +--FILE-- +length; + if ($length > strlen($insert)) { + + $expected = str_repeat('0', $length - strlen($insert)); + $expected .= $insert; + if ($expected !== $row['zero']) { + printf("[%03d] Expecting '%s' got '%s'\n", $offset, $expected, $row['zero']); + return false; + } + + } else if ($length <= 1) { + printf("[%03d] Length reported is too small to run test\n", $offset); + return false; + } + + return true; + } + + zerofill(2, $link, 'TINYINT'); + zerofill(3, $link, 'SMALLINT'); + zerofill(4, $link, 'MEDIUMINT'); + zerofill(5, $link, 'INT'); + zerofill(6, $link, 'INTEGER'); + zerofill(7, $link, 'BIGINT'); + zerofill(8, $link, 'FLOAT'); + zerofill(9, $link, 'DOUBLE'); + zerofill(10, $link, 'DOUBLE PRECISION'); + zerofill(11, $link, 'DECIMAL'); + zerofill(12, $link, 'DEC'); + + mysqli_close($link); + + print "done!"; +?> +--EXPECTF-- +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_insert_id.phpt b/ext/mysqli/tests/mysqli_insert_id.phpt index 26cc2c670b..3984326722 100644 --- a/ext/mysqli/tests/mysqli_insert_id.phpt +++ b/ext/mysqli/tests/mysqli_insert_id.phpt @@ -1,9 +1,9 @@ --TEST-- mysqli_insert_id() --SKIPIF-- - --FILE-- @@ -104,7 +104,7 @@ require_once('skipifconnectfailure.inc'); mysqli_free_result($res); if ($next_id != $row['last_id']) { - printf("[018] Something is wrong, check manually. Expecting %s got %s.\n", + printf("[019] Something is wrong, check manually. Expecting %s got %s.\n", $next_id, $row['last_id']); break; } @@ -112,6 +112,18 @@ require_once('skipifconnectfailure.inc'); mysqli_query($link, "UNLOCK TABLE test"); } + if (!$res = mysqli_query($link, "INSERT INTO test(id, label) VALUES (1000, 'a')")) { + printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + if (1000 !== ($tmp = mysqli_insert_id($link))) + printf("[021] Expecting int/1000, got %s/%s\n", gettype($tmp), $tmp); + + if (!$res = mysqli_query($link, "INSERT INTO test(label) VALUES ('b'), ('c')")) { + printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + if (1000 >= ($tmp = mysqli_insert_id($link))) + printf("[023] Expecting int/>1000, got %s/%s\n", gettype($tmp), $tmp); + mysqli_close($link); var_dump(mysqli_insert_id($link)); diff --git a/ext/mysqli/tests/mysqli_stmt_bind_param_call_user_func.phpt b/ext/mysqli/tests/mysqli_stmt_bind_param_call_user_func.phpt new file mode 100644 index 0000000000..ce469428f5 --- /dev/null +++ b/ext/mysqli/tests/mysqli_stmt_bind_param_call_user_func.phpt @@ -0,0 +1,398 @@ +--TEST-- +mysqli_stmt_bind_param used with call_user_func_array() (see also bug #43568) +--SKIPIF-- + +--FILE-- + &$stmt, + 1 => &$types, + 2 => &$id + ); + if (!call_user_func_array('mysqli_stmt_bind_param', $params)) + printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = $label = null; + if (!mysqli_stmt_bind_result($stmt, $id, $label) || + (true !== mysqli_stmt_fetch($stmt))) + printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + print "Call user func, procedural, using references for everything\n"; + var_dump($id); + var_dump($label); + + mysqli_stmt_close($stmt); + if (!$stmt = mysqli_stmt_init($link)) + printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) + printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $types = 'i'; + $id = 1; + $params = array( + 0 => &$types, + 1 => &$id + ); + if (!call_user_func_array(array($stmt, 'bind_param'), $params)) + printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = $label = null; + if (!mysqli_stmt_bind_result($stmt, $id, $label) || + (true !== mysqli_stmt_fetch($stmt))) + printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + print "Call user func, object oriented, using references for everything\n"; + var_dump($id); + var_dump($label); + + mysqli_stmt_close($stmt); + if (!$stmt = mysqli_stmt_init($link)) + printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) + printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $types = 'i'; + $id = 1; + $params = array( + 0 => $types, + 1 => &$id + ); + if (!call_user_func_array(array($stmt, 'bind_param'), $params)) + printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = $label = null; + if (!mysqli_stmt_bind_result($stmt, $id, $label) || + (true !== mysqli_stmt_fetch($stmt))) + printf("[019] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + print "Call user func, object oriented, using variable for types. using references for bound parameter\n"; + var_dump($id); + var_dump($label); + + mysqli_stmt_close($stmt); + if (!$stmt = mysqli_stmt_init($link)) + printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) + printf("[021] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = 1; + $params = array( + 0 => 'i', + 1 => &$id + ); + if (!call_user_func_array(array($stmt, 'bind_param'), $params)) + printf("[022] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[023] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = $label = null; + if (!mysqli_stmt_bind_result($stmt, $id, $label) || + (true !== mysqli_stmt_fetch($stmt))) + printf("[024] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + print "Call user func, object oriented, using constant for types. using references for bound parameter\n"; + var_dump($id); + var_dump($label); + + mysqli_stmt_close($stmt); + if (!$stmt = mysqli_stmt_init($link)) + printf("[025] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) + printf("[026] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $types = 'i'; + $id = 1; + $params = array( + 0 => &$stmt, + 1 => $types, + 2 => &$id + ); + if (!call_user_func_array('mysqli_stmt_bind_param', $params)) + printf("[027] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[028] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = $label = null; + if (!mysqli_stmt_bind_result($stmt, $id, $label) || + (true !== mysqli_stmt_fetch($stmt))) + printf("[029] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + print "Call user func, procedural, using references for everything but using variable for types\n"; + var_dump($id); + var_dump($label); + + mysqli_stmt_close($stmt); + if (!$stmt = mysqli_stmt_init($link)) + printf("[025] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) + printf("[026] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $types = 'i'; + $id = 1; + $params = array( + 0 => $stmt, + 1 => $types, + 2 => &$id + ); + if (!call_user_func_array('mysqli_stmt_bind_param', $params)) + printf("[027] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[028] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = $label = null; + if (!mysqli_stmt_bind_result($stmt, $id, $label) || + (true !== mysqli_stmt_fetch($stmt))) + printf("[029] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + print "Call user func, procedural, using references for bound parameter, using variables for resource and types\n"; + var_dump($id); + var_dump($label); + + mysqli_stmt_close($stmt); + if (!$stmt = mysqli_stmt_init($link)) + printf("[030] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) + printf("[031] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $types = 'i'; + $id = 1; + $params = array( + 0 => $stmt, + 1 => $types, + 2 => &$id + ); + if (!call_user_func_array('mysqli_stmt_bind_param', $params)) + printf("[032] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[033] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = $label = null; + if (!mysqli_stmt_bind_result($stmt, $id, $label) || + (true !== mysqli_stmt_fetch($stmt))) + printf("[034] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + print "Call user func, procedural, using references for bound parameter, using variables for resource and types\n"; + var_dump($id); + var_dump($label); + + mysqli_stmt_close($stmt); + if (!$stmt = mysqli_stmt_init($link)) + printf("[035] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) + printf("[036] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = 1; + $params = array( + 0 => $stmt, + 1 => 'i', + 2 => &$id + ); + if (!call_user_func_array('mysqli_stmt_bind_param', $params)) + printf("[037] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[038] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = $label = null; + if (!mysqli_stmt_bind_result($stmt, $id, $label) || + (true !== mysqli_stmt_fetch($stmt))) + printf("[039] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + print "Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types\n"; + var_dump($id); + var_dump($label); + + mysqli_stmt_close($stmt); + if (!$stmt = mysqli_stmt_init($link)) + printf("[040] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) + printf("[041] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = 1; + if (!call_user_func_array('mysqli_stmt_bind_param', array($stmt, 'i', &$id))) + printf("[042] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[043] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = $label = null; + if (!mysqli_stmt_bind_result($stmt, $id, $label) || + (true !== mysqli_stmt_fetch($stmt))) + printf("[044] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + print "Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types, array\n"; + var_dump($id); + var_dump($label); + + // + // Any of those shall fail - see also bugs.php.net/43568 + // + mysqli_stmt_close($stmt); + if (!$stmt = mysqli_stmt_init($link)) + printf("[045] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) + printf("[046] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $id = 1; + $params = array( + 0 => 'i', + 1 => $id + ); + if (call_user_func_array(array($stmt, 'bind_param'), $params)) + printf("[047] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[048] [%d] (Message might vary with MySQL Server version, e.g. No data supplied for parameters in prepared statement)\n", mysqli_stmt_errno($stmt)); + + mysqli_stmt_close($stmt); + if (!$stmt = mysqli_stmt_init($link)) + printf("[049] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) + printf("[050] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + $types = 'i'; + $id = 1; + $params = array( + 0 => $stmt, + 1 => 'i', + 2 => $id + ); + if (call_user_func_array('mysqli_stmt_bind_param', $params)) + printf("[051] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[052] [%d] (Message might vary with MySQL Server version, e.g. No data supplied for parameters in prepared statement)\n", mysqli_stmt_errno($stmt)); + + print "done!"; +?> +--EXPECTF-- +Regular, procedural, using variables +int(1) +string(1) "a" +Call user func, procedural, using references for everything +int(1) +string(1) "a" +Call user func, object oriented, using references for everything +int(1) +string(1) "a" +Call user func, object oriented, using variable for types. using references for bound parameter +int(1) +string(1) "a" +Call user func, object oriented, using constant for types. using references for bound parameter +int(1) +string(1) "a" +Call user func, procedural, using references for everything but using variable for types +int(1) +string(1) "a" +Call user func, procedural, using references for bound parameter, using variables for resource and types +int(1) +string(1) "a" +Call user func, procedural, using references for bound parameter, using variables for resource and types +int(1) +string(1) "a" +Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types +int(1) +string(1) "a" +Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types, array +int(1) +string(1) "a" +[048] [2031] (Message might vary with MySQL Server version, e.g. No data supplied for parameters in prepared statement) +[052] [2031] (Message might vary with MySQL Server version, e.g. No data supplied for parameters in prepared statement) +done! +--UEXPECTF-- +Regular, procedural, using variables +int(1) +unicode(1) "a" +Call user func, procedural, using references for everything +int(1) +unicode(1) "a" +Call user func, object oriented, using references for everything +int(1) +unicode(1) "a" +Call user func, object oriented, using variable for types. using references for bound parameter +int(1) +unicode(1) "a" +Call user func, object oriented, using constant for types. using references for bound parameter +int(1) +unicode(1) "a" +Call user func, procedural, using references for everything but using variable for types +int(1) +unicode(1) "a" +Call user func, procedural, using references for bound parameter, using variables for resource and types +int(1) +unicode(1) "a" +Call user func, procedural, using references for bound parameter, using variables for resource and types +int(1) +unicode(1) "a" +Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types +int(1) +unicode(1) "a" +Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types, array +int(1) +unicode(1) "a" +[048] [2031] (Message might vary with MySQL Server version, e.g. No data supplied for parameters in prepared statement) +[052] [2031] (Message might vary with MySQL Server version, e.g. No data supplied for parameters in prepared statement) +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_stmt_bind_result_zerofill.phpt b/ext/mysqli/tests/mysqli_stmt_bind_result_zerofill.phpt new file mode 100644 index 0000000000..e5bd304848 --- /dev/null +++ b/ext/mysqli/tests/mysqli_stmt_bind_result_zerofill.phpt @@ -0,0 +1,93 @@ +--TEST-- +mysqli_stmt_bind_result() - ZEROFILL +--SKIPIF-- + +--FILE-- +length; + if ($length > strlen($insert)) { + + $expected = str_repeat('0', $length - strlen($insert)); + $expected .= $insert; + if ($expected !== $result) { + printf("[%03d] Expecting '%s' got '%s'\n", $offset, $expected, $result); + return false; + } + + } else if ($length <= 1) { + printf("[%03d] Length reported is too small to run test\n", $offset); + return false; + } + + + return true; + } + + /* + We map those to PHP numeric types - + no padding/filling done. Neither with libmysql nor with mysqlnd. + zerofill(2, $link, 'TINYINT'); + zerofill(3, $link, 'SMALLINT'); + zerofill(4, $link, 'MEDIUMINT'); + zerofill(5, $link, 'INT'); + zerofill(6, $link, 'INTEGER'); + zerofill(7, $link, 'BIGINT'); + zerofill(8, $link, 'FLOAT'); + zerofill(9, $link, 'DOUBLE'); + zerofill(10, $link, 'DOUBLE PRECISION'); + */ + zerofill(11, $link, 'DECIMAL'); + zerofill(12, $link, 'DEC'); + + mysqli_close($link); + + print "done!"; +?> +--EXPECTF-- +done! \ No newline at end of file