mbeccati Sat Mar 28 02:58:05 2009 UTC
Added files: (Branch: PHP_5_3)
/php-src/ext/pdo_pgsql/tests bug44861.phpt
Modified files:
/php-src NEWS
/php-src/ext/pdo_pgsql pgsql_driver.c pgsql_statement.c
Log:
- Fixed bug #44861 (scrollable cursor don't work with pgsql)
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.541&r2=1.2027.2.547.2.965.2.542&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.541
php-src/NEWS:1.2027.2.547.2.965.2.542
--- php-src/NEWS:1.2027.2.547.2.965.2.541 Sat Mar 28 01:29:14 2009
+++ php-src/NEWS Sat Mar 28 02:58:04 2009
@@ -3,6 +3,7 @@
?? ??? 200?, PHP 5.3.0 RC 2
- Undeprecated ticks. (Arnaud)
+- Fixed bug #44861 (scrollable cursor don't work with pgsql). (Matteo)
- Fixed bug #47779 (Wrong value for SIG_UNBLOCK and SIG_SETMASK constants).
(Matteo)
- Fixed bug #47771 (Exception during object construction from arg call calls
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_pgsql/pgsql_driver.c?r1=1.53.2.14.2.9.2.4&r2=1.53.2.14.2.9.2.5&diff_format=u
Index: php-src/ext/pdo_pgsql/pgsql_driver.c
diff -u php-src/ext/pdo_pgsql/pgsql_driver.c:1.53.2.14.2.9.2.4
php-src/ext/pdo_pgsql/pgsql_driver.c:1.53.2.14.2.9.2.5
--- php-src/ext/pdo_pgsql/pgsql_driver.c:1.53.2.14.2.9.2.4 Wed Dec 31
11:15:41 2008
+++ php-src/ext/pdo_pgsql/pgsql_driver.c Sat Mar 28 02:58:04 2009
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql_driver.c,v 1.53.2.14.2.9.2.4 2008/12/31 11:15:41 sebastian Exp $
*/
+/* $Id: pgsql_driver.c,v 1.53.2.14.2.9.2.5 2009/03/28 02:58:04 mbeccati Exp $
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -232,13 +232,13 @@
if (S->cursor_name) {
efree(S->cursor_name);
}
- /* TODO: check how scrollable cursors related to prepared
statements */
spprintf(&S->cursor_name, 0, "pdo_pgsql_cursor_%08x", (unsigned
int) stmt);
+ emulate = 1;
}
#if HAVE_PQPREPARE
- if (driver_options) {
+ else if (driver_options) {
if (pdo_attr_lval(driver_options,
PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT, 0 TSRMLS_CC) == 1) {
emulate = 1;
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_pgsql/pgsql_statement.c?r1=1.31.2.12.2.7.2.8&r2=1.31.2.12.2.7.2.9&diff_format=u
Index: php-src/ext/pdo_pgsql/pgsql_statement.c
diff -u php-src/ext/pdo_pgsql/pgsql_statement.c:1.31.2.12.2.7.2.8
php-src/ext/pdo_pgsql/pgsql_statement.c:1.31.2.12.2.7.2.9
--- php-src/ext/pdo_pgsql/pgsql_statement.c:1.31.2.12.2.7.2.8 Wed Dec 31
11:15:41 2008
+++ php-src/ext/pdo_pgsql/pgsql_statement.c Sat Mar 28 02:58:04 2009
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql_statement.c,v 1.31.2.12.2.7.2.8 2008/12/31 11:15:41 sebastian
Exp $ */
+/* $Id: pgsql_statement.c,v 1.31.2.12.2.7.2.9 2009/03/28 02:58:04 mbeccati Exp
$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -129,6 +129,24 @@
S->current_row = 0;
+ if (S->cursor_name) {
+ char *q = NULL;
+ spprintf(&q, 0, "DECLARE %s SCROLL CURSOR WITH HOLD FOR %s",
S->cursor_name, stmt->active_query_string);
+ S->result = PQexec(H->server, q);
+ efree(q);
+
+ /* check if declare failed */
+ status = PQresultStatus(S->result);
+ if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
+ pdo_pgsql_error_stmt(stmt, status,
pdo_pgsql_sqlstate(S->result));
+ return 0;
+ }
+
+ /* fetch to be able to get the number of tuples later, but
don't advance the cursor pointer */
+ spprintf(&q, 0, "FETCH FORWARD 0 FROM %s", S->cursor_name);
+ S->result = PQexec(H->server, q);
+ efree(q);
+ } else
#if HAVE_PQPREPARE
if (S->stmt_name) {
/* using a prepared statement */
@@ -182,12 +200,7 @@
0);
} else
#endif
- if (S->cursor_name) {
- char *q = NULL;
- spprintf(&q, 0, "DECLARE %s CURSOR FOR %s", S->cursor_name,
stmt->active_query_string);
- S->result = PQexec(H->server, q);
- efree(q);
- } else {
+ {
S->result = PQexec(H->server, stmt->active_query_string);
}
status = PQresultStatus(S->result);
@@ -350,19 +363,23 @@
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
if (S->cursor_name) {
- char *ori_str;
+ char *ori_str = NULL;
char *q = NULL;
ExecStatusType status;
switch (ori) {
- case PDO_FETCH_ORI_NEXT: ori_str = "FORWARD";
break;
- case PDO_FETCH_ORI_PRIOR: ori_str = "BACKWARD";
break;
- case PDO_FETCH_ORI_REL: ori_str = "RELATIVE";
break;
+ case PDO_FETCH_ORI_NEXT: spprintf(&ori_str, 0,
"NEXT"); break;
+ case PDO_FETCH_ORI_PRIOR: spprintf(&ori_str, 0,
"BACKWARD"); break;
+ case PDO_FETCH_ORI_FIRST: spprintf(&ori_str, 0,
"FIRST"); break;
+ case PDO_FETCH_ORI_LAST: spprintf(&ori_str, 0,
"LAST"); break;
+ case PDO_FETCH_ORI_ABS: spprintf(&ori_str, 0,
"ABSOLUTE %ld", offset); break;
+ case PDO_FETCH_ORI_REL: spprintf(&ori_str, 0,
"RELATIVE %ld", offset); break;
default:
return 0;
}
- spprintf(&q, 0, "FETCH %s %ld FROM %s", ori_str, offset,
S->cursor_name);
+ spprintf(&q, 0, "FETCH %s FROM %s", ori_str, S->cursor_name);
+ efree(ori_str);
S->result = PQexec(S->H->server, q);
efree(q);
status = PQresultStatus(S->result);
@@ -372,9 +389,12 @@
return 0;
}
- S->current_row = 1;
- return 1;
-
+ if (PQntuples(S->result)) {
+ S->current_row = 1;
+ return 1;
+ } else {
+ return 0;
+ }
} else {
if (S->current_row < stmt->row_count) {
S->current_row++;
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_pgsql/tests/bug44861.phpt?view=markup&rev=1.1
Index: php-src/ext/pdo_pgsql/tests/bug44861.phpt
+++ php-src/ext/pdo_pgsql/tests/bug44861.phpt
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php