1--TEST--
2mysqli_set_local_infile_handler() - random ASCII character including \0
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8require_once('connect.inc');
9
10if (!function_exists('mysqli_set_local_infile_handler'))
11    die("skip - function not available.");
12
13if (!$TEST_EXPERIMENTAL)
14    die("skip - experimental (= unsupported) feature");
15
16if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
17	die("skip Cannot connect to MySQL");
18
19include_once("local_infile_tools.inc");
20if ($msg = check_local_infile_support($link, $engine))
21	die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error));
22
23mysqli_close($link);
24?>
25--INI--
26mysqli.allow_local_infile=1
27--FILE--
28<?php
29	require_once('connect.inc');
30	require_once('local_infile_tools.inc');
31	require_once('table.inc');
32
33	function callback_bad_character($fp, &$buffer, $buflen, &$error) {
34		static $invocation = 0;
35
36		printf("Callback: %d\n", $invocation++);
37
38		$num_chars = (version_compare(PHP_VERSION, '5.9.9', '>') == 1) ? (floor($buflen / 2) - 10) : ($buflen - 5);
39		$part1 = floor($num_chars / 2);
40		$part2 = $num_chars - $part1;
41
42		$buffer = '';
43		for ($i = 0; $i < $part1; $i++)
44			$buffer .= chr(mt_rand(0, 255));
45
46		$buffer .= ';"';
47
48		for ($i = 0; $i < $part2; $i++)
49			$buffer .= chr(mt_rand(0, 255));
50
51		$buffer .= '";';
52		if ($invocation > 10)
53			return 0;
54
55		return strlen($buffer);
56	}
57
58	$file = create_standard_csv(5);
59	/* we feed the handler with random data, therefore we cannot specify and expected rows */
60	try_handler(20, $link, $file, 'callback_bad_character');
61
62	mysqli_close($link);
63	print "done!";
64?>
65--CLEAN--
66<?php
67	require_once("clean_table.inc");
68?>
69--EXPECTF--
70Callback set to 'callback_bad_character'
71Callback: 0
72Callback: 1
73Callback: 2
74Callback: 3
75Callback: 4
76Callback: 5
77Callback: 6
78Callback: 7
79Callback: 8
80Callback: 9
81Callback: 10
82done!