]> granicus.if.org Git - php/commitdiff
- Fix fetching bound vars & tests
authorMarcus Boerger <helly@php.net>
Thu, 10 Mar 2005 18:48:01 +0000 (18:48 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 10 Mar 2005 18:48:01 +0000 (18:48 +0000)
ext/pdo_pgsql/pgsql_statement.c
ext/pdo_pgsql/tests/pdo_016.phpt
ext/pdo_pgsql/tests/pdo_018.phpt

index 1a6377660cd6394105f66de983ac7f80fa653c7a..f1d1c304fa65a14384e1dd2199ceb1ae25eef6aa 100644 (file)
@@ -72,7 +72,6 @@ static int pgsql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC)
 
 static int pgsql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
 {
-       pdo_dbh_t *dbh = stmt->dbh;
        pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
        pdo_pgsql_db_handle *H = S->H;
        ExecStatusType status;
@@ -84,6 +83,8 @@ static int pgsql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
                        S->result = NULL;
                }
        }
+       
+       S->current_row = 0;
 
        if (S->cursor_name) {
                char *q = NULL;
@@ -127,7 +128,7 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt,
        pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
 
        if (S->cursor_name) {
-               char *ori_str = NULL;
+               char *ori_str;
                char *q = NULL;
                ExecStatusType status;
 
@@ -135,12 +136,11 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt,
                        case PDO_FETCH_ORI_NEXT:        ori_str = "NEXT"; break;
                        case PDO_FETCH_ORI_PRIOR:       ori_str = "PRIOR"; break;
                        case PDO_FETCH_ORI_REL:         ori_str = "RELATIVE"; break;
-               }
-               if (!ori_str) {
-                       return 0;
+                       default:
+                               return 0;
                }
                
-               spprintf(&q, 0, "FETCH %s %d FROM %s", ori_str, offset, S->cursor_name);
+               spprintf(&q, 0, "FETCH %s %ld FROM %s", ori_str, offset, S->cursor_name);
                S->result = PQexec(S->H->server, q);
                status = PQresultStatus(S->result);
 
index 9c41aebaea6698e729f2dd91802d4fc2bbbd807e..f09290ba9b1929f4499a6ffee5841983a1e0cf08 100755 (executable)
@@ -89,7 +89,7 @@ bool(true)
 string(7) "String0"
 bool(true)
 bool(true)
-string(1) "0"
+int(0)
 array(1) {
   [1]=>
   string(7) "String1"
@@ -99,7 +99,7 @@ bool(true)
 string(7) "String1"
 bool(true)
 bool(true)
-string(1) "1"
+int(1)
 array(1) {
   [2]=>
   string(7) "String2"
@@ -109,7 +109,7 @@ bool(true)
 string(7) "String2"
 bool(true)
 bool(true)
-string(1) "2"
+int(2)
 ===REBIND/CONFLICT===
 string(7) "String0"
 string(7) "String1"
index 250bdaa4d2cdddd5d182d6c0ca76ec6c617c72f6..6eaa66c78889a1cbcb7471941a4acb374dfbd1a2 100755 (executable)
@@ -10,6 +10,22 @@ require_once('skipif.inc');
 require_once('connection.inc');
 require_once('prepare.inc');
 
+require_once($PDO_TESTS . 'pdo.inc');
+
+set_sql('create1', 'CREATE TABLE classtypes(id int PRIMARY KEY, name VARCHAR(20) UNIQUE)');
+set_sql('insert1', 'INSERT INTO classtypes VALUES(0, \'stdClass\')'); 
+set_sql('insert2', 'INSERT INTO classtypes VALUES(1, \'TestBase\')'); 
+set_sql('insert3', 'INSERT INTO classtypes VALUES(2, \'TestDerived\')'); 
+set_sql('selectC', 'SELECT COUNT(*) FROM classtypes'); 
+set_sql('select0', 'SELECT id, name FROM classtypes ORDER by id'); 
+set_sql('create2', 'CREATE TABLE test(id int PRIMARY KEY, classtype int, val VARCHAR(255))');
+set_sql('insert4', 'INSERT INTO test VALUES(:id, :classtype, :val)');
+set_sql('select1', 'SELECT id FROM classtypes WHERE name=:cname');
+set_sql('select2', 'SELECT test.val FROM test');
+set_sql('select3', 'SELECT classtypes.name AS name, test.val AS val FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id');
+set_sql('select4', 'SELECT COUNT(*) FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id WHERE (classtypes.id IS NULL OR classtypes.id > 0)');
+set_sql('select5', 'SELECT classtypes.name AS name, test.val AS val FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id WHERE (classtypes.id IS NULL OR classtypes.id > 0)');
+
 require_once($PDO_TESTS . 'pdo_018.inc');
 
 ?>
@@ -60,7 +76,7 @@ array(4) {
 ===FAILURE===
 Exception:SQLSTATE[HY000]: General error: cannot unserialize class
 ===COUNT===
-int(3)
+string(1) "3"
 ===DATABASE===
 array(3) {
   [0]=>