diff options
Diffstat (limited to 'ext/mysqli/tests')
37 files changed, 1083 insertions, 1688 deletions
diff --git a/ext/mysqli/tests/057.phpt b/ext/mysqli/tests/057.phpt index 2cb887506a..7c7e2b7568 100644 --- a/ext/mysqli/tests/057.phpt +++ b/ext/mysqli/tests/057.phpt @@ -35,8 +35,8 @@ require_once('skipifconnectfailure.inc'); var_dump(mysqli_stmt_reset($stmt)); var_dump($stmt = mysqli_prepare($link, "SELECT * FROM test_store_result")); - if ($IS_MYSQLND && $stmt->affected_rows !== -1) - printf("[001] Expecting -1, got %d\n", $stmt->affected_rows); + if ($stmt->affected_rows !== 0) + printf("[001] Expecting 0, got %d\n", $stmt->affected_rows); var_dump(mysqli_stmt_execute($stmt)); var_dump($stmt = @mysqli_prepare($link, "SELECT * FROM test_store_result"), mysqli_error($link)); diff --git a/ext/mysqli/tests/connect.inc b/ext/mysqli/tests/connect.inc index 3a9d8ec258..4acc20cb91 100644 --- a/ext/mysqli/tests/connect.inc +++ b/ext/mysqli/tests/connect.inc @@ -129,99 +129,6 @@ } } - function my_get_charsets($link) { - - /* Those tree are set by SET NAMES */ - $charsets = array( - 'client' => NULL, - 'results' => NULL, - 'connection' => NULL, - ); - - if (!($res = mysqli_query($link, "SHOW VARIABLES LIKE '%character%'"))) { - printf("[%d] %s\n", mysqli_errno($link), mysqli_error($link)); - return $charsets; - } - - $names = array(); - while ($row = mysqli_fetch_assoc($res)) { - $names[$row['Variable_name']] = $row['Value']; - } - mysqli_free_result($res); - - if (!($res = mysqli_query($link, sprintf("SHOW CHARACTER SET LIKE '%s'", $names['character_set_client']))) || - !($details = mysqli_fetch_assoc($res))) { - printf("[%d] %s\n", mysqli_errno($link), mysqli_error($link)); - return $charsets; - } - mysqli_free_result($res); - - $charsets['client'] = array( - 'charset' => $details['Charset'], - 'desc' => $details['Description'], - 'collation' => $details['Default collation'], - 'maxlen' => $details['Maxlen'], - 'nr' => NULL, - ); - - if (!($res = mysqli_query($link, sprintf("SHOW COLLATION LIKE '%s'", $details['Default collation']))) || - !($collation = mysqli_fetch_assoc($res))) { - printf("[%d] %s\n", mysqli_errno($link), mysqli_error($link)); - return $charsets; - } - mysqli_free_result($res); - $charsets['client']['nr'] = $collation['Id']; - - if (!($res = mysqli_query($link, sprintf("SHOW CHARACTER SET LIKE '%s'", $names['character_set_results']))) || - !($details = mysqli_fetch_assoc($res))) { - printf("[%d] %s\n", mysqli_errno($link), mysqli_error($link)); - return $charsets; - } - mysqli_free_result($res); - - $charsets['results'] = array( - 'charset' => $details['Charset'], - 'desc' => $details['Description'], - 'collation' => $details['Default collation'], - 'maxlen' => $details['Maxlen'], - 'nr' => NULL, - ); - - if (!($res = mysqli_query($link, sprintf("SHOW COLLATION LIKE '%s'", $details['Default collation']))) || - !($collation = mysqli_fetch_assoc($res))) { - printf("[%d] %s\n", mysqli_errno($link), mysqli_error($link)); - return $charsets; - } - mysqli_free_result($res); - $charsets['results']['nr'] = $collation['Id']; - - - if (!($res = mysqli_query($link, sprintf("SHOW CHARACTER SET LIKE '%s'", $names['character_set_connection']))) || - !($details = mysqli_fetch_assoc($res))) { - printf("[%d] %s\n", mysqli_errno($link), mysqli_error($link)); - return $charsets; - } - mysqli_free_result($res); - - $charsets['connection'] = array( - 'charset' => $details['Charset'], - 'desc' => $details['Description'], - 'collation' => $details['Default collation'], - 'maxlen' => $details['Maxlen'], - 'nr' => NULL, - ); - - if (!($res = mysqli_query($link, sprintf("SHOW COLLATION LIKE '%s'", $details['Default collation']))) || - !($collation = mysqli_fetch_assoc($res))) { - printf("[%d] %s\n", mysqli_errno($link), mysqli_error($link)); - return $charsets; - } - mysqli_free_result($res); - $charsets['connection']['nr'] = $collation['Id']; - - return $charsets; - } - function have_innodb($link) { if (($res = $link->query("SHOW VARIABLES LIKE 'have_innodb'")) && ($row = $res->fetch_row()) && diff --git a/ext/mysqli/tests/mysqli_begin_transaction.phpt b/ext/mysqli/tests/mysqli_begin_transaction.phpt new file mode 100644 index 0000000000..6c0508172f --- /dev/null +++ b/ext/mysqli/tests/mysqli_begin_transaction.phpt @@ -0,0 +1,126 @@ +--TEST-- +mysqli_begin_transaction() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +require_once('connect.inc'); +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die(sprintf("Cannot connect, [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); + +if (!have_innodb($link)) + die(sprintf("Needs InnoDB support, [%d] %s", $link->errno, $link->error)); +?> +--FILE-- +<?php + require_once("connect.inc"); + /* {{{ proto bool mysqli_begin_transaction(object link, [int flags [, string name]]) */ + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_begin_transaction())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_begin_transaction($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_begin_transaction($link, $link))) + printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[004] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + + if (!is_null($tmp = @mysqli_begin_transaction($link, $link))) + printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_begin_transaction($link, 0, $link))) + printf("[006] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_begin_transaction($link, 0, "mytrx", $link))) + printf("[007] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) + printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_query($link, 'CREATE TABLE test(id INT) ENGINE = InnoDB')) + printf("[009] Cannot create test table, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (true !== ($tmp = mysqli_autocommit($link, true))) + printf("[010] Cannot turn on autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp); + + /* overrule autocommit */ + if (true !== ($tmp = mysqli_begin_transaction($link))) + printf("[011] Got %s - [%d] %s\n", var_dump($tmp, true), mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_query($link, 'INSERT INTO test(id) VALUES (1)')) + printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $tmp = mysqli_rollback($link); + if ($tmp !== true) + printf("[013] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + /* empty */ + $res = mysqli_query($link, "SELECT * FROM test"); + var_dump($res->fetch_assoc()); + + /* valid flags */ + $flags = array(MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT); + + if (mysqli_get_server_version($link) >= 50605) { + $flags[] = MYSQLI_TRANS_START_READ_WRITE; + $flags[] = MYSQLI_TRANS_START_READ_ONLY; + } + + /* just coverage */ + foreach ($flags as $flag) { + if (!mysqli_begin_transaction($link, $flag, sprintf("flag %d", $flag))) { + printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + if (!mysqli_query($link, 'SELECT * FROM test') || !mysqli_rollback($link)) { + printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + } + + /* does it really set a flag? */ + if (mysqli_get_server_version($link) >= 50605) { + if (!mysqli_begin_transaction($link, MYSQLI_TRANS_START_READ_ONLY, sprintf("flag %d", $flag))) { + printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + if (mysqli_query($link, "INSERT INTO test(id) VALUES (2)")) { + printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } else if (!mysqli_commit($link)) { + printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } else { + $res = mysqli_query($link, "SELECT id FROM test WHERE id = 2"); + } + } + + if (!mysqli_begin_transaction($link, -1)) { + printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + if (mysqli_get_server_version($link) >= 50605) { + /* does it like stupid names? */ + if (@!$link->begin_transaction(MYSQLI_TRANS_START_READ_WRITE, "*/trick me?\n\0")) + printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + /* does it like stupid names? */ + if (@!$link->begin_transaction(MYSQLI_TRANS_START_READ_WRITE, "az09")) + printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + print "done!"; +?> +--CLEAN-- +<?php + require_once("clean_table.inc"); +?> +--EXPECTF-- +NULL + +Warning: mysqli_begin_transaction(): Invalid value for parameter flags (-1) in %s on line %d +[019] [%d]%A +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_change_user_old.phpt b/ext/mysqli/tests/mysqli_change_user_old.phpt new file mode 100644 index 0000000000..96357ebf51 --- /dev/null +++ b/ext/mysqli/tests/mysqli_change_user_old.phpt @@ -0,0 +1,127 @@ +--TEST-- +mysqli_change_user(), MySQL < 5.6 +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die(sprintf("SKIP Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket)); + +if (mysqli_get_server_version($link) >= 50600) + die("SKIP For MySQL < 5.6.0"); +?> +--FILE-- +<?php + require_once("connect.inc"); + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_change_user())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_change_user($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_change_user($link, $link))) + printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_change_user($link, $link, $link))) + printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_change_user($link, $link, $link, $link, $link))) + printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[006] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + + if (false !== ($tmp = mysqli_change_user($link, $user . '_unknown_really', $passwd . 'non_empty', $db))) + printf("[007] Expecting false, got %s/%s\n", gettype($tmp), $tmp); + + if (false !== ($tmp = mysqli_change_user($link, $user, $passwd . '_unknown_really', $db))) + printf("[008] Expecting false, got %s/%s\n", gettype($tmp), $tmp); + + if (false !== ($tmp = mysqli_change_user($link, $user, $passwd, $db . '_unknown_really'))) + printf("[009] Expecting false, got %s/%s\n", gettype($tmp), $tmp); + + // Reconnect because Percona and MariaDB block any commands after 3 failed + // change_user commands + mysqli_close($link); + + if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[020] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + } + if (!mysqli_query($link, 'SET @mysqli_change_user_test_var=1')) + printf("[010] Failed to set test variable: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!$res = mysqli_query($link, 'SELECT @mysqli_change_user_test_var AS test_var')) + printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + $tmp = mysqli_fetch_assoc($res); + mysqli_free_result($res); + if (1 != $tmp['test_var']) + printf("[012] Cannot set test variable\n"); + + if (true !== ($tmp = mysqli_change_user($link, $user, $passwd, $db))) + printf("[013] Expecting true, got %s/%s\n", gettype($tmp), $tmp); + + if (!$res = mysqli_query($link, 'SELECT database() AS dbname, user() AS user')) + printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + $tmp = mysqli_fetch_assoc($res); + mysqli_free_result($res); + + if (substr($tmp['user'], 0, strlen($user)) !== $user) + printf("[015] Expecting user %s, got user() %s\n", $user, $tmp['user']); + if ($tmp['dbname'] != $db) + printf("[016] Expecting database %s, got database() %s\n", $db, $tmp['dbname']); + + if (!$res = mysqli_query($link, 'SELECT @mysqli_change_user_test_var AS test_var')) + printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + $tmp = mysqli_fetch_assoc($res); + mysqli_free_result($res); + if (NULL !== $tmp['test_var']) + printf("[019] Test variable is still set!\n"); + + mysqli_close($link); + + if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[020] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + } + + if (false !== ($tmp = mysqli_change_user($link, str_repeat('user', 16384), str_repeat('pass', 16384), str_repeat('dbase', 16384)))) + printf("[021] Expecting false, got %s/%s\n", gettype($tmp), $tmp); + + mysqli_close($link); + + if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[022] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + } + + /* silent protocol change if no db which requires workaround in mysqlnd/libmysql + (empty db = no db send with COM_CHANGE_USER) */ + if (true !== ($tmp = mysqli_change_user($link, $user, $passwd, ""))) + printf("[023] Expecting true, got %s/%s\n", gettype($tmp), $tmp); + + if (!$res = mysqli_query($link, 'SELECT database() AS dbname, user() AS user')) + printf("[024] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + $tmp = mysqli_fetch_assoc($res); + mysqli_free_result($res); + + if ($tmp['dbname'] != "") + printf("[025] Expecting database '', got database() '%s'\n", $tmp['dbname']); + + mysqli_close($link); + + if (NULL !== ($tmp = @mysqli_change_user($link, $user, $passwd, $db))) + printf("[026] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +done! diff --git a/ext/mysqli/tests/mysqli_class_mysqli_interface.phpt b/ext/mysqli/tests/mysqli_class_mysqli_interface.phpt index df7d1c6580..ea86c198e7 100644 --- a/ext/mysqli/tests/mysqli_class_mysqli_interface.phpt +++ b/ext/mysqli/tests/mysqli_class_mysqli_interface.phpt @@ -20,38 +20,41 @@ require_once('skipifconnectfailure.inc'); $methods = get_class_methods($mysqli); $expected_methods = array( 'autocommit' => true, + 'begin_transaction' => true, 'change_user' => true, - 'character_set_name' => true, - 'close' => true, - 'commit' => true, - 'connect' => true, + 'character_set_name' => true, + 'close' => true, + 'commit' => true, + 'connect' => true, 'dump_debug_info' => true, 'escape_string' => true, 'get_charset' => true, 'get_client_info' => true, 'get_server_info' => true, 'get_warnings' => true, - 'init' => true, - 'kill' => true, + 'init' => true, + 'kill' => true, 'more_results' => true, 'multi_query' => true, - 'mysqli' => true, + 'mysqli' => true, 'next_result' => true, - 'options' => true, - 'ping' => true, - 'prepare' => true, - 'query' => true, + 'options' => true, + 'ping' => true, + 'prepare' => true, + 'query' => true, 'real_connect' => true, - 'real_escape_string' => true, + 'real_escape_string' => true, 'real_query' => true, - 'refresh' => true, - 'rollback' => true, - 'select_db' => true, + 'refresh' => true, + 'rollback' => true, + 'release_savepoint' => true, + 'savepoint' => true, + 'select_db' => true, 'set_charset' => true, - 'set_opt' => true, - 'ssl_set' => true, - 'stat' => true, - 'stmt_init' => true, + 'set_opt' => true, + 'ssl_set' => true, + 'stat' => true, + 'stmt_init' => true, 'store_result' => true, 'thread_safe' => true, 'use_result' => true, @@ -67,12 +70,6 @@ require_once('skipifconnectfailure.inc'); $expected_methods['get_connection_stats'] = true; $expected_methods['reap_async_query'] = true; $expected_methods['poll'] = true; - } else { - // libmysql only - if (function_exists('mysqli_ssl_set')) - $expected_methods['ssl_set'] = true; - $expected_methods['set_local_infile_default'] = true; - $expected_methods['set_local_infile_handler'] = true; } /* we should add ruled when to expect them */ @@ -301,7 +298,7 @@ mysqli->insert_id = '0'/integer ('0'/integer) mysqli->sqlstate = '00000'/%unicode|string% ('00000'/%unicode|string%) mysqli->stat = 'Uptime: %d Threads: %d Questions: %d Slow queries: %d Opens: %d Flush tables: %d Open tables: %d Queries per second avg: %d.%d'/string ('Uptime: %d Threads: %d Questions: %d Slow queries: %d Opens: %d Flush tables: %d Open tables: %d Queries per second avg: %d.%d'/string) mysqli->host_info = '%s'/%unicode|string% ('%s'/%unicode|string%) -mysqli->info = ''/NULL (''/%unicode|string%) +mysqli->info = ''/NULL (''/NULL) mysqli->thread_id = '%d'/integer ('%d'/integer) mysqli->protocol_version = '%d'/integer ('%d'/integer) mysqli->server_info = '%s'/%unicode|string% ('%s'/%unicode|string%) diff --git a/ext/mysqli/tests/mysqli_class_mysqli_reflection.phpt b/ext/mysqli/tests/mysqli_class_mysqli_reflection.phpt index 5fd4b6f45c..259fcd9ae6 100644 --- a/ext/mysqli/tests/mysqli_class_mysqli_reflection.phpt +++ b/ext/mysqli/tests/mysqli_class_mysqli_reflection.phpt @@ -6,8 +6,6 @@ require_once('skipif.inc'); require_once('skipifemb.inc'); require_once('connect.inc'); -if (($tmp = substr(PHP_VERSION, 0, strpos(PHP_VERSION, '.'))) && ($tmp < 5)) - die("skip Reflection not available before PHP 5 (found PHP $tmp)"); /* Let's not deal with cross-version issues in the EXPECTF/UEXPECTF. Most of the things which we test are covered by mysqli_class_*_interface.phpt. @@ -120,6 +118,36 @@ isPassedByReference: no isOptional: no isDefaultValueAvailable: no +Inspecting method 'begin_transaction' +isFinal: no +isAbstract: no +isPublic: yes +isPrivate: no +isProtected: no +isStatic: no +isConstructor: no +isDestructor: no +isInternal: yes +isUserDefined: no +returnsReference: no +Modifiers: 256 +Number of Parameters: 2 +Number of Required Parameters: 0 + +Inspecting parameter 'flags' of method 'begin_transaction' +isArray: no +allowsNull: no +isPassedByReference: no +isOptional: yes +isDefaultValueAvailable: no + +Inspecting parameter 'name' of method 'begin_transaction' +isArray: no +allowsNull: no +isPassedByReference: no +isOptional: yes +isDefaultValueAvailable: no + Inspecting method 'change_user' isFinal: no isAbstract: no @@ -202,9 +230,23 @@ isInternal: yes isUserDefined: no returnsReference: no Modifiers: 256 -Number of Parameters: 0 +Number of Parameters: 2 Number of Required Parameters: 0 +Inspecting parameter 'flags' of method 'commit' +isArray: no +allowsNull: no +isPassedByReference: no +isOptional: yes +isDefaultValueAvailable: no + +Inspecting parameter 'name' of method 'commit' +isArray: no +allowsNull: no +isPassedByReference: no +isOptional: yes +isDefaultValueAvailable: no + Inspecting method 'connect' isFinal: no isAbstract: no @@ -850,6 +892,29 @@ isPassedByReference: no isOptional: no isDefaultValueAvailable: no +Inspecting method 'release_savepoint' +isFinal: no +isAbstract: no +isPublic: yes +isPrivate: no +isProtected: no +isStatic: no +isConstructor: no +isDestructor: no +isInternal: yes +isUserDefined: no +returnsReference: no +Modifiers: 256 +Number of Parameters: 1 +Number of Required Parameters: 1 + +Inspecting parameter 'name' of method 'release_savepoint' +isArray: no +allowsNull: no +isPassedByReference: no +isOptional: no +isDefaultValueAvailable: no + Inspecting method 'rollback' isFinal: no isAbstract: no @@ -863,9 +928,46 @@ isInternal: yes isUserDefined: no returnsReference: no Modifiers: 256 -Number of Parameters: 0 +Number of Parameters: 2 Number of Required Parameters: 0 +Inspecting parameter 'flags' of method 'rollback' +isArray: no +allowsNull: no +isPassedByReference: no +isOptional: yes +isDefaultValueAvailable: no + +Inspecting parameter 'name' of method 'rollback' +isArray: no +allowsNull: no +isPassedByReference: no +isOptional: yes +isDefaultValueAvailable: no + +Inspecting method 'savepoint' +isFinal: no +isAbstract: no +isPublic: yes +isPrivate: no +isProtected: no +isStatic: no +isConstructor: no +isDestructor: no +isInternal: yes +isUserDefined: no +returnsReference: no +Modifiers: 256 +Number of Parameters: 1 +Number of Required Parameters: 1 + +Inspecting parameter 'name' of method 'savepoint' +isArray: no +allowsNull: no +isPassedByReference: no +isOptional: no +isDefaultValueAvailable: no + Inspecting method 'select_db' isFinal: no isAbstract: no diff --git a/ext/mysqli/tests/mysqli_commit_oo.phpt b/ext/mysqli/tests/mysqli_commit_oo.phpt index 34ec4bfcdc..77bcf412e7 100644 --- a/ext/mysqli/tests/mysqli_commit_oo.phpt +++ b/ext/mysqli/tests/mysqli_commit_oo.phpt @@ -21,53 +21,78 @@ if (!have_innodb($link)) $link = NULL; $mysqli = new mysqli(); - if (!is_null($tmp = @$mysqli->commit())) + if (!is_null($tmp = @$mysqli->commit())) { printf("[013] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); + } - if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) + if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) { printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket); + } - if (!is_null($tmp = @$mysqli->commit($link))) - printf("[002] Expecting NULL/NULL, got %s/%s, [%d] %s\n", - gettype($tmp), $tmp, $mysqli->errno, $mysqli->error); + if (true !== ($tmp = $mysqli->commit())) { + printf("[002] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); + } - if (true !== ($tmp = $mysqli->commit())) - printf("[014] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); - - if (true !== ($tmp = $mysqli->autocommit(false))) + if (true !== ($tmp = $mysqli->autocommit(false))) { printf("[003] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp); + } - if (!$mysqli->query('DROP TABLE IF EXISTS test')) + if (!$mysqli->query('DROP TABLE IF EXISTS test')) { printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); + } - if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) + if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) { printf("[005] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error); + } - if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) + if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) { printf("[006] [%d] %s\n", $mysqli->errno, $mysqli->error); + } $tmp = $mysqli->commit(); - if ($tmp !== true) + if ($tmp !== true) { printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + } if (!$mysqli->query('ROLLBACK')) printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error); - if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) + if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) { printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error); + } + $tmp = $res->fetch_assoc(); - if (1 != $tmp['num']) + if (1 != $tmp['num']) { printf("[010] Expecting 1 row in table test, found %d rows\n", $tmp['num']); + } $res->free(); - if (!$mysqli->query('DROP TABLE IF EXISTS test')) + if (!$mysqli->query('DROP TABLE IF EXISTS test')) { printf("[011] [%d] %s\n", $mysqli->errno, $mysqli->error); + } + + if (!$mysqli->commit(0 , "tx_name0123")) { + printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error); + } + if (!$mysqli->commit(0 , "*/ nonsense")) { + printf("[013] [%d] %s\n", $mysqli->errno, $mysqli->error); + } + if (!$mysqli->commit(0 , "tx_name ulf вендел")) { + printf("[014] [%d] %s\n", $mysqli->errno, $mysqli->error); + } + if (!$mysqli->commit(0 , "tx_name \t\n\r\b")) { + printf("[015] [%d] %s\n", $mysqli->errno, $mysqli->error); + } + if (!$mysqli->commit(MYSQLI_TRANS_COR_AND_CHAIN | MYSQLI_TRANS_COR_NO_RELEASE , "tx_name")) { + printf("[016] [%d] %s\n", $mysqli->errno, $mysqli->error); + } $mysqli->close(); - if (NULL !== ($tmp = @$mysqli->commit())) - printf("[012] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + if (NULL !== ($tmp = @$mysqli->commit())) { + printf("[017] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + } print "done!"; ?> @@ -76,4 +101,9 @@ if (!have_innodb($link)) require_once("clean_table.inc"); ?> --EXPECTF-- +Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d + +Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d + +Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_constants.phpt b/ext/mysqli/tests/mysqli_constants.phpt index 8bdc849f78..7c6dacd393 100644 --- a/ext/mysqli/tests/mysqli_constants.phpt +++ b/ext/mysqli/tests/mysqli_constants.phpt @@ -32,7 +32,7 @@ require_once('skipifconnectfailure.inc'); "MYSQLI_ASSOC" => true, "MYSQLI_NUM" => true, "MYSQLI_BOTH" => true, - "MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH" => true, + "MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH"=> true, "MYSQLI_NOT_NULL_FLAG" => true, "MYSQLI_PRI_KEY_FLAG" => true, "MYSQLI_UNIQUE_KEY_FLAG" => true, @@ -86,14 +86,21 @@ require_once('skipifconnectfailure.inc'); "MYSQLI_SET_CHARSET_NAME" => true, "MYSQLI_SET_CHARSET_DIR" => true, "MYSQLI_REFRESH_GRANT" => true, - "MYSQLI_REFRESH_LOG" => true, + "MYSQLI_REFRESH_LOG" => true, "MYSQLI_REFRESH_TABLES" => true, "MYSQLI_REFRESH_HOSTS" => true, "MYSQLI_REFRESH_STATUS" => true, "MYSQLI_REFRESH_THREADS" => true, "MYSQLI_REFRESH_SLAVE" => true, "MYSQLI_REFRESH_MASTER" => true, - "MYSQLI_DEBUG_TRACE_ENABLED" => true, + "MYSQLI_DEBUG_TRACE_ENABLED" => true, + "MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT" => true, + "MYSQLI_TRANS_START_READ_WRITE" => true, + "MYSQLI_TRANS_START_READ_ONLY" => true, + "MYSQLI_TRANS_COR_AND_CHAIN" => true, + "MYSQLI_TRANS_COR_AND_NO_CHAIN" => true, + "MYSQLI_TRANS_COR_RELEASE" => true, + "MYSQLI_TRANS_COR_NO_RELEASE" => true, ); /* depends on the build - experimental */ @@ -125,6 +132,12 @@ require_once('skipifconnectfailure.inc'); $expected_constants['MYSQLI_SERVER_QUERY_WAS_SLOW'] = true; } + + /* First introduced in MySQL 6.0, backported to MySQL 5.5 */ + if ($version >= 50606 || $IS_MYSQLND) { + $expected_constants['MYSQLI_SERVER_PUBLIC_KEY'] = true; + } + if ($version > 50002) { $expected_constants = array_merge($expected_constants, array( "MYSQLI_TYPE_NEWDECIMAL" => true, diff --git a/ext/mysqli/tests/mysqli_expire_password.phpt b/ext/mysqli/tests/mysqli_expire_password.phpt index ce89a21670..4fdf902c79 100644 --- a/ext/mysqli/tests/mysqli_expire_password.phpt +++ b/ext/mysqli/tests/mysqli_expire_password.phpt @@ -127,11 +127,11 @@ if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO expiretest@'% ?> --EXPECTF-- -Warning: mysqli_real_connect(): (HY000/1820): %s in %s on line %d -[001] Cannot connect [1820] %s +Warning: mysqli_real_connect(): (HY000/1862): %s in %s on line %d +[001] Cannot connect [1862] %s -Warning: mysqli_real_connect(): (HY000/1820): %s in %s on line %d -[003] Cannot connect [1820] %s +Warning: mysqli_real_connect(): (HY000/1862): %s in %s on line %d +[003] Cannot connect [1862] %s [006] Connect allowed, query fail, [1820] %s [008] Connect allowed, pw set, [0%A array(1) { diff --git a/ext/mysqli/tests/mysqli_fetch_field.phpt b/ext/mysqli/tests/mysqli_fetch_field.phpt index d1d358b342..2b9108072b 100644 --- a/ext/mysqli/tests/mysqli_fetch_field.phpt +++ b/ext/mysqli/tests/mysqli_fetch_field.phpt @@ -22,7 +22,13 @@ require_once('skipifconnectfailure.inc'); require('table.inc'); - $charsets = my_get_charsets($link); + // Make sure that client, connection and result charsets are all the + // same. Not sure whether this is strictly necessary. + if (!mysqli_set_charset($link, 'utf8')) + printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link)); + + $charsetInfo = mysqli_get_charset($link); + if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) { printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } @@ -34,19 +40,17 @@ require_once('skipifconnectfailure.inc'); /* label column, result set charset */ $tmp = mysqli_fetch_field($res); var_dump($tmp); - if ($tmp->charsetnr != $charsets['results']['nr']) { + if ($tmp->charsetnr != $charsetInfo->number) { printf("[004] Expecting charset %s/%d got %d\n", - $charsets['results']['charset'], - $charsets['results']['nr'], $tmp->charsetnr); + $charsetInfo->charset, $charsetInfo->number, $tmp->charsetnr); } - if ($tmp->length != (1 * $charsets['results']['maxlen'])) { + if ($tmp->length != $charsetInfo->max_length) { printf("[005] Expecting length %d got %d\n", - $charsets['results']['maxlen'], - $tmp->max_length); + $charsetInfo->max_length, $tmp->max_length); } if ($tmp->db != $db) { printf("011] Expecting database '%s' got '%s'\n", - $db, $tmp->db); + $db, $tmp->db); } var_dump(mysqli_fetch_field($res)); @@ -174,4 +178,4 @@ object(stdClass)#%d (13) { [%u|b%"decimals"]=> int(0) } -done!
\ No newline at end of file +done! diff --git a/ext/mysqli/tests/mysqli_fetch_field_oo.phpt b/ext/mysqli/tests/mysqli_fetch_field_oo.phpt index 2d5ad261b1..8c5609b163 100644 --- a/ext/mysqli/tests/mysqli_fetch_field_oo.phpt +++ b/ext/mysqli/tests/mysqli_fetch_field_oo.phpt @@ -27,7 +27,12 @@ require_once('skipifconnectfailure.inc'); if (!is_null($tmp = @$res->fetch_field($link))) printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); - $charsets = my_get_charsets($link); + // Make sure that client, connection and result charsets are all the + // same. Not sure whether this is strictly necessary. + if (!$mysqli->set_charset('utf8')) + printf("[%d] %s\n", $mysqli->errno, $mysqli->errno); + + $charsetInfo = $mysqli->get_charset(); if (!$res = $mysqli->query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) { printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); @@ -37,18 +42,16 @@ require_once('skipifconnectfailure.inc'); $tmp = $res->fetch_field(); var_dump($tmp); - if ($tmp->charsetnr != $charsets['results']['nr']) { + if ($tmp->charsetnr != $charsetInfo->number) { printf("[005] Expecting charset %s/%d got %d\n", - $charsets['results']['charset'], - $charsets['results']['nr'], $tmp->charsetnr); + $charsetInfo->charset, $charsetInfo->number, $tmp->charsetnr); } - if ($tmp->length != (1 * $charsets['results']['maxlen'])) { + if ($tmp->length != $charsetInfo->max_length) { printf("[006] Expecting length %d got %d\n", - $charsets['results']['maxlen'], - $tmp->max_length); + $charsetInfo->max_length, $tmp->max_length); } if ($tmp->db != $db) { - printf("008] Expecting database '%s' got '%s'\n", + printf("[007] Expecting database '%s' got '%s'\n", $db, $tmp->db); } @@ -126,4 +129,4 @@ object(stdClass)#%d (13) { bool(false) Warning: mysqli_result::fetch_field(): Couldn't fetch mysqli_result in %s on line %d -done!
\ No newline at end of file +done! diff --git a/ext/mysqli/tests/mysqli_fetch_fields.phpt b/ext/mysqli/tests/mysqli_fetch_fields.phpt index 479c71cbbc..6b66d6f231 100644 --- a/ext/mysqli/tests/mysqli_fetch_fields.phpt +++ b/ext/mysqli/tests/mysqli_fetch_fields.phpt @@ -21,7 +21,13 @@ require_once('skipifconnectfailure.inc'); printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); require('table.inc'); - $charsets = my_get_charsets($link); + + // Make sure that client, connection and result charsets are all the + // same. Not sure whether this is strictly necessary. + if (!mysqli_set_charset($link, 'utf8')) + printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link)); + + $charsetInfo = mysqli_get_charset($link); if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) { printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); @@ -33,14 +39,14 @@ require_once('skipifconnectfailure.inc'); switch ($k) { case 1: /* label column, result set charset */ - if ($field->charsetnr != $charsets['results']['nr']) { + if ($field->charsetnr != $charsetInfo->number) { printf("[004] Expecting charset %s/%d got %d\n", - $charsets['results']['charset'], - $charsets['results']['nr'], $field->charsetnr); + $charsetInfo->charset, + $charsetInfo->number, $field->charsetnr); } - if ($field->length != (1 * $charsets['results']['maxlen'])) { + if ($field->length != $charsetInfo->max_length) { printf("[005] Expecting length %d got %d\n", - $charsets['results']['maxlen'], + $charsetInfo->max_length, $field->max_length); } break; @@ -118,4 +124,4 @@ object(stdClass)#%d (13) { } Warning: mysqli_fetch_fields(): Couldn't fetch mysqli_result in %s on line %d -done!
\ No newline at end of file +done! diff --git a/ext/mysqli/tests/mysqli_field_seek.phpt b/ext/mysqli/tests/mysqli_field_seek.phpt index a747bdfa01..449d2f90d4 100644 --- a/ext/mysqli/tests/mysqli_field_seek.phpt +++ b/ext/mysqli/tests/mysqli_field_seek.phpt @@ -66,7 +66,13 @@ require_once('skipifconnectfailure.inc'); printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); require('table.inc'); - $charsets = my_get_charsets($link); + + // Make sure that client, connection and result charsets are all the + // same. Not sure whether this is strictly necessary. + if (!mysqli_set_charset($link, 'utf8')) + printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link)); + + $charsetInfo = mysqli_get_charset($link); if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1", MYSQLI_USE_RESULT)) { printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); @@ -81,15 +87,13 @@ require_once('skipifconnectfailure.inc'); $field = mysqli_fetch_field($res); var_dump($field); /* label column, result set charset */ - if ($field->charsetnr != $charsets['results']['nr']) { + if ($field->charsetnr != $charsetInfo->number) { printf("[004] Expecting charset %s/%d got %d\n", - $charsets['results']['charset'], - $charsets['results']['nr'], $field->charsetnr); + $charsetInfo->charset, $charsetInfo->number, $field->charsetnr); } - if ($field->length != (1 * $charsets['results']['maxlen'])) { + if ($field->length != $charsetInfo->max_length) { printf("[005] Expecting length %d got %d\n", - $charsets['results']['maxlen'], - $field->max_length); + $charsetInfo->max_length, $field->max_length); } var_dump(mysqli_field_tell($res)); @@ -217,7 +221,7 @@ bool(false) Warning: mysqli_field_seek(): Invalid field offset in %s on line %d bool(false) bool(true) -object(stdClass)#3 (13) { +object(stdClass)#%d (13) { [%u|b%"name"]=> %unicode|string%(5) "_null" [%u|b%"orgname"]=> @@ -248,4 +252,4 @@ object(stdClass)#3 (13) { Warning: mysqli_field_seek(): Couldn't fetch mysqli_result in %s on line %d NULL -done!
\ No newline at end of file +done! diff --git a/ext/mysqli/tests/mysqli_info.phpt b/ext/mysqli/tests/mysqli_info.phpt index 2d5004fe6e..6bb5d215e0 100644 --- a/ext/mysqli/tests/mysqli_info.phpt +++ b/ext/mysqli/tests/mysqli_info.phpt @@ -21,8 +21,8 @@ require_once('skipifconnectfailure.inc'); printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); // NOTE: empty string, no multiple insert syntax - if (!is_string($tmp = mysqli_info($link)) || ('' != $tmp)) - printf("[004] Expecting string/empty, got %s/%s\n", gettype($tmp), $tmp); + if (!is_null($tmp = mysqli_info($link)) || ('' != $tmp)) + printf("[004] Expecting null, got %s/%s\n", gettype($tmp), $tmp); if (!$res = mysqli_query($link, "INSERT INTO test(id, label) VALUES (101, 'a'), (102, 'b')")) printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); @@ -54,8 +54,8 @@ require_once('skipifconnectfailure.inc'); if (!$res = mysqli_query($link, "SELECT 1")) printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); - if (!is_string($tmp = mysqli_info($link)) || ('' != $tmp)) - printf("[014] Expecting string/empty, got %s/%s\n", gettype($tmp), $tmp); + if (!is_null($tmp = mysqli_info($link)) || ('' != $tmp)) + printf("[014] Expecting null, got %s/%s\n", gettype($tmp), $tmp); mysqli_free_result($res); // NOTE: no LOAD DATA INFILE test diff --git a/ext/mysqli/tests/mysqli_pam_sha256.phpt b/ext/mysqli/tests/mysqli_pam_sha256.phpt new file mode 100644 index 0000000000..3016e200d7 --- /dev/null +++ b/ext/mysqli/tests/mysqli_pam_sha256.phpt @@ -0,0 +1,113 @@ +--TEST-- +PAM: SHA-256 +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +ob_start(); +phpinfo(INFO_MODULES); +$tmp = ob_get_contents(); +ob_end_clean(); +if (!stristr($tmp, "auth_plugin_sha256_password")) + die("skip SHA256 auth plugin not built-in to mysqlnd"); + +require_once('connect.inc'); +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die(printf("skip: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error())); + +if (mysqli_get_server_version($link) < 50606) + die("skip: SHA-256 requires MySQL 5.6.6+"); + +if (!($res = $link->query("SHOW PLUGINS"))) { + die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); +} + +$found = false; +while ($row = $res->fetch_assoc()) { + if (($row['Name'] == 'sha256_password') && ($row['Status'] == 'ACTIVE')) { + $found = true; + break; + } +} +if (!$found) + die("skip SHA-256 server plugin unavailable"); + +if (!($res = $link->query("SHOW STATUS LIKE 'Rsa_public_key'"))) { + die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); +} + +if (!($row = $res->fetch_assoc())) { + die(sprintf("skip Failed to check RSA pub key, [%d] %s\n", $link->errno, $link->error)); +} + +if (strlen($row['Value']) < 100) { + die(sprintf("skip Server misconfiguration? RSA pub key is suspicious, [%d] %s\n", $link->errno, $link->error)); +} + +if (!$link->query("SET @@session.old_passwords=2")) { + die(sprintf("skip Cannot set @@session.old_passwords=2 [%d] %s", $link->errno, $link->error)); +} + +$link->query('DROP USER shatest'); +$link->query("DROP USER shatest@localhost"); + + +if (!$link->query('CREATE USER shatest@"%" IDENTIFIED WITH sha256_password') || + !$link->query('CREATE USER shatest@"localhost" IDENTIFIED WITH sha256_password')) { + die(sprintf("skip CREATE USER failed [%d] %s", $link->errno, $link->error)); +} + +if (!$link->query('SET PASSWORD FOR shatest@"%" = PASSWORD("shatest")') || + !$link->query('SET PASSWORD FOR shatest@"localhost" = PASSWORD("shatest")')) { + die(sprintf("skip SET PASSWORD failed [%d] %s", $link->errno, $link->error)); +} + +if (!$link->query("DROP TABLE IF EXISTS test") || + !$link->query("CREATE TABLE test (id INT)") || + !$link->query("INSERT INTO test(id) VALUES (1), (2), (3)")) + die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error)); + + +if (!$link->query(sprintf("GRANT SELECT ON TABLE %s.test TO shatest@'%%'", $db)) || + !$link->query(sprintf("GRANT SELECT ON TABLE %s.test TO shatest@'localhost'", $db))) { + die(sprintf("skip Cannot grant SELECT to user [%d] %s", mysqli_errno($link), mysqli_error($link))); +} + +$link->close(); +?> +--FILE-- +<?php + require_once("connect.inc"); + + if (!$link = my_mysqli_connect($host, 'shatest', 'shatest', $db, $port, $socket)) { + printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, "shatest", $db, $port, $socket); + } else { + + if (!$res = $link->query("SELECT id FROM test WHERE id = 1")) + printf("[002] [%d] %s\n", $link->errno, $link->error); + + if (!$row = mysqli_fetch_assoc($res)) { + printf("[003] [%d] %s\n", $link->errno, $link->error); + } + + if ($row['id'] != 1) { + printf("[004] Expecting 1 got %s/'%s'", gettype($row['id']), $row['id']); + } + + $res->close(); + $link->close(); + } + + print "done!"; +?> +--CLEAN-- +<?php + require_once("clean_table.inc"); + $link->query('DROP USER shatest'); + $link->query('DROP USER shatest@localhost'); +?> +--EXPECTF-- +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_pam_sha256_public_key_ini.phpt b/ext/mysqli/tests/mysqli_pam_sha256_public_key_ini.phpt new file mode 100644 index 0000000000..27bbed138c --- /dev/null +++ b/ext/mysqli/tests/mysqli_pam_sha256_public_key_ini.phpt @@ -0,0 +1,129 @@ +--TEST-- +PAM: SHA-256, mysqlnd.sha256_server_public_key +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +ob_start(); +phpinfo(INFO_MODULES); +$tmp = ob_get_contents(); +ob_end_clean(); +if (!stristr($tmp, "auth_plugin_sha256_password")) + die("skip SHA256 auth plugin not built-in to mysqlnd"); + +require_once('connect.inc'); +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die(printf("skip: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error())); + +if (mysqli_get_server_version($link) < 50606) + die("skip: SHA-256 requires MySQL 5.6.6+"); + +if (!($res = $link->query("SHOW PLUGINS"))) { + die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); +} + +$found = false; +while ($row = $res->fetch_assoc()) { + if (($row['Name'] == 'sha256_password') && ($row['Status'] == 'ACTIVE')) { + $found = true; + break; + } +} +if (!$found) + die("skip SHA-256 server plugin unavailable"); + +if (!($res = $link->query("SHOW STATUS LIKE 'Rsa_public_key'"))) { + die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); +} + +if (!($row = $res->fetch_assoc())) { + die(sprintf("skip Failed to check RSA pub key, [%d] %s\n", $link->errno, $link->error)); +} + +$key = $row['Value']; +if (strlen($key) < 100) { + die(sprintf("skip Server misconfiguration? RSA pub key is suspicious, [%d] %s\n", $link->errno, $link->error)); +} + +/* date changes may give false positive */ +$file = "test_sha256_ini"; +if ((file_exists($file) && !unlink($file)) || !($fp = @fopen($file, "w"))) { + die(sprintf("skip Cannot create RSA pub key file '%s'", $file)); +} +$key = str_replace("A", "a", $key); +$key = str_replace("M", "m", $key); +if (strlen($key) != fwrite($fp, $key)) { + die(sprintf("skip Failed to create pub key file")); +} + + +if (!$link->query("SET @@session.old_passwords=2")) { + die(sprintf("skip Cannot set @@session.old_passwords=2 [%d] %s", $link->errno, $link->error)); +} + +$link->query('DROP USER shatest'); +$link->query("DROP USER shatest@localhost"); + + +if (!$link->query('CREATE USER shatest@"%" IDENTIFIED WITH sha256_password') || + !$link->query('CREATE USER shatest@"localhost" IDENTIFIED WITH sha256_password')) { + die(sprintf("skip CREATE USER failed [%d] %s", $link->errno, $link->error)); +} + +if (!$link->query('SET PASSWORD FOR shatest@"%" = PASSWORD("shatest")') || + !$link->query('SET PASSWORD FOR shatest@"localhost" = PASSWORD("shatest")')) { + die(sprintf("skip SET PASSWORD failed [%d] %s", $link->errno, $link->error)); +} + +if (!$link->query("DROP TABLE IF EXISTS test") || + !$link->query("CREATE TABLE test (id INT)") || + !$link->query("INSERT INTO test(id) VALUES (1), (2), (3)")) + die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error)); + + +if (!$link->query(sprintf("GRANT SELECT ON TABLE %s.test TO shatest@'%%'", $db)) || + !$link->query(sprintf("GRANT SELECT ON TABLE %s.test TO shatest@'localhost'", $db))) { + die(sprintf("skip Cannot grant SELECT to user [%d] %s", mysqli_errno($link), mysqli_error($link))); +} + +$link->close(); +?> +--INI-- +mysqlnd.sha256_server_public_key="test_sha256_ini" +--FILE-- +<?php + require_once("connect.inc"); + + + $link = new mysqli($host, 'shatest', 'shatest', $db, $port, $socket); + if ($link->connect_errno) { + printf("[001] [%d] %s\n", $link->connect_errno, $link->connect_error); + } else { + if (!$res = $link->query("SELECT id FROM test WHERE id = 1")) + printf("[002] [%d] %s\n", $link->errno, $link->error); + + if (!$row = mysqli_fetch_assoc($res)) { + printf("[003] [%d] %s\n", $link->errno, $link->error); + } + + if ($row['id'] != 1) { + printf("[004] Expecting 1 got %s/'%s'", gettype($row['id']), $row['id']); + } + } + print "done!"; +?> +--CLEAN-- +<?php + require_once("clean_table.inc"); + $link->query('DROP USER shatest'); + $link->query('DROP USER shatest@localhost'); + $file = "test_sha256_ini"; + @unlink($file); +?> +--EXPECTF-- + +Warning: mysqli::mysqli(): (HY000/1045): %s in %s on line %d +[001] [1045] %s +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_pam_sha256_public_key_option.phpt b/ext/mysqli/tests/mysqli_pam_sha256_public_key_option.phpt new file mode 100644 index 0000000000..afed773b01 --- /dev/null +++ b/ext/mysqli/tests/mysqli_pam_sha256_public_key_option.phpt @@ -0,0 +1,132 @@ +--TEST-- +PAM: SHA-256, option: MYSQLI_SERVER_PUBLIC_KEY +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +ob_start(); +phpinfo(INFO_MODULES); +$tmp = ob_get_contents(); +ob_end_clean(); +if (!stristr($tmp, "auth_plugin_sha256_password")) + die("skip SHA256 auth plugin not built-in to mysqlnd"); + +require_once('connect.inc'); +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die(printf("skip: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error())); + +if (mysqli_get_server_version($link) < 50606) + die("skip: SHA-256 requires MySQL 5.6.6+"); + +if (!($res = $link->query("SHOW PLUGINS"))) { + die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); +} + +$found = false; +while ($row = $res->fetch_assoc()) { + if (($row['Name'] == 'sha256_password') && ($row['Status'] == 'ACTIVE')) { + $found = true; + break; + } +} +if (!$found) + die("skip SHA-256 server plugin unavailable"); + +if (!($res = $link->query("SHOW STATUS LIKE 'Rsa_public_key'"))) { + die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); +} + +if (!($row = $res->fetch_assoc())) { + die(sprintf("skip Failed to check RSA pub key, [%d] %s\n", $link->errno, $link->error)); +} + +if (strlen($row['Value']) < 100) { + die(sprintf("skip Server misconfiguration? RSA pub key is suspicious, [%d] %s\n", $link->errno, $link->error)); +} + +/* date changes may give false positive */ +$file = sprintf("%s%s%s_%s", sys_get_temp_dir(), DIRECTORY_SEPARATOR, "test_sha256_" , @date("Ymd")); +if ((file_exists($file) && !unlink($file)) || !($fp = @fopen($file, "w"))) { + die(sprintf("skip Cannot create RSA pub key file '%s'", $file)); +} +if (strlen($row['Value']) != fwrite($fp, $row['Value'])) { + die(sprintf("skip Failed to create pub key file")); +} + + +if (!$link->query("SET @@session.old_passwords=2")) { + die(sprintf("skip Cannot set @@session.old_passwords=2 [%d] %s", $link->errno, $link->error)); +} + +$link->query('DROP USER shatest'); +$link->query("DROP USER shatest@localhost"); + + +if (!$link->query('CREATE USER shatest@"%" IDENTIFIED WITH sha256_password') || + !$link->query('CREATE USER shatest@"localhost" IDENTIFIED WITH sha256_password')) { + die(sprintf("skip CREATE USER failed [%d] %s", $link->errno, $link->error)); +} + +if (!$link->query('SET PASSWORD FOR shatest@"%" = PASSWORD("shatest")') || + !$link->query('SET PASSWORD FOR shatest@"localhost" = PASSWORD("shatest")')) { + die(sprintf("skip SET PASSWORD failed [%d] %s", $link->errno, $link->error)); +} + +if (!$link->query("DROP TABLE IF EXISTS test") || + !$link->query("CREATE TABLE test (id INT)") || + !$link->query("INSERT INTO test(id) VALUES (1), (2), (3)")) + die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error)); + + +if (!$link->query(sprintf("GRANT SELECT ON TABLE %s.test TO shatest@'%%'", $db)) || + !$link->query(sprintf("GRANT SELECT ON TABLE %s.test TO shatest@'localhost'", $db))) { + die(sprintf("skip Cannot grant SELECT to user [%d] %s", mysqli_errno($link), mysqli_error($link))); +} + +$link->close(); +?> +--FILE-- +<?php + require_once("connect.inc"); + + $file = sprintf("%s%s%s_%s", sys_get_temp_dir(), DIRECTORY_SEPARATOR, "test_sha256_" , @date("Ymd")); + if (file_exists($file) && is_readable($file)) { + + $link = mysqli_init(); + if (!($link->options(MYSQLI_SERVER_PUBLIC_KEY, $file))) { + printf("[001] mysqli_options failed, [%d] %s\n", $link->errno, $link->error); + } + + if (!$link->real_connect($host, 'shatest', 'shatest', $db, $port, $socket)) { + printf("[002] [%d] %s\n", $link->connect_errno, $link->connect_error); + } + + if (!$res = $link->query("SELECT id FROM test WHERE id = 1")) + printf("[003] [%d] %s\n", $link->errno, $link->error); + + if (!$row = mysqli_fetch_assoc($res)) { + printf("[004] [%d] %s\n", $link->errno, $link->error); + } + + if ($row['id'] != 1) { + printf("[005] Expecting 1 got %s/'%s'", gettype($row['id']), $row['id']); + } + + $res->close(); + $link->close(); + } + + print "done!"; +?> +--CLEAN-- +<?php + require_once("clean_table.inc"); + $link->query('DROP USER shatest'); + $link->query('DROP USER shatest@localhost'); + $file = sprintf("%s%s%s_%s", sys_get_temp_dir(), DIRECTORY_SEPARATOR, "test_sha256_" , @date("Ymd")); + @unlink($file); +?> +--EXPECTF-- +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_pam_sha256_public_key_option_invalid.phpt b/ext/mysqli/tests/mysqli_pam_sha256_public_key_option_invalid.phpt new file mode 100644 index 0000000000..e2626240d8 --- /dev/null +++ b/ext/mysqli/tests/mysqli_pam_sha256_public_key_option_invalid.phpt @@ -0,0 +1,188 @@ +--TEST-- +PAM: SHA-256, option: MYSQLI_SERVER_PUBLIC_KEY (invalid) +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +ob_start(); +phpinfo(INFO_MODULES); +$tmp = ob_get_contents(); +ob_end_clean(); +if (!stristr($tmp, "auth_plugin_sha256_password")) + die("skip SHA256 auth plugin not built-in to mysqlnd"); + +require_once('connect.inc'); +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die(printf("skip: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error())); + +if (mysqli_get_server_version($link) < 50606) + die("skip: SHA-256 requires MySQL 5.6.6+"); + +if (!($res = $link->query("SHOW PLUGINS"))) { + die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); +} + +$found = false; +while ($row = $res->fetch_assoc()) { + if (($row['Name'] == 'sha256_password') && ($row['Status'] == 'ACTIVE')) { + $found = true; + break; + } +} +if (!$found) + die("skip SHA-256 server plugin unavailable"); + +if (!($res = $link->query("SHOW STATUS LIKE 'Rsa_public_key'"))) { + die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); +} + +if (!($row = $res->fetch_assoc())) { + die(sprintf("skip Failed to check RSA pub key, [%d] %s\n", $link->errno, $link->error)); +} + +if (strlen($row['Value']) < 100) { + die(sprintf("skip Server misconfiguration? RSA pub key is suspicious, [%d] %s\n", $link->errno, $link->error)); +} + +/* date changes may give false positive */ +$file = sprintf("%s%s%s_%s", sys_get_temp_dir(), DIRECTORY_SEPARATOR, "test_sha256_" , @date("Ymd")); +if ((file_exists($file) && !unlink($file)) || !($fp = @fopen($file, "w"))) { + die(sprintf("skip Cannot create RSA pub key file '%s'", $file)); +} +if (strlen($row['Value']) != fwrite($fp, $row['Value'])) { + die(sprintf("skip Failed to create pub key file")); +} + + +if (!$link->query("SET @@session.old_passwords=2")) { + die(sprintf("skip Cannot set @@session.old_passwords=2 [%d] %s", $link->errno, $link->error)); +} + +$link->query('DROP USER shatest'); +$link->query("DROP USER shatest@localhost"); + + +if (!$link->query('CREATE USER shatest@"%" IDENTIFIED WITH sha256_password') || + !$link->query('CREATE USER shatest@"localhost" IDENTIFIED WITH sha256_password')) { + die(sprintf("skip CREATE USER failed [%d] %s", $link->errno, $link->error)); +} + +if (!$link->query('SET PASSWORD FOR shatest@"%" = PASSWORD("shatest")') || + !$link->query('SET PASSWORD FOR shatest@"localhost" = PASSWORD("shatest")')) { + die(sprintf("skip SET PASSWORD failed [%d] %s", $link->errno, $link->error)); +} + +if (!$link->query("DROP TABLE IF EXISTS test") || + !$link->query("CREATE TABLE test (id INT)") || + !$link->query("INSERT INTO test(id) VALUES (1), (2), (3)")) + die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error)); + + +if (!$link->query(sprintf("GRANT SELECT ON TABLE %s.test TO shatest@'%%'", $db)) || + !$link->query(sprintf("GRANT SELECT ON TABLE %s.test TO shatest@'localhost'", $db))) { + die(sprintf("skip Cannot grant SELECT to user [%d] %s", mysqli_errno($link), mysqli_error($link))); +} + +$link->close(); +?> +--FILE-- +<?php + require_once("connect.inc"); + + function sha_connect($offset, $host, $db, $port, $socket, $file) { + + $link = mysqli_init(); + if (!($link->options(MYSQLI_SERVER_PUBLIC_KEY, $file))) { + printf("[%03d + 001] mysqli_options failed, [%d] %s\n", $offset, $link->errno, $link->error); + return false; + } + + if (!$link->real_connect($host, 'shatest', 'shatest', $db, $port, $socket)) { + printf("[%03d + 002] [%d] %s\n", $offset, $link->connect_errno, $link->connect_error); + return false; + } + + if (!$res = $link->query("SELECT id FROM test WHERE id = 1")) + printf("[%03d + 003] [%d] %s\n", $offset, $link->errno, $link->error); + return false; + + if (!$row = mysqli_fetch_assoc($res)) { + printf("[%03d + 004] [%d] %s\n", $offset, $link->errno, $link->error); + return false; + } + + if ($row['id'] != 1) { + printf("[%03d + 005] Expecting 1 got %s/'%s'", $offset, gettype($row['id']), $row['id']); + return false; + } + + $res->close(); + $link->close(); + return true; + } + + $file = sprintf("%s%s%s_%s", sys_get_temp_dir(), DIRECTORY_SEPARATOR, "test_sha256_" , @date("Ymd")); + if (file_exists($file) && is_readable($file)) { + + /* valid key */ + sha_connect(100, $host, $db, $port, $socket, $file); + + /* invalid key */ + $file_wrong = sprintf("%s%s%s_%s", sys_get_temp_dir(), DIRECTORY_SEPARATOR, "test_sha256_wrong" , @date("Ymd")); + + $key = file_get_contents($file); + $key = str_replace("A", "a", $key); + $key = str_replace("M", "m", $key); + @unlink($file_wrong); + if (!($fp = fopen($file_wrong, "w"))) { + printf("[002] Can't write public key file."); + } else { + fwrite($fp, $key); + fclose($fp); + sha_connect(200, $host, $db, $port, $socket, $file_wrong); + } + + /* empty file */ + @unlink($file_wrong); + if (!($fp = fopen($file_wrong, "w"))) { + printf("[003] Can't write public key file."); + } else { + fwrite($fp, ""); + fclose($fp); + sha_connect(300, $host, $db, $port, $socket, $file_wrong); + } + + /* file does not exist */ + @unlink($file_wrong); + sha_connect(400, $host, $db, $port, $socket, $file_wrong); + + } else { + printf("[001] Cannot read public key file."); + } + + print "done!"; +?> +--CLEAN-- +<?php + require_once("clean_table.inc"); + $link->query('DROP USER shatest'); + $link->query('DROP USER shatest@localhost'); + $file = sprintf("%s%s%s_%s", sys_get_temp_dir(), DIRECTORY_SEPARATOR, "test_sha256_" , @date("Ymd")); + @unlink($file); + $file_wrong = sprintf("%s%s%s_%s", sys_get_temp_dir(), DIRECTORY_SEPARATOR, "test_sha256_wrong" , @date("Ymd")); + @unlink($file_wrong); +?> +--EXPECTF-- +Warning: mysqli::real_connect(): (HY000/1045): %s in %s on line %d +[200 + 002] [1045] %s + +Warning: mysqli::real_connect(): (HY000/1045): %s in %s on line %d +[300 + 002] [1045] %s + +Warning: mysqli::real_connect(%sest_sha256_wrong_%d): failed to open stream: No such file or directory in %s on line %d + +Warning: mysqli::real_connect(): (HY000/1045): %s in %s on line %d +[400 + 002] [1045] %s +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_query_local_infile_large.phpt b/ext/mysqli/tests/mysqli_query_local_infile_large.phpt deleted file mode 100644 index 76bc415d8b..0000000000 --- a/ext/mysqli/tests/mysqli_query_local_infile_large.phpt +++ /dev/null @@ -1,103 +0,0 @@ ---TEST-- -mysql_query(LOAD DATA LOCAL INFILE) with large data set (10MB) ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifconnectfailure.inc'); - -$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); -if (!$link) - die(sprintf("skip Can't connect [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - // Create a large CVS file - $file = tempnam(sys_get_temp_dir(), 'mysqli_test.cvs'); - if (!$fp = fopen($file, 'w')) - printf("[001] Cannot create CVS file '%s'\n", $file); - - $data = str_repeat("a", 127) . ";" . str_repeat("b", 127) . "\n"; - - $runtime = 5; - $max_bytes = 1024 * 1024 * 10; - - $start = microtime(true); - $bytes = 0; - $rowno = 0; - while (($bytes < $max_bytes) && ((microtime(true) - $start) < $runtime)) { - if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1)) - $bytes += fwrite($fp, (binary)(++$rowno . ";" . $data)); - else - $bytes += fwrite($fp, ++$rowno . ";" . $data); - } - fclose($fp); - printf("Filesize in bytes: %d\nRows: %d\n", $bytes, $rowno); - - require_once("connect.inc"); - if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) - printf("[002] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); - - if (!mysqli_query($link, "DROP TABLE IF EXISTS test") || - !mysqli_query($link, "CREATE TABLE test(id INT, col1 VARCHAR(255), col2 VARCHAR(255)) ENGINE = " . $engine)) - printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); - - if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE test FIELDS TERMINATED BY ';'", mysqli_real_escape_string($link, $file)))) - printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); - - if ((!is_string(mysqli_info($link))) || ('' == mysqli_info($link))) { - printf("[005] [%d] %s, mysqli_info not set \n", mysqli_errno($link), mysqli_error($link)); - } - - if (!($res = mysqli_query($link, "SELECT COUNT(*) AS _num FROM test"))) - printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); - - $row = mysqli_fetch_assoc($res); - if (($row["_num"] != $rowno)) - printf("[007] Expecting %d rows, found %d\n", $rowno, $row["_num"]); - - mysqli_free_result($res); - - $random = mt_rand(1, $rowno); - if (!$res = mysqli_query($link, "SELECT id, col1, col2 FROM test WHERE id = " . $random)) - printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); - - $row = mysqli_fetch_assoc($res); - var_dump($row); - mysqli_free_result($res); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php -$file = tempnam(sys_get_temp_dir(), 'mysqli_test.cvs'); -if (file_exists($file)) - unlink($file); - -require_once("connect.inc"); -if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) - printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); - -if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) - printf("[c002] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); -?> ---EXPECTF-- -Filesize in bytes: %d -Rows: %d -array(3) { - [%u|b%"id"]=> - %unicode|string%(%d) "%d" - [%u|b%"col1"]=> - %unicode|string%(127) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - [%u|b%"col2"]=> - %unicode|string%(127) "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" -} -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_default.phpt b/ext/mysqli/tests/mysqli_set_local_infile_default.phpt deleted file mode 100644 index 0348b01f6a..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_default.phpt +++ /dev/null @@ -1,132 +0,0 @@ ---TEST-- -mysqli_set_local_infile_default() ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); -if (!$link) - die(sprintf("skip Can't connect [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - - $link = $tmp = null; - if (!is_null($tmp = @mysqli_set_local_infile_default())) - printf("[001] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); - - if (!is_null($tmp = @mysqli_set_local_infile_default($link))) - printf("[002] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); - - $link = new mysqli(); - if (!is_null($tmp = @mysqli_set_local_infile_default($link))) - printf("[002a] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); - - include("table.inc"); - - if (!is_null($tmp = @mysqli_set_local_infile_default($link, 'foo'))) - printf("[003] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); - - - function callback_simple($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation); - - $invocation++; - if (!is_resource($fp)) - printf("[012] First argument passed to callback is not a resource but %s/%s\n", - $fp, gettype($fp)); - - if (!$buffer = fread($fp, $buflen)) { - if ($invocation == 1) { - printf("[013] Cannot read from stream\n"); - $error = 'Cannot read from stream'; - } else { - return strlen($buffer); - } - } - - $lines = explode("\n", $buffer); - if (count($lines) != 4 && strlen($buffer) > 0) { - printf("[014] Test is too simple to handle a buffer of size %d that cannot hold all lines\n", $buflen); - $error = 'Parser too simple'; - } - - $buffer = ''; - foreach ($lines as $k => $line) { - if ('' === trim($line)) - continue; - - $columns = explode(';', $line); - if (empty($columns)) { - printf("[015] Cannot parse columns\n"); - $error = 'Cannot parse columns'; - } - - // increase id column value - $columns[0] += 1; - $buffer .= implode(';', $columns); - $buffer .= "\n"; - } - - return strlen($buffer); - } - - $file = create_standard_csv(4); - $expected = array( - array('id' => 98, 'label' => 'x'), - array('id' => 99, 'label' => 'y'), - array('id' => 100, 'label' => 'z'), - ); - try_handler(10, $link, $file, 'callback_simple', $expected); - - $expected = array( - array('id' => 97, 'label' => 'x'), - array('id' => 98, 'label' => 'y'), - array('id' => 99, 'label' => 'z'), - ); - try_handler(20, $link, $file, 'default', $expected); - - $expected = array( - array('id' => 98, 'label' => 'x'), - array('id' => 99, 'label' => 'y'), - array('id' => 100, 'label' => 'z'), - ); - try_handler(30, $link, $file, 'callback_simple', $expected); - - mysqli_close($link); - - if (!is_null($tmp = @mysqli_set_local_infile_default($link))) - printf("[300] Expecting NULL/NULL got %s/%s\n", $tmp, gettype($tmp)); - - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_simple' -Callback: 0 -Callback: 1 -Callback set to 'default' -Callback set to 'callback_simple' -Callback: 2 -Callback: 3 -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler.phpt deleted file mode 100644 index 58f4c70351..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler.phpt +++ /dev/null @@ -1,196 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_simple($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation); - - $invocation++; - if (!is_resource($fp)) - printf("[012] First argument passed to callback is not a resource but %s/%s\n", - $fp, gettype($fp)); - - if (!$buffer = fread($fp, $buflen)) { - if ($invocation == 1) { - printf("[013] Cannot read from stream\n"); - $error = 'Cannot read from stream'; - } else { - return strlen($buffer); - } - } - - $lines = explode("\n", $buffer); - if (count($lines) != 4 && strlen($buffer) > 0) { - printf("[014] Test is too simple to handle a buffer of size %d that cannot hold all lines\n", $buflen); - $error = 'Parser too simple'; - } - - $buffer = ''; - foreach ($lines as $k => $line) { - if ('' === trim($line)) - continue; - - $columns = explode(';', $line); - if (empty($columns)) { - printf("[015] Cannot parse columns\n"); - $error = 'Cannot parse columns'; - } - - // increase id column value - $columns[0] += 1; - $buffer .= implode(';', $columns); - $buffer .= "\n"; - } - - return strlen($buffer); - } - - function callback_fclose($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - - fclose($fp); - return strlen($buffer); - } - - function callback_closefile($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - flush(); - if (is_resource($fp)) - fclose($fp); - $buffer = "1;'a';\n"; - if ($invocation > 10) - return 0; - - return strlen($buffer); - } - - function callback_invalid_args($fp, &$buffer, $buflen) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - $buffer = fread($fp, $buflen); - - return strlen($buffer); - } - - function callback_error($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - $buffer = fread($fp, $buflen); - $error = 'How to access this error?'; - - return -1; - } - - if (!is_null($tmp = @mysqli_set_local_infile_handler())) - printf("[001] Expecting NULL/NULL got %s/%s\n", $tmp, gettype($tmp)); - - $handle = null; - if (!is_null($tmp = @mysqli_set_local_infile_handler($handle))) - printf("[002] Expecting NULL/NULL got %s/%s\n", $tmp, gettype($tmp)); - - $handle = @new mysqli(); - if (!is_null($tmp = @mysqli_set_local_infile_handler($handle, 'callback_simple'))) - printf("[003] Expecting NULL/NULL got %s/%s\n", $tmp, gettype($tmp)); - - if (false !== ($tmp = @mysqli_set_local_infile_handler($link, 'unknown'))) - printf("[004] Expecting false/boolean got %s/%s\n", $tmp, gettype($tmp)); - - $file = create_standard_csv(5); - - $expected = array( - array('id' => 98, 'label' => 'x'), - array('id' => 99, 'label' => 'y'), - array('id' => 100, 'label' => 'z'), - ); - try_handler(10, $link, $file, 'callback_simple', $expected); - - $expected = array(); - try_handler(20, $link, $file, 'callback_fclose', $expected); - - // FIXME - TODO - KLUDGE - - // IMHO this is wrong. ext/mysqli should bail as the function signature - // is not complete. That's a BC break, OK, but it makes perfectly sense. - $expected = array(); - try_handler(30, $link, $file, 'callback_invalid_args', $expected); - - $expected = array(); - try_handler(40, $link, $file, 'callback_error', $expected); - - - mysqli_close($link); - - if (!is_null($tmp = @mysqli_set_local_infile_handler($link, 'callback_simple'))) - printf("[300] Expecting NULL/NULL got %s/%s\n", $tmp, gettype($tmp)); - - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_simple' -Callback: 0 -Callback: 1 -Callback set to 'callback_fclose' -Callback: 0 -[022] LOAD DATA failed, [2000] File handle close%s -Callback set to 'callback_invalid_args' -Callback: 0 -Callback: 1 -[037] More results than expected! -array(2) { - [%u|b%"id"]=> - %unicode|string%(2) "97" - [%u|b%"label"]=> - %unicode|string%(1) "x" -} -array(2) { - [%u|b%"id"]=> - %unicode|string%(2) "98" - [%u|b%"label"]=> - %unicode|string%(1) "y" -} -array(2) { - [%u|b%"id"]=> - %unicode|string%(2) "99" - [%u|b%"label"]=> - %unicode|string%(1) "z" -} -Callback set to 'callback_error' -Callback: 0 -[042] LOAD DATA failed, [2000] How to access this error? -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_bad_character.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_bad_character.phpt deleted file mode 100644 index b8f51c214f..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_bad_character.phpt +++ /dev/null @@ -1,82 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - random ASCII character including \0 ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); -require_once('connect.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_bad_character($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - - $num_chars = (version_compare(PHP_VERSION, '5.9.9', '>') == 1) ? (floor($buflen / 2) - 10) : ($buflen - 5); - $part1 = floor($num_chars / 2); - $part2 = $num_chars - $part1; - - $buffer = ''; - for ($i = 0; $i < $part1; $i++) - $buffer .= chr(mt_rand(0, 255)); - - $buffer .= ';"'; - - for ($i = 0; $i < $part2; $i++) - $buffer .= chr(mt_rand(0, 255)); - - $buffer .= '";'; - if ($invocation > 10) - return 0; - - return strlen($buffer); - } - - $file = create_standard_csv(5); - /* we feed the handler with random data, therefore we cannot specify and expected rows */ - try_handler(20, $link, $file, 'callback_bad_character'); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_bad_character' -Callback: 0 -Callback: 1 -Callback: 2 -Callback: 3 -Callback: 4 -Callback: 5 -Callback: 6 -Callback: 7 -Callback: 8 -Callback: 9 -Callback: 10 -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_buffer_overflow.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_buffer_overflow.phpt deleted file mode 100644 index a3c8801023..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_buffer_overflow.phpt +++ /dev/null @@ -1,60 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - buffer overflow ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_buffer_overflow($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation); - $buffer = fread($fp, $buflen); - - $buffer = str_repeat(';', $buflen * 2); - return strlen($buffer); - } - - $file = create_standard_csv(5); - $expected = array(); - try_handler(20, $link, $file, 'callback_buffer_overflow', $expected); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_buffer_overflow' -Callback: 0 - -Warning: mysqli_query(): Too much data returned in %s on line %d -[022] LOAD DATA failed, [%d] Too much data returned -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_close_link.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_close_link.phpt deleted file mode 100644 index 408bb29ec4..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_close_link.phpt +++ /dev/null @@ -1,61 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - close database link ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require("table.inc"); - require_once('local_infile_tools.inc'); - - function callback_close_link($fp, &$buffer, $buflen, &$error) { - global $link; - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - flush(); - if (is_object($link)) - mysqli_close($link); - - $buffer = "1;'a';\n"; - if ($invocation > 10) - return 0; - - return strlen($buffer); - } - - $file = create_standard_csv(1); - $expected = array(array('id' => 1, 'label' => 'a')); - try_handler(20, $link, $file, 'callback_close_link', $expected); - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_close_link' -Callback: 0 -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_closefile.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_closefile.phpt deleted file mode 100644 index 168cbc1358..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_closefile.phpt +++ /dev/null @@ -1,70 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - do not use the file pointer ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once("table.inc"); - require_once('local_infile_tools.inc'); - - function callback_closefile($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - flush(); - if (is_resource($fp)) - fclose($fp); - $buffer = "1;'a';\n"; - if ($invocation > 10) - return 0; - - return strlen($buffer); - } - - $file = create_standard_csv(1); - $expected = array(array('id' => 1, 'label' => 'a')); - try_handler(20, $link, $file, 'callback_closefile', $expected); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_closefile' -Callback: 0 -Callback: 1 -Callback: 2 -Callback: 3 -Callback: 4 -Callback: 5 -Callback: 6 -Callback: 7 -Callback: 8 -Callback: 9 -Callback: 10 -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_closures.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_closures.phpt deleted file mode 100644 index ad7ab32c1c..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_closures.phpt +++ /dev/null @@ -1,62 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - use closures as handler ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - $callback_replace_buffer = function ($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - flush(); - - $buffer = fread($fp, $buflen); - - if ($invocation > 10) - return 0; - - return strlen($buffer); - }; - - $file = create_standard_csv(1); - if (!try_handler(20, $link, $file, $callback_replace_buffer, null)) - printf("[008] Failure\n"); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'Closure object' -Callback: 0 -Callback: 1 -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_kill_link.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_kill_link.phpt deleted file mode 100644 index b2b42a22e5..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_kill_link.phpt +++ /dev/null @@ -1,61 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - kill database link ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require("table.inc"); - require_once('local_infile_tools.inc'); - - function callback_kill_link($fp, &$buffer, $buflen, &$error) { - global $link; - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - flush(); - if (is_object($link)) - mysqli_kill($link, mysqli_thread_id($link)); - - $buffer = "1;'a';\n"; - if ($invocation > 10) - return 0; - - mysqli_set_local_infile_default($link); - return strlen($buffer); - } - - $file = create_standard_csv(1); - $expected = array(array('id' => 1, 'label' => 'a')); - try_handler(20, $link, $file, 'callback_kill_link', $expected); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_kill_link' -Callback: 0 -[022] LOAD DATA failed, [2000] Can't execute load data local init callback function -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_negative_len.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_negative_len.phpt deleted file mode 100644 index 16e38c5fa2..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_negative_len.phpt +++ /dev/null @@ -1,58 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - negative return value/buflen to indicate an error ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_negative_len($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation); - $buffer = fread($fp, $buflen); - - $error = "negative length means error"; - return -1; - } - - $file = create_standard_csv(1); - $expected = array(); - try_handler(20, $link, $file, 'callback_negative_len', $expected); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_negative_len' -Callback: 0 -[022] LOAD DATA failed, [2000] negative length means error -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_nested_call.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_nested_call.phpt deleted file mode 100644 index 4663fe236e..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_nested_call.phpt +++ /dev/null @@ -1,107 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - nested calls ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_simple($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback - callback_simple(): %d\n", $invocation); - - $invocation++; - if (!is_resource($fp)) - printf("[012] First argument passed to callback is not a resource but %s/%s\n", - $fp, gettype($fp)); - - if (!$buffer = fread($fp, $buflen)) { - if ($invocation == 1) { - printf("[013] Cannot read from stream\n"); - $error = 'Cannot read from stream'; - } else { - return strlen($buffer); - } - } - - $lines = explode("\n", $buffer); - if (count($lines) != 4 && strlen($buffer) > 0) { - printf("[014] Test is too simple to handle a buffer of size %d that cannot hold all lines\n", $buflen); - $error = 'Parser too simple'; - } - - $buffer = ''; - foreach ($lines as $k => $line) { - if ('' === trim($line)) - continue; - - $columns = explode(';', $line); - if (empty($columns)) { - printf("[015] Cannot parse columns\n"); - $error = 'Cannot parse columns'; - } - - // increase id column value - $columns[0] += 1; - $buffer .= implode(';', $columns); - $buffer .= "\n"; - } - - /* report the wrong length */ - return strlen($buffer); - } - - function callback_report_short_len($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback - report_short_len(): %d\n", $invocation++); - return callback_simple($fp, $buffer, $buflen, $error); - } - - $file = create_standard_csv(1); - $expected = array( - array('id' => 98, 'label' => 'x'), - array('id' => 99, 'label' => 'y'), - array('id' => 100, 'label' => 'z'), - ); - try_handler(20, $link, $file, 'callback_report_short_len', $expected); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_report_short_len' -Callback - report_short_len(): 0 -Callback - callback_simple(): 0 -Callback - report_short_len(): 1 -Callback - callback_simple(): 1 -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_new_query.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_new_query.phpt deleted file mode 100644 index ca06435c5e..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_new_query.phpt +++ /dev/null @@ -1,71 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - run new query on db link ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_new_query($fp, &$buffer, $buflen, &$error) { - global $link; - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - flush(); - if (is_object($link)) { - if (!$res = mysqli_query($link, "SELECT id, label FROM test")) { - printf("[Callback 001 - %03d] Cannot run query, [%d] %s\n", - $invocation, mysqli_errno($link), mysqli_error($link)); - } - if ($res) - mysqli_free_result($res); - } - $buffer = "1;'a';\n"; - if ($invocation > 10) - return 0; - - mysqli_set_local_infile_default($link); - return strlen($buffer); - } - - $file = create_standard_csv(1); - $expected = array(array('id' => 1, 'label' => 'a')); - try_handler(20, $link, $file, 'callback_new_query', $expected); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_new_query' -Callback: 0 -[Callback 001 - 001] Cannot run query, [2014] Commands out of sync; you can't run this command now -[022] LOAD DATA failed, [2000] Can't execute load data local init callback function -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_nofileop.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_nofileop.phpt deleted file mode 100644 index 601a09e12c..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_nofileop.phpt +++ /dev/null @@ -1,70 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - do not use the file pointer ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_nofileop($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - flush(); - - $buffer = "1;'a';\n"; - if ($invocation > 10) - return 0; - - return strlen($buffer); - } - - $file = create_standard_csv(1); - $expected = array(array('id' => 1, 'label' => 'a')); - try_handler(20, $link, $file, 'callback_nofileop', $expected); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_nofileop' -Callback: 0 -Callback: 1 -Callback: 2 -Callback: 3 -Callback: 4 -Callback: 5 -Callback: 6 -Callback: 7 -Callback: 8 -Callback: 9 -Callback: 10 -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_openbasedir.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_openbasedir.phpt deleted file mode 100644 index 7163aca10d..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_openbasedir.phpt +++ /dev/null @@ -1,115 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - open basedir restrictions ---SKIPIF-- -<?php -if (!$fp = @fopen('skipif.inc', 'r')) - die("skip open_basedir restrictions forbid opening include files"); - -include_once('skipif.inc'); -include_once('skipifemb.inc'); -include_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -include_once('connect.inc'); -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -if (!$res = mysqli_query($link, 'SHOW VARIABLES LIKE "local_infile"')) { - mysqli_close($link); - die("skip Cannot check if Server variable 'local_infile' is set to 'ON'"); -} - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -open_basedir="." ---FILE-- -<?php - @include('connect.inc'); - if (!isset($db)) { - // stupid run-tests.php - any idea how to set system ini setting dynamically??? - print "Warning: tempnam(): open_basedir restriction in effect. File(grrr) is not within the allowed path(s): (grrr) in grrr on line 0 -[005 + 1] Cannot create CVS file '' -Callback set to 'callback_simple' -[012] LOAD DATA failed, [0] grrr -[014/0] [0] '' -done!"; - die(); - } - - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_simple($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation); - - $invocation++; - if (!is_resource($fp)) - printf("[012] First argument passed to callback is not a resource but %s/%s\n", - $fp, gettype($fp)); - - if (!$buffer = fread($fp, $buflen)) { - if ($invocation == 1) { - printf("[013] Cannot read from stream\n"); - $error = 'Cannot read from stream'; - } else { - return strlen($buffer); - } - } - - $lines = explode("\n", $buffer); - if (count($lines) != 4 && strlen($buffer) > 0) { - printf("[014] Test is too simple to handle a buffer of size %d that cannot hold all lines\n", $buflen); - $error = 'Parser too simple'; - } - - $buffer = ''; - foreach ($lines as $k => $line) { - if ('' === trim($line)) - continue; - - $columns = explode(';', $line); - if (empty($columns)) { - printf("[015] Cannot parse columns\n"); - $error = 'Cannot parse columns'; - } - - // increase id column value - $columns[0] += 1; - $buffer .= implode(';', $columns); - $buffer .= "\n"; - } - - return strlen($buffer); - } - - $file = create_standard_csv(5); - $expected = array( - array('id' => 98, 'label' => 'x'), - array('id' => 99, 'label' => 'y'), - array('id' => 100, 'label' => 'z'), - ); - try_handler(10, $link, $file, 'callback_simple', $expected); - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Warning: tempnam(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s on line %d -[005 + 1] Cannot create CVS file '' -Callback set to 'callback_simple' -[012] LOAD DATA failed, [%d] %s -[014/0] [0] '' -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_replace_buffer.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_replace_buffer.phpt deleted file mode 100644 index 0d4024e528..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_replace_buffer.phpt +++ /dev/null @@ -1,78 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - replace buffer pointer ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_replace_buffer($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - flush(); - - $buffer = fread($fp, $buflen); - - $ret = "1;'a';\n"; - $buffer = $ret; - - $num_chars = ((version_compare(PHP_VERSION, '5.9.9', '>') == 1)) ? floor($buflen / 2) : $buflen; - assert(strlen($buffer) < $num_chars); - - if ($invocation > 10) - return 0; - - return strlen($buffer); - } - - $file = create_standard_csv(1); - $expected = array(array('id' => 1, 'label' => 'a')); - if (!try_handler(20, $link, $file, 'callback_replace_buffer', $expected)) - printf("[008] Failure\n"); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_replace_buffer' -Callback: 0 -Callback: 1 -Callback: 2 -Callback: 3 -Callback: 4 -Callback: 5 -Callback: 6 -Callback: 7 -Callback: 8 -Callback: 9 -Callback: 10 -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_short_len.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_short_len.phpt deleted file mode 100644 index b3144e430e..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_short_len.phpt +++ /dev/null @@ -1,101 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - report shorter buffer ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$TEST_EXPERIMENTAL) - die("skip - experimental (= unsupported) feature"); - -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_short_len($fp, &$buffer, $buflen, &$error) { - static $invocation = 0; - - printf("Callback: %d\n", $invocation); - - $invocation++; - if (!is_resource($fp)) - printf("[012] First argument passed to callback is not a resource but %s/%s\n", - $fp, gettype($fp)); - - if (!$buffer = fread($fp, $buflen)) { - if ($invocation == 1) { - printf("[013] Cannot read from stream\n"); - $error = 'Cannot read from stream'; - } else { - return strlen($buffer); - } - } - - $lines = explode("\n", $buffer); - if (count($lines) != 4 && strlen($buffer) > 0) { - printf("[014] Test is too simple to handle a buffer of size %d that cannot hold all lines\n", $buflen); - $error = 'Parser too simple'; - } - - $buffer = ''; - foreach ($lines as $k => $line) { - if ('' === trim($line)) - continue; - - $columns = explode(';', $line); - if (empty($columns)) { - printf("[015] Cannot parse columns\n"); - $error = 'Cannot parse columns'; - } - - // increase id column value - $columns[0] += 1; - $buffer .= implode(';', $columns); - $buffer .= "\n"; - } - - /* report the wrong length */ - return strlen($buffer) - 1; - } - - $file = create_standard_csv(1); - $expected = array( - array('id' => 98, 'label' => 'x'), - array('id' => 99, 'label' => 'y'), - array('id' => 100, 'label' => 'z'), - ); - try_handler(20, $link, $file, 'callback_short_len', $expected); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_short_len' -Callback: 0 - -Warning: mysqli_query(): Mismatch between the return value of the callback and the content length of the buffer. in %s on line %d -[022] LOAD DATA failed, [2000] Mismatch between the return value of the callback and the content length of the buffer. -[024/0] [0] '' -done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_set_local_infile_handler_unregister.phpt b/ext/mysqli/tests/mysqli_set_local_infile_handler_unregister.phpt deleted file mode 100644 index f287f4d874..0000000000 --- a/ext/mysqli/tests/mysqli_set_local_infile_handler_unregister.phpt +++ /dev/null @@ -1,64 +0,0 @@ ---TEST-- -mysqli_set_local_infile_handler() - do not use the file pointer ---SKIPIF-- -<?php -require_once('skipif.inc'); -require_once('skipifemb.inc'); -require_once('skipifconnectfailure.inc'); - -if (!function_exists('mysqli_set_local_infile_handler')) - die("skip - function not available."); - -require_once('connect.inc'); -if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) - die("skip Cannot connect to MySQL"); - -include_once("local_infile_tools.inc"); -if ($msg = check_local_infile_support($link, $engine)) - die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); - -mysqli_close($link); -?> ---INI-- -mysqli.allow_local_infile=1 ---FILE-- -<?php - require_once('connect.inc'); - require_once('local_infile_tools.inc'); - require_once('table.inc'); - - function callback_unregister($fp, &$buffer, $buflen, &$error) { - global $link; - static $invocation = 0; - - printf("Callback: %d\n", $invocation++); - flush(); - if (is_resource($fp)) - fclose($fp); - $buffer = "1;'a';\n"; - if ($invocation > 10) - return 0; - - mysqli_set_local_infile_default($link); - return strlen($buffer); - } - - $file = create_standard_csv(1); - $expected = array(array('id' => 1, 'label' => 'a')); - try_handler(20, $link, $file, 'callback_unregister', $expected); - - mysqli_close($link); - print "done!"; -?> ---CLEAN-- -<?php - require_once("clean_table.inc"); -?> ---EXPECTF-- -Callback set to 'callback_unregister' -Callback: 0 - -Warning: mysqli_query(): File handle closed in %s on line %d -[022] LOAD DATA failed, [2000] File handle closed -[024/0] [0] '' -done! diff --git a/ext/mysqli/tests/mysqli_stmt_get_result_metadata_fetch_field.phpt b/ext/mysqli/tests/mysqli_stmt_get_result_metadata_fetch_field.phpt index afaccaf3c7..739bf56ea1 100644 --- a/ext/mysqli/tests/mysqli_stmt_get_result_metadata_fetch_field.phpt +++ b/ext/mysqli/tests/mysqli_stmt_get_result_metadata_fetch_field.phpt @@ -12,7 +12,13 @@ if (!function_exists('mysqli_stmt_get_result')) --FILE-- <?php require('table.inc'); - $charsets = my_get_charsets($link); + + // Make sure that client, connection and result charsets are all the + // same. Not sure whether this is strictly necessary. + if (!mysqli_set_charset($link, 'utf8')) + printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link)); + + $charsetInfo = mysqli_get_charset($link); if (!($stmt = mysqli_stmt_init($link)) || !mysqli_stmt_prepare($stmt, "SELECT id, label, id + 1 as _id, concat(label, '_') ___label FROM test ORDER BY id ASC LIMIT 3") || @@ -39,15 +45,14 @@ if (!function_exists('mysqli_stmt_get_result')) Label column, result set charset. All of the following columns are "too hot" - too server dependent */ - if ($field->charsetnr != $charsets['results']['nr']) { + if ($field->charsetnr != $charsetInfo->number) { printf("[004] Expecting charset %s/%d got %d\n", - $charsets['results']['charset'], - $charsets['results']['nr'], $field->charsetnr); + $charsetInfo->charset, + $charsetInfo->number, $field->charsetnr); } - if ($field->length != (1 * $charsets['results']['maxlen'])) { + if ($field->length != $charsetInfo->max_length) { printf("[005] Expecting length %d got %d\n", - $charsets['results']['maxlen'], - $field->max_length); + $charsetInfo->max_length, $field->max_length); } } } @@ -173,4 +178,4 @@ object(stdClass)#%d (13) { [%u|b%"decimals"]=> int(31) } -done!
\ No newline at end of file +done! diff --git a/ext/mysqli/tests/table.inc b/ext/mysqli/tests/table.inc index ec360c8f2c..e0d7a06c57 100644 --- a/ext/mysqli/tests/table.inc +++ b/ext/mysqli/tests/table.inc @@ -17,7 +17,7 @@ if (!mysqli_query($link, 'SET SESSION sql_mode=\'\'')) { exit(1); } -if (!mysqli_query($link, 'CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE=' . $engine)) { +if (!mysqli_query($link, 'CREATE TABLE test(id INT DEFAULT 0, label CHAR(1), PRIMARY KEY(id)) ENGINE=' . $engine)) { printf("Failed to create test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); exit(1); } |