1--TEST-- 2mysqli_set_local_infile_handler() - nested calls 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_simple($fp, &$buffer, $buflen, &$error) { 34 static $invocation = 0; 35 36 printf("Callback - callback_simple(): %d\n", $invocation); 37 38 $invocation++; 39 if (!is_resource($fp)) 40 printf("[012] First argument passed to callback is not a resource but %s/%s\n", 41 $fp, gettype($fp)); 42 43 if (!$buffer = fread($fp, $buflen)) { 44 if ($invocation == 1) { 45 printf("[013] Cannot read from stream\n"); 46 $error = 'Cannot read from stream'; 47 } else { 48 return strlen($buffer); 49 } 50 } 51 52 $lines = explode("\n", $buffer); 53 if (count($lines) != 4 && strlen($buffer) > 0) { 54 printf("[014] Test is too simple to handle a buffer of size %d that cannot hold all lines\n", $buflen); 55 $error = 'Parser too simple'; 56 } 57 58 $buffer = ''; 59 foreach ($lines as $k => $line) { 60 if ('' === trim($line)) 61 continue; 62 63 $columns = explode(';', $line); 64 if (empty($columns)) { 65 printf("[015] Cannot parse columns\n"); 66 $error = 'Cannot parse columns'; 67 } 68 69 // increase id column value 70 $columns[0] += 1; 71 $buffer .= implode(';', $columns); 72 $buffer .= "\n"; 73 } 74 75 /* report the wrong length */ 76 return strlen($buffer); 77 } 78 79 function callback_report_short_len($fp, &$buffer, $buflen, &$error) { 80 static $invocation = 0; 81 82 printf("Callback - report_short_len(): %d\n", $invocation++); 83 return callback_simple($fp, $buffer, $buflen, $error); 84 } 85 86 $file = create_standard_csv(1); 87 $expected = array( 88 array('id' => 98, 'label' => 'x'), 89 array('id' => 99, 'label' => 'y'), 90 array('id' => 100, 'label' => 'z'), 91 ); 92 try_handler(20, $link, $file, 'callback_report_short_len', $expected); 93 94 mysqli_close($link); 95 print "done!"; 96?> 97--CLEAN-- 98<?php 99 require_once("clean_table.inc"); 100?> 101--EXPECTF-- 102Callback set to 'callback_report_short_len' 103Callback - report_short_len(): 0 104Callback - callback_simple(): 0 105Callback - report_short_len(): 1 106Callback - callback_simple(): 1 107done!