File: mysqli_set_local_infile_handler_new_query.phpt

package info (click to toggle)
php5 5.4.45-0%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 140,304 kB
  • sloc: ansic: 725,735; php: 21,197; sh: 11,702; xml: 5,860; cpp: 2,974; exp: 1,514; yacc: 1,271; makefile: 1,228; pascal: 686; awk: 538; perl: 315; sql: 22
file content (71 lines) | stat: -rw-r--r-- 1,918 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--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!