Author: uwendel
Date: 2007-07-20 13:56:54 +0200 (Fri, 20 Jul 2007)
New Revision: 805
Modified:
trunk/tests/ext/mysqli/mysqli_set_local_infile_default.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_bad_character.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_buffer_overflow.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_close_link.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_closefile.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_kill_link.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_negative_len.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nested_call.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_new_query.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nofileop.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_replace_buffer.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_short_len.phpt
trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_unregister.phpt
Log:
Space2Tab and a general clean up
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_default.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_default.phpt 2007-07-19 15:52:37 UTC
(rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_default.phpt 2007-07-20 11:56:54 UTC
(rev 805)
@@ -14,7 +14,8 @@
?>
--FILE--
<?php
- include "connect.inc";
+ require_once('connect.inc');
+ require_once('local_infile_tools.inc');
$link = $tmp = null;
if (!is_null($tmp = @mysqli_set_local_infile_default()))
@@ -74,91 +75,7 @@
return strlen($buffer);
}
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'w'))
- printf("[004] Cannot create CVS file '%s'\n", $file);
-
- if (!fwrite($fp, "97;'x';\n") ||
- !fwrite($fp, "98;'y';\n") ||
- !fwrite($fp, "99;'z';\n"))
- printf("[005] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[006] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might not
be able to read it\n",
- $file);
-
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if ('default' == $handler) {
- mysqli_set_local_infile_default($link);
- printf("Callback set to default\n");
- } else {
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
- }
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
- if (0 !== mysqli_warning_count($link)) {
- printf("[%03d] There are warnings!\n", $offset + 3);
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 4, mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 5, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 7, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d] More results than expected! Dumping data \n", $offset + 7);
- do {
- var_dump($tmp);
- } while ($tmp = mysqli_fetch_assoc($res));
- }
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
+ $file = create_standard_csv(4);
$expected = array(
array('id' => 98, 'label' => 'x'),
array('id' => 99, 'label' => 'y'),
@@ -191,7 +108,7 @@
Callback set to 'callback_simple'
Callback: 0
Callback: 1
-Callback set to default
+Callback set to 'default'
Callback set to 'callback_simple'
Callback: 2
Callback: 3
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler.phpt 2007-07-19 15:52:37 UTC
(rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler.phpt 2007-07-20 11:56:54 UTC
(rev 805)
@@ -1,229 +1,162 @@
--TEST--
mysqli_set_local_infile_handler()
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
-require_once('skipifemb.inc');
+require_once('skipifemb.inc');
require_once('connect.inc');
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
-
+ die("skip - function not available.");
+
+require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include "connect.inc";
- include("table.inc");
+ require_once('connect.inc');
+ require_once('local_infile_tools.inc');
+ require_once('table.inc');
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
+ 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_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_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));
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'w'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ function callback_fclose($fp, &$buffer, $buflen, &$error) {
+ static $invocation = 0;
- if (!fwrite($fp, "97;'x';\n") ||
- !fwrite($fp, "98;'y';\n") ||
- !fwrite($fp, "99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
+ printf("Callback: %d\n", $invocation++);
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
- if (0 !== mysqli_warning_count($link)) {
- printf("[%03d] There are warnings!\n", $offset + 3);
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 4, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
+ fclose($fp);
+ return strlen($buffer);
+ }
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 5, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 7, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d] More results than expected! Dumping data \n", $offset + 7);
- do {
- var_dump($tmp);
- } while ($tmp = mysqli_fetch_assoc($res));
- }
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
- $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);
-
- $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));
+ function callback_closefile($fp, &$buffer, $buflen, &$error) {
+ static $invocation = 0;
- print "done!";
+ 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);
+
+ $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!";
?>
--EXPECTF--
+Callback set to 'callback_simple'
+Callback: 0
+Callback: 1
Callback set to 'callback_fclose'
Callback: 0
-Should bail!
Callback set to 'callback_invalid_args'
-Callback: 0
Should bail!
Callback set to 'callback_error'
Callback: 0
+
+Warning: mysqli_query(): How to access this error? in %s on line %d
[042] LOAD DATA failed, [2000] How to access this error?
-done!
+done!
\ No newline at end of file
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_bad_character.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_bad_character.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_bad_character.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,102 +1,54 @@
--TEST--
mysqli_set_local_infile_handler() - random ASCII character including \0
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
-require_once('skipifemb.inc');
+require_once('skipifemb.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");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include_once "connect.inc";
- include_once("table.inc");
+ require_once('connect.inc');
+ require_once('local_infile_tools.inc');
+ require_once('table.inc');
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
- function callback_bad_character($fp, &$buffer, $buflen, &$error) {
- static $invocation = 0;
+ function callback_bad_character($fp, &$buffer, $buflen, &$error) {
+ static $invocation = 0;
- printf("Callback: %d\n", $invocation++);
+ printf("Callback: %d\n", $invocation++);
- $num_chars = (ini_get('unicode.semantics')) ? (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));
+ $num_chars = (ini_get('unicode.semantics')) ? (floor($buflen / 2) - 10) : ($buflen -
5);
+ $part1 = floor($num_chars / 2);
+ $part2 = $num_chars - $part1;
- $buffer .= ';"';
-
- for ($i = 0; $i < $part2; $i++)
- $buffer .= chr(mt_rand(0, 255));
-
- $buffer .= '";';
- if ($invocation > 10)
- return 0;
-
- return strlen($buffer);
- }
-
- function try_handler($offset, $link, $file, $handler) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- return true;
- }
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'wb'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ $buffer = '';
+ for ($i = 0; $i < $part1; $i++)
+ $buffer .= chr(mt_rand(0, 255));
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
-
- try_handler(20, $link, $file, 'callback_bad_character');
-
- mysqli_close($link);
- print "done!";
+ $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!";
?>
--EXPECTF--
Callback set to 'callback_bad_character'
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_buffer_overflow.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_buffer_overflow.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_buffer_overflow.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,121 +1,39 @@
--TEST--
mysqli_set_local_infile_handler() - buffer overflow
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
-require_once('skipifemb.inc');
-include_once('connect.inc');
+require_once('skipifemb.inc');
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
+ die("skip - function not available.");
+include_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include_once "connect.inc";
- include_once ("table.inc");
-
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
- 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);
- }
-
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
+ require_once('connect.inc');
+ require_once('local_infile_tools.inc');
+ require_once('table.inc');
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 5, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res))
- printf("[%03d] More results than expected!\n");
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'w'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ function callback_buffer_overflow($fp, &$buffer, $buflen, &$error) {
+ static $invocation = 0;
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
+ printf("Callback: %d\n", $invocation);
+ $buffer = fread($fp, $buflen);
-
- $expected = array(
- );
- try_handler(20, $link, $file, 'callback_buffer_overflow', $expected);
-
- mysqli_close($link);
- print "done!";
+ $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!";
?>
--EXPECTF--
Callback set to 'callback_buffer_overflow'
@@ -123,4 +41,4 @@
Warning: mysqli_query(): Too much data returned in %s on line %d
[022] LOAD DATA failed, [%d] Too much data returned
-done!
+done!
\ No newline at end of file
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_close_link.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_close_link.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_close_link.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,125 +1,44 @@
--TEST--
mysqli_set_local_infile_handler() - close database link
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
-require_once('skipifemb.inc');
-require_once('connect.inc');
+require_once('skipifemb.inc');
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
+ die("skip - function not available.");
+require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include "connect.inc";
- include("table.inc");
+ include "connect.inc";
+ include("table.inc");
+ require_once('local_infile_tools.inc');
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
- 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);
+ function callback_close_link($fp, &$buffer, $buflen, &$error) {
+ global $link;
+ static $invocation = 0;
- $buffer = "1;'a';\n";
- if ($invocation > 10)
- return 0;
+ printf("Callback: %d\n", $invocation++);
+ flush();
+ if (is_object($link))
+ mysqli_close($link);
- return strlen($buffer);
- }
+ $buffer = "1;'a';\n";
+ if ($invocation > 10)
+ return 0;
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
+ return strlen($buffer);
+ }
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 5, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res))
- printf("[%03d] More results than expected!\n");
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'wb'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
-
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
-
-
- $expected = array(array('id' => 1, 'label' => 'a'));
- try_handler(20, $link, $file, 'callback_close_link', $expected);
-
- mysqli_close($link);
- print "done!";
+ $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!";
?>
--EXPECTF--
Callback set to 'callback_close_link'
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_closefile.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_closefile.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_closefile.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,123 +1,43 @@
--TEST--
mysqli_set_local_infile_handler() - do not use the file pointer
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
-require_once('skipifemb.inc');
-require_once('connect.inc');
+require_once('skipifemb.inc');
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
+ die("skip - function not available.");
+require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include "connect.inc";
- include("table.inc");
+ include "connect.inc";
+ include("table.inc");
+ require_once('local_infile_tools.inc');
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
- 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_closefile($fp, &$buffer, $buflen, &$error) {
+ static $invocation = 0;
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
+ printf("Callback: %d\n", $invocation++);
+ flush();
+ if (is_resource($fp))
+ fclose($fp);
+ $buffer = "1;'a';\n";
+ if ($invocation > 10)
+ return 0;
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 5, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res))
- printf("[%03d] More results than expected!\n");
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'wb'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ return strlen($buffer);
+ }
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
+ $file = create_standard_csv(1);
+ $expected = array(array('id' => 1, 'label' => 'a'));
+ try_handler(20, $link, $file, 'callback_closefile', $expected);
-
- $expected = array(array('id' => 1, 'label' => 'a'));
- try_handler(20, $link, $file, 'callback_closefile', $expected);
-
- mysqli_close($link);
- print "done!";
+ mysqli_close($link);
+ print "done!";
?>
--EXPECTF--
Callback set to 'callback_closefile'
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_kill_link.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_kill_link.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_kill_link.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,129 +1,49 @@
--TEST--
mysqli_set_local_infile_handler() - kill database link
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
-require_once('skipifemb.inc');
-require_once('connect.inc');
+require_once('skipifemb.inc');
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
+ die("skip - function not available.");
+require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include "connect.inc";
- include("table.inc");
+ include "connect.inc";
+ include("table.inc");
+ require_once('local_infile_tools.inc');
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
- 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);
- }
+ function callback_kill_link($fp, &$buffer, $buflen, &$error) {
+ global $link;
+ static $invocation = 0;
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
+ printf("Callback: %d\n", $invocation++);
+ flush();
+ if (is_object($link))
+ mysqli_kill($link, mysqli_thread_id($link));
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 5, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res))
- printf("[%03d] More results than expected!\n");
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'wb'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ $buffer = "1;'a';\n";
+ if ($invocation > 10)
+ return 0;
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
+ mysqli_set_local_infile_default($link);
+ return strlen($buffer);
+ }
-
- $expected = array(array('id' => 1, 'label' => 'a'));
- try_handler(20, $link, $file, 'callback_kill_link', $expected);
-
- mysqli_close($link);
- print "done!";
+ $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!";
?>
--EXPECTF--
Callback set to 'callback_kill_link'
Callback: 0
-[022] LOAD DATA failed, [2] Can't execute load data local init callback function
+[022] LOAD DATA failed, [2000] Can't execute load data local init callback function
done!
\ No newline at end of file
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_negative_len.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_negative_len.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_negative_len.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,124 +1,44 @@
--TEST--
mysqli_set_local_infile_handler() - negative return value/buflen to indicate an error
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
-require_once('connect.inc');
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
+ die("skip - function not available.");
+require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include_once("connect.inc");
- include_once("table.inc");
+ require_once('connect.inc');
+ require_once('local_infile_tools.inc');
+ require_once('table.inc');
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
- 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;
- }
-
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
+ function callback_negative_len($fp, &$buffer, $buflen, &$error) {
+ static $invocation = 0;
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 5, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res))
- printf("[%03d] More results than expected!\n");
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'w'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ printf("Callback: %d\n", $invocation);
+ $buffer = fread($fp, $buflen);
- if (!fwrite($fp, "97;'x';\n") ||
- !fwrite($fp, "98;'y';\n") ||
- !fwrite($fp, "99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
+ $error = "negative length means error";
+ return -1;
+ }
-
- $expected = array(
- );
- try_handler(20, $link, $file, 'callback_negative_len', $expected);
-
- mysqli_close($link);
- print "done!";
+ $file = create_standard_csv(1);
+ $expected = array();
+ try_handler(20, $link, $file, 'callback_negative_len', $expected);
+
+ mysqli_close($link);
+ print "done!";
?>
--EXPECTF--
Callback set to 'callback_negative_len'
Callback: 0
+
+Warning: mysqli_query(): negative length means error in %s on line %d
[022] LOAD DATA failed, [2000] negative length means error
done!
\ No newline at end of file
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nested_call.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nested_call.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nested_call.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,170 +1,86 @@
--TEST--
mysqli_set_local_infile_handler() - nested calls
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
-require_once('connect.inc');
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
-
+ die("skip - function not available.");
+
+require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include "connect.inc";
- include("table.inc");
-
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
+ 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_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);
- }
-
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 5, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d] More results than expected! Dumping data \n", $offset + 7);
- do {
- var_dump($tmp);
- } while ($tmp = mysqli_fetch_assoc($res));
- }
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'w'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ function callback_report_short_len($fp, &$buffer, $buflen, &$error) {
+ static $invocation = 0;
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
+ printf("Callback - report_short_len(): %d\n", $invocation++);
+ return callback_simple($fp, $buffer, $buflen, $error);
+ }
-
- $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!";
+ $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!";
?>
--EXPECTF--
Callback set to 'callback_report_short_len'
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_new_query.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_new_query.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_new_query.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,136 +1,55 @@
--TEST--
mysqli_set_local_infile_handler() - run new query on db link
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
-require_once('skipifemb.inc');
-require_once('connect.inc');
+require_once('skipifemb.inc');
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
+ die("skip - function not available.");
+require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include "connect.inc";
- include("table.inc");
+ require_once('connect.inc');
+ require_once('local_infile_tools.inc');
+ require_once('table.inc');
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
- 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);
- }
+ function callback_new_query($fp, &$buffer, $buflen, &$error) {
+ global $link;
+ static $invocation = 0;
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
+ 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;
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 5, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res))
- printf("[%03d] More results than expected!\n");
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'wb'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ mysqli_set_local_infile_default($link);
+ return strlen($buffer);
+ }
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
+ $file = create_standard_csv(1);
+ $expected = array(array('id' => 1, 'label' => 'a'));
+ try_handler(20, $link, $file, 'callback_new_query', $expected);
-
- $expected = array(array('id' => 1, 'label' => 'a'));
- try_handler(20, $link, $file, 'callback_new_query', $expected);
-
- mysqli_close($link);
- print "done!";
+ mysqli_close($link);
+ print "done!";
?>
--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, [2] Can't execute load data local init callback function
+[022] LOAD DATA failed, [2000] Can't execute load data local init callback function
done!
\ No newline at end of file
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nofileop.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nofileop.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nofileop.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,122 +1,42 @@
--TEST--
mysqli_set_local_infile_handler() - do not use the file pointer
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
-require_once('connect.inc');
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
-
+ die("skip - function not available.");
+
+require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include "connect.inc";
- include("table.inc");
+ require_once('connect.inc');
+ require_once('local_infile_tools.inc');
+ require_once('table.inc');
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
- 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);
- }
+ function callback_nofileop($fp, &$buffer, $buflen, &$error) {
+ static $invocation = 0;
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
+ printf("Callback: %d\n", $invocation++);
+ flush();
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 5, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res))
- printf("[%03d] More results than expected!\n");
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'wb'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ $buffer = "1;'a';\n";
+ if ($invocation > 10)
+ return 0;
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
+ return strlen($buffer);
+ }
-
- $expected = array(array('id' => 1, 'label' => 'a'));
- try_handler(20, $link, $file, 'callback_nofileop', $expected);
-
- mysqli_close($link);
- print "done!";
+ $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!";
?>
--EXPECTF--
Callback set to 'callback_nofileop'
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_replace_buffer.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_replace_buffer.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_replace_buffer.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,131 +1,50 @@
--TEST--
mysqli_set_local_infile_handler() - replace buffer pointer
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
-require_once('skipifemb.inc');
-require_once('connect.inc');
+require_once('skipifemb.inc');
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
-
+ die("skip - function not available.");
+
+require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include "connect.inc";
- include("table.inc");
-
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
- 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 = (ini_get('unicode.semantics')) ? floor($buflen / 2) : $buflen;
- assert(strlen($buffer) < $num_chars);
-
- if ($invocation > 10)
- return 0;
-
- return strlen($buffer);
- }
+ require_once('connect.inc');
+ require_once('local_infile_tools.inc');
+ require_once('table.inc');
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
+ function callback_replace_buffer($fp, &$buffer, $buflen, &$error) {
+ static $invocation = 0;
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
-
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 5, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res))
- printf("[%03d] More results than expected!\n", $offset + 7);
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'wb'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ printf("Callback: %d\n", $invocation++);
+ flush();
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
+ $buffer = fread($fp, $buflen);
-
- $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!";
+ $ret = "1;'a';\n";
+ $buffer = $ret;
+
+ $num_chars = (ini_get('unicode.semantics')) ? 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!";
?>
--EXPECTF--
Callback set to 'callback_replace_buffer'
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_short_len.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_short_len.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_short_len.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -1,166 +1,85 @@
--TEST--
mysqli_set_local_infile_handler() - report shorter buffer
--SKIPIF--
-<?php
+<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
-require_once('connect.inc');
-
+
if (!function_exists('mysqli_set_local_infile_handler'))
- die("skip - function not available.");
+ die("skip - function not available.");
+require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
- die("skip - experimental (= unsupported) feature");
+ die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
- include "connect.inc";
- include("table.inc");
-
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
- 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;
- }
-
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
+ require_once('connect.inc');
+ require_once('local_infile_tools.inc');
+ require_once('table.inc');
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 5, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d] More results than expected! Dumping data \n", $offset + 7);
- do {
- var_dump($tmp);
- } while ($tmp = mysqli_fetch_assoc($res));
- }
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'w'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
+ function callback_short_len($fp, &$buffer, $buflen, &$error) {
+ static $invocation = 0;
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
- $file);
+ printf("Callback: %d\n", $invocation);
-
- $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!";
+ $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!";
?>
--EXPECTF--
Callback set to 'callback_short_len'
Callback: 0
-Callback: 1
-done!
+
+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
Modified: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_unregister.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_unregister.phpt 2007-07-19
15:52:37 UTC (rev 804)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_unregister.phpt 2007-07-20
11:56:54 UTC (rev 805)
@@ -14,15 +14,10 @@
?>
--FILE--
<?php
- include "connect.inc";
- include("table.inc");
+ require_once('connect.inc');
+ require_once('local_infile_tools.inc');
+ require_once('table.inc');
- function shutdown_clean($file) {
- if ($file) {
- unlink($file);
- }
- }
-
function callback_unregister($fp, &$buffer, $buflen, &$error) {
global $link;
static $invocation = 0;
@@ -39,95 +34,7 @@
return strlen($buffer);
}
- function try_handler($offset, $link, $file, $handler, $expected) {
-
- if ('default' == $handler) {
- mysqli_set_local_infile_default($link);
- printf("Callback set to default\n");
- } else {
- if (!mysqli_set_local_infile_handler($link, $handler)) {
- printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
- return false;
- }
- printf("Callback set to '%s'\n", $handler);
- }
-
- if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
- printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
-
-
- if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
- INTO TABLE test
- FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\''
- LINES TERMINATED BY '\n'",
- mysqli_real_escape_string($link, $file)))) {
- printf("[%03d] LOAD DATA failed, [%d] %s\n",
- $offset + 2,
- mysqli_errno($link), mysqli_error($link));
- }
- if (0 !== mysqli_warning_count($link)) {
- printf("[%03d] There are warnings!\n", $offset + 3);
- }
-
- if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
- printf("[%03d] [%d] %s\n", $offset + 4, mysqli_errno($link), mysqli_error($link));
- return false;
- }
-
- foreach ($expected as $k => $values) {
- if (!$tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d/%d] [%d] %s\n", $offset + 5, $k, mysqli_errno($link),
mysqli_error($link));
- return false;
- }
- if ($values['id'] != $tmp['id']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 6, $k,
- $values['id'], $tmp['id']);
- return false;
- }
- if ($values['label'] != $tmp['label']) {
- printf("[%03d/%d] Expecting %s got %s\n",
- $offset + 7, $k,
- $values['label'], $tmp['label']);
- return false;
- }
- }
-
- if ($res && $tmp = mysqli_fetch_assoc($res)) {
- printf("[%03d] More results than expected! Dumping data \n", $offset + 7);
- do {
- var_dump($tmp);
- } while ($tmp = mysqli_fetch_assoc($res));
- }
-
- if ($res)
- mysqli_free_result($res);
-
- return true;
- }
-
-
- // create a CVS file
- $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
- if (!$fp = fopen($file, 'wb'))
- printf("[005] Cannot create CVS file '%s'\n", $file);
- else
- register_shutdown_function("shutdown_clean", $file);
-
- if (!fwrite($fp, (binary)"97;'x';\n") ||
- !fwrite($fp, (binary)"98;'y';\n") ||
- !fwrite($fp, (binary)"99;'z';\n"))
- printf("[006] Cannot write CVS file '%s'\n", $file);
-
- fclose($fp);
-
- if (!chmod($file, 0644))
- printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might not
be able to read it\n",
- $file);
-
-
+ $file = create_standard_csv(1);
$expected = array(array('id' => 1, 'label' => 'a'));
try_handler(20, $link, $file, 'callback_unregister', $expected);
@@ -137,4 +44,5 @@
--EXPECTF--
Callback set to 'callback_unregister'
Callback: 0
+[022] LOAD DATA failed, [2000] Can't execute load data local init callback function
done!
\ No newline at end of file
| Thread |
|---|
| • PHP mysqlnd svn commit: r805 - trunk/tests/ext/mysqli | uwendel | 20 Jul |