cvs: php4 /ext/pgsql pgsql.c

From: Date: Thu, 24 Jan 2002 09:27:43 +0000
Subject: cvs: php4 /ext/pgsql pgsql.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-9147@lists.php.net to get a copy of this message
yohgaki Thu Jan 24 04:27:43 2002 EDT Modified files: /php4/ext/pgsql pgsql.c Log: Revert last 2 commit. Instead, make php_pgsql_do_connect() to catch broken connection always. # I think this is better than check&reset connection when query # functions are called. Index: php4/ext/pgsql/pgsql.c diff -u php4/ext/pgsql/pgsql.c:1.144 php4/ext/pgsql/pgsql.c:1.145 --- php4/ext/pgsql/pgsql.c:1.144 Thu Jan 24 01:40:10 2002 +++ php4/ext/pgsql/pgsql.c Thu Jan 24 04:27:43 2002 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql.c,v 1.144 2002/01/24 06:40:10 yohgaki Exp $ */ +/* $Id: pgsql.c,v 1.145 2002/01/24 09:27:43 yohgaki Exp $ */ #include <stdlib.h> @@ -535,15 +535,29 @@ PGG(num_links)++; PGG(num_persistent)++; } else { /* we do */ + php_log_err("CONNECTION IS ALREADY OPENED :)" TSRMLS_CC); if (Z_TYPE_P(le) != le_plink) { RETURN_FALSE; } /* ensure that the link did not die */ + { + /* need to send & get something from backend to + make sure we catch CONNECTION_BAD everytime */ + PGresult *pg_result; + pg_result = PQexec(le->ptr, "select 1"); + PQclear(pg_result); + } + PQconsumeInput(le->ptr); if (PQstatus(le->ptr)==CONNECTION_BAD) { /* the link died */ - if (connstring) { - le->ptr=PQconnectdb(connstring); - } else { - le->ptr=PQsetdb(host,port,options,tty,dbname); + if (le->ptr == NULL) { + if (connstring) { + le->ptr=PQconnectdb(connstring); + } else { + le->ptr=PQsetdb(host,port,options,tty,dbname); + } + } + else { + PQreset(le->ptr); } if (le->ptr==NULL || PQstatus(le->ptr)==CONNECTION_BAD) { php_error(E_WARNING,"PostgreSQL link lost, unable to reconnect"); @@ -721,9 +735,6 @@ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); - if (PQstatus(pgsql) != CONNECTION_OK) { - PQreset(pgsql); - } switch(entry_type) { case PHP_PG_DBNAME: Z_STRVAL_P(return_value) = PQdb(pgsql); @@ -832,9 +843,6 @@ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); - if (PQstatus(pgsql) != CONNECTION_OK) { - PQreset(pgsql); - } convert_to_string_ex(query); PQsetnonblocking(pgsql, 0); while ((pgsql_result = PQgetResult(pgsql))) { @@ -2516,9 +2524,6 @@ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); - if (PQstatus(pgsql) != CONNECTION_OK) { - PQreset(pgsql); - } if (PQsetnonblocking(pgsql, 1)) { php_error(E_NOTICE,"%s() cannot set connection to nonblocking mode", get_active_function_name(TSRMLS_C));

« previous php.cvs (#9147) next »