helly Sun Jul 27 12:45:10 2003 EDT
Modified files:
/php-src/ext/pgsql pgsql.c
Log:
New smart connect/shutdown for persistent connections.
Behavior for old libs/servers is "BEGIN;ROLLBACK;" in request shutdown.
For new libs a "RESET ALL;" is done in connect and "ROLLBACK;" is only done
where appropriate.
Index: php-src/ext/pgsql/pgsql.c
diff -u php-src/ext/pgsql/pgsql.c:1.284 php-src/ext/pgsql/pgsql.c:1.285
--- php-src/ext/pgsql/pgsql.c:1.284 Tue Jul 22 19:05:17 2003
+++ php-src/ext/pgsql/pgsql.c Sun Jul 27 12:45:10 2003
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql.c,v 1.284 2003/07/22 23:05:17 helly Exp $ */
+/* $Id: pgsql.c,v 1.285 2003/07/27 16:45:10 helly Exp $ */
#include <stdlib.h>
@@ -339,11 +339,20 @@
while ((res = PQgetResult(link))) {
PQclear(res);
}
- orig = PGG(ignore_notices);
- PGG(ignore_notices) = 1;
- res = PQexec(link,"BEGIN;ROLLBACK;");
- PQclear(res);
- PGG(ignore_notices) = orig;
+#if HAVE_PGTRANSACTIONSTATUS && HAVE_PQPROTOCOLVERSION
+ if (PQprotocolVersion(link) >= 3 && PQtransactionStatus(link) != PQTRANS_IDLE)
+#endif
+ {
+ orig = PGG(ignore_notices);
+ PGG(ignore_notices) = 1;
+#if HAVE_PGTRANSACTIONSTATUS && HAVE_PQPROTOCOLVERSION
+ res = PQexec(link,"ROLLBACK;");
+#else
+ res = PQexec(link,"BEGIN;ROLLBACK;");
+#endif
+ PQclear(res);
+ PGG(ignore_notices) = orig;
+ }
return 0;
}
@@ -517,6 +526,7 @@
zval **args[5];
int i, connect_type = 0;
char *msgbuf;
+ PGresult *pg_result;
if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 5
|| zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) ==
FAILURE) {
@@ -625,12 +635,15 @@
goto err;
}
}
+ pgsql = (PGconn *) le->ptr;
+#if HAVE_PQPROTOCOLVERSION && HAVE_PQPARAMETERSTATUS
+ if (PQprotocolVersion(pgsql) >= 3 &&
atof(PQparameterStatus(pgsql, "server_version")) >= 7.2) {
+#else
if (atof(PG_VERSION) >= 7.2) {
- PGresult *pg_result;
- pg_result = PQexec(le->ptr, "BEGIN;COMMIT;RESET ALL;");
+#endif
+ pg_result = PQexec(pgsql, "RESET ALL;");
PQclear(pg_result);
}
- pgsql = (PGconn *) le->ptr;
}
ZEND_REGISTER_RESOURCE(return_value, pgsql, le_plink);
} else { /* Non persistent connection */
@@ -840,7 +853,7 @@
add_assoc_long(return_value, "protocol",
PQprotocolVersion(pgsql));
#if HAVE_PQPARAMETERSTATUS
if (PQprotocolVersion(pgsql) >= 3) {
- add_assoc_string(return_value, "server",
PQparameterStatus(pgsql, "server_version"), 1);
+ add_assoc_string(return_value, "server",
(char*)PQparameterStatus(pgsql, "server_version"), 1);
}
#endif
#endif
@@ -915,19 +928,24 @@
}
/* }}} */
-/* {{{ proto bool pg_ping(resource connection)
+/* {{{ proto bool pg_ping([resource connection])
Ping database. If connection is bad, try to reconnect. */
PHP_FUNCTION(pg_ping)
{
- zval *pgsql_link = NULL;
- int id = -1;
+ zval *pgsql_link;
+ int id;
PGconn *pgsql;
PGresult *res;
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS()
TSRMLS_CC, "r",
- &pgsql_link) ==
FAILURE) {
- RETURN_FALSE;
+ if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS()
TSRMLS_CC, "r", &pgsql_link) == SUCCESS) {
+ id = -1;
+ } else {
+ pgsql_link = NULL;
+ id = PGG(default_link);
}
+ if (pgsql_link == NULL && id == -1) {
+ RETURN_FALSE;
+ }
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link",
le_link, le_plink);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php