iliaa           Sun Jul 22 15:50:18 2007 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src/ext/pdo    pdo_stmt.c 
    /php-src/ext/pdo/tests      pdo_034.phpt 
  Log:
  Added test for KEY_PAIR code and fixed KEY_PAIR detection code
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo/pdo_stmt.c?r1=1.118.2.38.2.20&r2=1.118.2.38.2.21&diff_format=u
Index: php-src/ext/pdo/pdo_stmt.c
diff -u php-src/ext/pdo/pdo_stmt.c:1.118.2.38.2.20 
php-src/ext/pdo/pdo_stmt.c:1.118.2.38.2.21
--- php-src/ext/pdo/pdo_stmt.c:1.118.2.38.2.20  Sun Jul 22 15:14:21 2007
+++ php-src/ext/pdo/pdo_stmt.c  Sun Jul 22 15:50:17 2007
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pdo_stmt.c,v 1.118.2.38.2.20 2007/07/22 15:14:21 iliaa Exp $ */
+/* $Id: pdo_stmt.c,v 1.118.2.38.2.21 2007/07/22 15:50:17 iliaa Exp $ */
 
 /* The PDO Statement Handle Class */
 
@@ -1521,7 +1521,7 @@
        if (!error)     {
                PDO_STMT_CLEAR_ERR();
                MAKE_STD_ZVAL(data);
-               if (how & (PDO_FETCH_GROUP|PDO_FETCH_KEY_PAIR)) {
+               if ((how & PDO_FETCH_GROUP) || how == PDO_FETCH_KEY_PAIR) {
                        array_init(return_value);
                        return_all = return_value;
                } else {
@@ -1533,11 +1533,11 @@
                }
        }
        if (!error) {
-               if (how & PDO_FETCH_GROUP) {
+               if ((how & PDO_FETCH_GROUP)) {
                        do {
                                MAKE_STD_ZVAL(data);
                        } while (do_fetch(stmt, TRUE, data, how, 
PDO_FETCH_ORI_NEXT, 0, return_all TSRMLS_CC));
-               } else if (how & PDO_FETCH_KEY_PAIR) {
+               } else if (how == PDO_FETCH_KEY_PAIR) {
                        while (do_fetch(stmt, TRUE, data, how, 
PDO_FETCH_ORI_NEXT, 0, return_all TSRMLS_CC));
                } else {
                        array_init(return_value);
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo/tests/pdo_034.phpt?r1=1.1.2.4&r2=1.1.2.5&diff_format=u
Index: php-src/ext/pdo/tests/pdo_034.phpt
diff -u php-src/ext/pdo/tests/pdo_034.phpt:1.1.2.4 
php-src/ext/pdo/tests/pdo_034.phpt:1.1.2.5
--- php-src/ext/pdo/tests/pdo_034.phpt:1.1.2.4  Sat May 19 15:28:37 2007
+++ php-src/ext/pdo/tests/pdo_034.phpt  Sun Jul 22 15:50:17 2007
@@ -23,6 +23,7 @@
 var_dump($db->query("SELECT a,b FROM test")->fetch(PDO::FETCH_KEY_PAIR));
 var_dump($db->query("SELECT a,b FROM test")->fetchAll(PDO::FETCH_KEY_PAIR));
 var_dump($db->query("SELECT * FROM test")->fetch(PDO::FETCH_KEY_PAIR));
+var_dump($db->query("SELECT a,a FROM test")->fetchAll(PDO::FETCH_KEY_PAIR));
 
 ?>
 --EXPECTF--
@@ -31,34 +32,31 @@
   string(1) "0"
 }
 array(5) {
-  [0]=>
-  array(1) {
-    ["test0"]=>
-    string(1) "0"
-  }
-  [1]=>
-  array(1) {
-    ["test1"]=>
-    string(1) "1"
-  }
-  [2]=>
-  array(1) {
-    ["test2"]=>
-    string(1) "2"
-  }
-  [3]=>
-  array(1) {
-    ["test3"]=>
-    string(1) "3"
-  }
-  [4]=>
-  array(1) {
-    ["test4"]=>
-    string(1) "4"
-  }
+  ["test0"]=>
+  string(1) "0"
+  ["test1"]=>
+  string(1) "1"
+  ["test2"]=>
+  string(1) "2"
+  ["test3"]=>
+  string(1) "3"
+  ["test4"]=>
+  string(1) "4"
 }
 
-Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error: 
PDO::FETCH_KEY_PAIR fetch mode requires the result set to contain extactly 2 
columns. in %s/tests%spdo_034.php on line %d
+Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error: 
PDO::FETCH_KEY_PAIR fetch mode requires the result set to contain extactly 2 
columns. in %s/pdo_034.php on line %d
 
-Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General 
error%s/tests%spdo_034.php on line %d
+Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in 
%s/pdo_034.php on line %d
 bool(false)
+array(5) {
+  ["test0"]=>
+  string(5) "test0"
+  ["test1"]=>
+  string(5) "test1"
+  ["test2"]=>
+  string(5) "test2"
+  ["test3"]=>
+  string(5) "test3"
+  ["test4"]=>
+  string(5) "test4"
+}

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to