1--TEST-- 2mysqli_set_local_infile_default() 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 12$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); 13if (!$link) 14 die(sprintf("skip Can't connect [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); 15 16include_once("local_infile_tools.inc"); 17if ($msg = check_local_infile_support($link, $engine)) 18 die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); 19 20mysqli_close($link); 21?> 22--INI-- 23mysqli.allow_local_infile=1 24--FILE-- 25<?php 26 require_once('connect.inc'); 27 require_once('local_infile_tools.inc'); 28 29 $link = $tmp = null; 30 if (!is_null($tmp = @mysqli_set_local_infile_default())) 31 printf("[001] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); 32 33 if (!is_null($tmp = @mysqli_set_local_infile_default($link))) 34 printf("[002] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); 35 36 $link = new mysqli(); 37 if (!is_null($tmp = @mysqli_set_local_infile_default($link))) 38 printf("[002a] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); 39 40 include("table.inc"); 41 42 if (!is_null($tmp = @mysqli_set_local_infile_default($link, 'foo'))) 43 printf("[003] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); 44 45 46 function callback_simple($fp, &$buffer, $buflen, &$error) { 47 static $invocation = 0; 48 49 printf("Callback: %d\n", $invocation); 50 51 $invocation++; 52 if (!is_resource($fp)) 53 printf("[012] First argument passed to callback is not a resource but %s/%s\n", 54 $fp, gettype($fp)); 55 56 if (!$buffer = fread($fp, $buflen)) { 57 if ($invocation == 1) { 58 printf("[013] Cannot read from stream\n"); 59 $error = 'Cannot read from stream'; 60 } else { 61 return strlen($buffer); 62 } 63 } 64 65 $lines = explode("\n", $buffer); 66 if (count($lines) != 4 && strlen($buffer) > 0) { 67 printf("[014] Test is too simple to handle a buffer of size %d that cannot hold all lines\n", $buflen); 68 $error = 'Parser too simple'; 69 } 70 71 $buffer = ''; 72 foreach ($lines as $k => $line) { 73 if ('' === trim($line)) 74 continue; 75 76 $columns = explode(';', $line); 77 if (empty($columns)) { 78 printf("[015] Cannot parse columns\n"); 79 $error = 'Cannot parse columns'; 80 } 81 82 // increase id column value 83 $columns[0] += 1; 84 $buffer .= implode(';', $columns); 85 $buffer .= "\n"; 86 } 87 88 return strlen($buffer); 89 } 90 91 $file = create_standard_csv(4); 92 $expected = array( 93 array('id' => 98, 'label' => 'x'), 94 array('id' => 99, 'label' => 'y'), 95 array('id' => 100, 'label' => 'z'), 96 ); 97 try_handler(10, $link, $file, 'callback_simple', $expected); 98 99 $expected = array( 100 array('id' => 97, 'label' => 'x'), 101 array('id' => 98, 'label' => 'y'), 102 array('id' => 99, 'label' => 'z'), 103 ); 104 try_handler(20, $link, $file, 'default', $expected); 105 106 $expected = array( 107 array('id' => 98, 'label' => 'x'), 108 array('id' => 99, 'label' => 'y'), 109 array('id' => 100, 'label' => 'z'), 110 ); 111 try_handler(30, $link, $file, 'callback_simple', $expected); 112 113 mysqli_close($link); 114 115 if (!is_null($tmp = @mysqli_set_local_infile_default($link))) 116 printf("[300] Expecting NULL/NULL got %s/%s\n", $tmp, gettype($tmp)); 117 118 print "done!"; 119?> 120--CLEAN-- 121<?php 122 require_once("clean_table.inc"); 123?> 124--EXPECTF-- 125Callback set to 'callback_simple' 126Callback: 0 127Callback: 1 128Callback set to 'default' 129Callback set to 'callback_simple' 130Callback: 2 131Callback: 3 132done!