From cdb042f63272f817ecf372039d64469a99483d7a Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Thu, 10 Mar 2005 18:48:01 +0000 Subject: [PATCH] - Fix fetching bound vars & tests --- ext/pdo_pgsql/pgsql_statement.c | 12 ++++++------ ext/pdo_pgsql/tests/pdo_016.phpt | 6 +++--- ext/pdo_pgsql/tests/pdo_018.phpt | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 1a6377660c..f1d1c304fa 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -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); diff --git a/ext/pdo_pgsql/tests/pdo_016.phpt b/ext/pdo_pgsql/tests/pdo_016.phpt index 9c41aebaea..f09290ba9b 100755 --- a/ext/pdo_pgsql/tests/pdo_016.phpt +++ b/ext/pdo_pgsql/tests/pdo_016.phpt @@ -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" diff --git a/ext/pdo_pgsql/tests/pdo_018.phpt b/ext/pdo_pgsql/tests/pdo_018.phpt index 250bdaa4d2..6eaa66c788 100755 --- a/ext/pdo_pgsql/tests/pdo_018.phpt +++ b/ext/pdo_pgsql/tests/pdo_018.phpt @@ -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]=> -- 2.40.0