1--TEST--
2mysqli_set_local_infile_handler() - replace buffer pointer
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8
9if (!function_exists('mysqli_set_local_infile_handler'))
10	die("skip - function not available.");
11
12require_once('connect.inc');
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_replace_buffer($fp, &$buffer, $buflen, &$error) {
34		static $invocation = 0;
35
36		printf("Callback: %d\n", $invocation++);
37		flush();
38
39		$buffer = fread($fp, $buflen);
40
41		$ret = "1;'a';\n";
42		$buffer = $ret;
43
44		$num_chars = ((version_compare(PHP_VERSION, '5.9.9', '>') == 1)) ? floor($buflen / 2) : $buflen;
45		assert(strlen($buffer) < $num_chars);
46
47		if ($invocation > 10)
48			return 0;
49
50		return strlen($buffer);
51	}
52
53	$file = create_standard_csv(1);
54	$expected = array(array('id' => 1, 'label' => 'a'));
55	if (!try_handler(20, $link, $file, 'callback_replace_buffer', $expected))
56		printf("[008] Failure\n");
57
58	mysqli_close($link);
59	print "done!";
60?>
61--CLEAN--
62<?php
63	require_once("clean_table.inc");
64?>
65--EXPECTF--
66Callback set to 'callback_replace_buffer'
67Callback: 0
68Callback: 1
69Callback: 2
70Callback: 3
71Callback: 4
72Callback: 5
73Callback: 6
74Callback: 7
75Callback: 8
76Callback: 9
77Callback: 10
78done!