mirror of
https://github.com/php/php-src.git
synced 2024-10-19 07:22:40 +00:00
110 lines
2.8 KiB
Plaintext
110 lines
2.8 KiB
Plaintext
|
--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 = mysqli_connect($host, $user, $passwb, $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'");
|
||
|
}
|
||
|
|
||
|
$row = mysqli_fetch_assoc($res);
|
||
|
mysqli_free_result($res);
|
||
|
mysqli_close($link);
|
||
|
|
||
|
if ('ON' != $row['Value'])
|
||
|
die(sprintf("skip Server variable 'local_infile' seems not set to 'ON', found '%s'",
|
||
|
$row['Value']));
|
||
|
?>
|
||
|
--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!";
|
||
|
?>
|
||
|
--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!
|