]> granicus.if.org Git - php/commitdiff
1) Whitespace/CS
authorUlf Wendel <uw@php.net>
Thu, 12 Jul 2007 13:50:51 +0000 (13:50 +0000)
committerUlf Wendel <uw@php.net>
Thu, 12 Jul 2007 13:50:51 +0000 (13:50 +0000)
2) Fixing [U]EXPECTF to be portable among different MySQL Server versions

ext/mysql/tests/mysql_unbuffered_query.phpt

index 37e0919701c0fa9f7ac7eb5ccc005228fef3946d..a19ba457060e30d855bdc0b86e36bfcb982859d5 100644 (file)
@@ -2,85 +2,92 @@
 mysql_unbuffered_query()
 --SKIPIF--
 <?php require_once('skipif.inc'); ?>
-<?php require_once('skipifemb.inc'); ?>
 --FILE--
 <?php
-    include "connect.inc";
-    
-    $tmp    = NULL;   
-    $link   = NULL;    
-    
-    if (false !== ($tmp = @mysql_unbuffered_query($link)))
-        printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
-        
-    require('table.inc');
-    
-    if (NULL !== ($tmp = @mysql_unbuffered_query("SELECT 1 AS a", $link, "foo")))
-        printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
-    
-    if (false !== ($tmp = mysql_unbuffered_query('THIS IS NOT SQL', $link)))
-        printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
-        
-    if (false !== ($tmp = mysql_unbuffered_query('SELECT "this is sql but with backslash g"\g', $link)))
-        printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);        
-        
-    if ((0 === mysql_errno($link)) || ('' == mysql_error($link)))
-        printf("[005] mysql_errno()/mysql_error should return some error\n");
-        
-    if (!$res = mysql_unbuffered_query('SELECT "this is sql but with semicolon" AS valid ; ', $link))
-        printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
-    
-    var_dump(mysql_fetch_assoc($res));    
-    mysql_free_result($res);
-        
-    if (false !== ($res = mysql_unbuffered_query('SELECT "this is sql but with semicolon" AS valid ; SHOW VARIABLES', $link)))
-        printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
-        
-    if (mysql_unbuffered_query('DROP PROCEDURE IF EXISTS p', $link)) {
-        // let's try to play with stored procedures        
-        if (mysql_unbuffered_query('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;', $link)) {
-            $res = mysql_unbuffered_query('CALL p(@version)', $link);    
-            $res = mysql_unbuffered_query('SELECT @version AS p_version', $link);
-            var_dump(mysql_fetch_assoc($res));            
-            mysql_free_result($res);
-        } else {
-            printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
-        }
-        
-        mysql_unbuffered_query('DROP FUNCTION IF EXISTS f', $link);
-        if (mysql_unbuffered_query('CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN ver_param;', $link)) {
-            $res = mysql_unbuffered_query('SELECT f(VERSION()) AS f_version', $link);
-            var_dump(mysql_fetch_assoc($res));
-            mysql_free_result($res);
-        } else {
-            printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link));
-        }
-    }
-    
-    var_dump(mysql_unbuffered_query('INSERT INTO test(id) VALUES (100)', $link));
-    var_dump($res = mysql_unbuffered_query('SELECT id FROM test', $link));
-    var_dump(mysql_num_rows($res));   
-    
-    mysql_close($link);
-    
-    if (false !== ($tmp = mysql_unbuffered_query("SELECT id FROM test", $link)))
-        printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
-    
-    print "done!";
+include_once("connect.inc");
+
+$tmp    = NULL;
+$link   = NULL;
+
+if (false !== ($tmp = @mysql_unbuffered_query($link)))
+       printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+require('table.inc');
+
+if (NULL !== ($tmp = @mysql_unbuffered_query("SELECT 1 AS a", $link, "foo")))
+       printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+if (false !== ($tmp = mysql_unbuffered_query('THIS IS NOT SQL', $link)))
+       printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+if (false !== ($tmp = mysql_unbuffered_query('SELECT "this is sql but with backslash g"\g', $link)))
+       printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+if ((0 === mysql_errno($link)) || ('' == mysql_error($link)))
+       printf("[005] mysql_errno()/mysql_error should return some error\n");
+
+if (!$res = mysql_unbuffered_query('SELECT "this is sql but with semicolon" AS valid ; ', $link))
+       printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+var_dump(mysql_fetch_assoc($res));
+mysql_free_result($res);
+
+if (false !== ($res = mysql_unbuffered_query('SELECT "this is sql but with semicolon" AS valid ; SHOW VARIABLES', $link)))
+       printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+if (mysql_unbuffered_query('DROP PROCEDURE IF EXISTS p', $link)) {
+       // let's try to play with stored procedures
+       if (mysql_unbuffered_query('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;', $link)) {
+               $res = mysql_unbuffered_query('CALL p(@version)', $link);
+               $res = mysql_unbuffered_query('SELECT @version AS p_version', $link);
+               $tmp = mysql_fetch_assoc($res);
+               if (!isset($tmp['p_version']) || ('' == $tmp['p_version'])) {
+                       printf("[008] Result seems wrong, dumping\n");
+                       var_dump($tmp);
+               }
+               if (ini_get('unicode.semantics') && !is_unicode($tmp['p_version'])) {
+                       printf("[009] Expecting unicode string, dumping\n");
+                       var_dump($tmp);
+               }
+               mysql_free_result($res);
+       } else {
+               printf("[010] [%d] %s\n", mysql_errno($link), mysql_error($link));
+       }
+
+       mysql_unbuffered_query('DROP FUNCTION IF EXISTS f', $link);
+       if (mysql_unbuffered_query('CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN ver_param;', $link)) {
+               $res = mysql_unbuffered_query('SELECT f(VERSION()) AS f_version', $link);
+               $tmp = mysql_fetch_assoc($res);
+               if (!isset($tmp['f_version']) || ('' == $tmp['f_version'])) {
+                       printf("[011] Result seems wrong, dumping\n");
+                       var_dump($tmp);
+               }
+               if (ini_get('unicode.semantics') && !is_unicode($tmp['f_version'])) {
+                       printf("[012] Expecting unicode string, dumping\n");
+                       var_dump($tmp);
+               }
+               mysql_free_result($res);
+       } else {
+               printf("[012] [%d] %s\n", mysql_errno($link), mysql_error($link));
+       }
+}
+
+var_dump(mysql_unbuffered_query('INSERT INTO test(id) VALUES (100)', $link));
+var_dump($res = mysql_unbuffered_query('SELECT id FROM test', $link));
+var_dump(mysql_num_rows($res));
+
+mysql_close($link);
+
+if (false !== ($tmp = mysql_unbuffered_query("SELECT id FROM test", $link)))
+       printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+print "done!";
 ?>
 --EXPECTF--
 array(1) {
   ["valid"]=>
   string(30) "this is sql but with semicolon"
 }
-array(1) {
-  ["p_version"]=>
-  string(16) "5.0.26-debug-log"
-}
-array(1) {
-  ["f_version"]=>
-  string(16) "5.0.26-debug-log"
-}
 bool(true)
 resource(%d) of type (mysql result)
 int(0)
@@ -94,14 +101,6 @@ array(1) {
   [u"valid"]=>
   unicode(30) "this is sql but with semicolon"
 }
-array(1) {
-  [u"p_version"]=>
-  unicode(16) "5.0.26-debug-log"
-}
-array(1) {
-  [u"f_version"]=>
-  unicode(16) "5.0.26-debug-log"
-}
 bool(true)
 resource(%d) of type (mysql result)
 int(0)