List:Commits« Previous MessageNext Message »
From:uwendel Date:June 22 2007 12:35pm
Subject:PHP mysqlnd svn commit: r450 - trunk/tests/ext/mysqli
View as plain text  
Author: uwendel
Date: 2007-06-22 14:35:12 +0200 (Fri, 22 Jun 2007)
New Revision: 450

Added:
   trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nested_call.phpt
Log:
Failure.

Callback set to 'callback_report_short_len'
Callback: 0
Callback: 0
Callback: 0
Callback: 1
[022] LOAD DATA failed, [2]
[023] [2006] MySQL server has gone away



Added: trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nested_call.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nested_call.phpt	2007-06-22
12:19:38 UTC (rev 449)
+++ trunk/tests/ext/mysqli/mysqli_set_local_infile_handler_nested_call.phpt	2007-06-22
12:35:12 UTC (rev 450)
@@ -0,0 +1,163 @@
+--TEST--
+mysqli_set_local_infile_handler() - nested calls
+--SKIPIF--
+<?php 
+require_once('skipif.inc');
+require_once('skipifemb.inc'); 
+if (!function_exists('mysqli_set_local_infile_handler'))
+    die("skip - function not available.");
+?>
+--FILE--
+<?php
+    include "connect.inc";
+    include("table.inc");   
+    
+        
+    function callback_simple($fp, &$buffer, $buflen, &$error) {
+        static $invocation = 0;
+        
+        printf("Callback: %d\n", $invocation);
+        
+        $invocation++;
+        if (!is_resource($fp))
+            printf("[012] First argument passed to callback is not a resource but
%s/%s\n",
+                $fp, gettype($fp));
+                
+        if (!$buffer = fread($fp, $buflen)) {
+            if ($invocation == 1) {
+                printf("[013] Cannot read from stream\n");
+                $error = 'Cannot read from stream';
+            } else {
+                return strlen($buffer);
+            }
+        }        
+        
+        $lines = explode("\n", $buffer);        
+        if (count($lines) != 4 && strlen($buffer) > 0) {
+            printf("[014] Test is too simple to handle a buffer of size %d that cannot
hold all lines\n", $buflen);
+            $error = 'Parser too simple';
+        }            
+        
+        $buffer = '';
+        foreach ($lines as $k => $line) {
+            if ('' === trim($line))
+                continue;
+                
+            $columns = explode(';', $line);
+            if (empty($columns)) {
+                printf("[015] Cannot parse columns\n");
+                $error = 'Cannot parse columns';
+            }
+            
+            // increase id column value
+            $columns[0] += 1;
+            $buffer .= implode(';', $columns);
+            $buffer .= "\n";
+        }
+        
+        /* report the wrong length */
+        return strlen($buffer) - 1;
+    }
+    
+    function callback_report_short_len($fp, &$buffer, $buflen, &$error) {
+        static $invocation = 0;
+        
+        printf("Callback: %d\n", $invocation);
+        return callback_simple($fp, $buffer, $buflen, $error) -1;
+    }
+    
+    function try_handler($offset, $link, $file, $handler, $expected) {
+        
+        if (!mysqli_set_local_infile_handler($link, $handler)) {
+            printf("[%03d] Cannot set infile handler to '%s'\n", $offset, $handler);
+            return false;
+        }
+        printf("Callback set to '%s'\n", $handler);
+        
+        if (!mysqli_query($link, sprintf("DELETE FROM test"))) {
+            printf("[%03d] Cannot remove records, [%d] %s\n", $offset + 1,
mysqli_errno($link), mysqli_error($link));
+            return false;
+        }
+        
+        
+        if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' 
+                                        INTO TABLE test
+                                        FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY
'\''
+                                        LINES TERMINATED BY '\n'",
+            mysqli_real_escape_string($link, $file)))) {
+            printf("[%03d] LOAD DATA failed, [%d] %s\n", 
+                    $offset + 2,
+                    mysqli_errno($link), mysqli_error($link));
+        }
+        
+        if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id")) {
+            printf("[%03d] [%d] %s\n", $offset + 3, mysqli_errno($link),
mysqli_error($link));
+            return false;
+        }
+
+        foreach ($expected as $k => $values) {
+            if (!$tmp = mysqli_fetch_assoc($res)) {
+                printf("[%03d/%d] [%d] %s\n", $offset + 4, $k, mysqli_errno($link),
mysqli_error($link));
+                return false;
+            }
+            if ($values['id'] != $tmp['id']) {
+                printf("[%03d/%d] Expecting %s got %s\n", 
+                    $offset + 5, $k, 
+                    $values['id'], $tmp['id']);
+                return false;
+            }
+            if ($values['label'] != $tmp['label']) {
+                printf("[%03d/%d] Expecting %s got %s\n", 
+                    $offset + 6, $k,
+                    $values['label'], $tmp['label']);
+                return false;
+            }
+        }
+        
+        if ($res && $tmp = mysqli_fetch_assoc($res)) {
+            printf("[%03d] More results than expected! Dumping data \n", $offset + 7);
+            do {
+                var_dump($tmp);
+            } while ($tmp = mysqli_fetch_assoc($res));
+        }
+        
+        if ($res)
+            mysqli_free_result($res);
+        
+        return true;
+    }    
+    
+    // create a CVS file
+    $file = tempnam(sys_get_temp_dir(), 'mysqli_test');
+    if (!$fp = fopen($file, 'w'))
+        printf("[005] Cannot create CVS file '%s'\n", $file);
+
+    if (!fwrite($fp, "97;'x';\n") ||
+        !fwrite($fp, "98;'y';\n") ||
+        !fwrite($fp, "99;'z';\n"))
+        printf("[006] Cannot write CVS file '%s'\n", $file);
+        
+    fclose($fp);    
+    
+    if (!chmod($file, 0644))
+        printf("[007] Cannot change the file perms of '%s' from 0600 to 0644, MySQL might
not be able to read it\n",
+            $file);
+
+    
+        $expected = array(
+                    array('id' => 98,   'label' => 'x'),
+                    array('id' => 99,   'label' => 'y'),
+                    array('id' => 100,  'label' => 'z'),
+                );
+    try_handler(20, $link, $file, 'callback_report_short_len', $expected);    
+    
+    mysqli_close($link);    
+    print "done!";
+?>
+--EXPECTF--
+Callback set to 'callback_report_short_len'
+Callback: 0
+Callback: 0
+Callback: 1
+Callback: 1
+done!
\ No newline at end of file

Thread
PHP mysqlnd svn commit: r450 - trunk/tests/ext/mysqliuwendel22 Jun