cvs: php-src(PHP_5_1) /ext/pdo_pgsql pgsql_statement.c php_pdo_pgsql_int.h

From: Date: Sat, 17 Dec 2005 17:59:06 +0000
Subject: cvs: php-src(PHP_5_1) /ext/pdo_pgsql pgsql_statement.c php_pdo_pgsql_int.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-35995@lists.php.net to get a copy of this message
iliaa Sat Dec 17 17:59:06 2005 EDT Modified files: (Branch: PHP_5_1) /php-src/ext/pdo_pgsql pgsql_statement.c php_pdo_pgsql_int.h Log: Retry on failed prepare resulting from duplicate statement name. http://cvs.php.net/viewcvs.cgi/php-src/ext/pdo_pgsql/pgsql_statement.c?r1=1.31.2.7&r2=1.31.2.8&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.7 php-src/ext/pdo_pgsql/pgsql_statement.c:1.31.2.8 --- php-src/ext/pdo_pgsql/pgsql_statement.c:1.31.2.7 Thu Dec 1 16:33:01 2005 +++ php-src/ext/pdo_pgsql/pgsql_statement.c Sat Dec 17 17:59:05 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql_statement.c,v 1.31.2.7 2005/12/01 16:33:01 iliaa Exp $ */ +/* $Id: pgsql_statement.c,v 1.31.2.8 2005/12/17 17:59:05 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -126,7 +126,8 @@ if (S->stmt_name) { /* using a prepared statement */ - if (!stmt->executed) { + if (!S->is_prepared) { +stmt_retry: /* we deferred the prepare until now, because we didn't * know anything about the parameter types; now we do */ S->result = PQprepare(H->server, S->stmt_name, S->query, @@ -137,12 +138,31 @@ case PGRES_COMMAND_OK: case PGRES_TUPLES_OK: /* it worked */ + S->is_prepared = 1; PQclear(S->result); break; - default: - pdo_pgsql_error_stmt(stmt, status, - pdo_pgsql_sqlstate(S->result)); - return 0; + default: { + char *sqlstate = pdo_pgsql_sqlstate(S->result); + /* 42P05 means that the prepared statement already existed. this can happen if you use + * a connection pooling software line pgpool which doesn't close the db-connection once + * php disconnects. if php dies (no chanche to run RSHUTDOWN) during execution it has no + * chance to DEALLOCATE the prepared statements it has created. so, if we hit a 42P05 we + * deallocate it and retry ONCE (thies 2005.12.15) + */ + if (!strcmp(sqlstate, "42P05")) { + char buf[100]; /* stmt_name == "pdo_pgsql_cursor_%08x" */ + PGresult *res; + snprintf(buf, sizeof(buf), "DEALLOCATE %s", S->stmt_name); + res = PQexec(H->server, buf); + if (res) { + PQclear(res); + } + goto stmt_retry; + } else { + pdo_pgsql_error_stmt(stmt, status, sqlstate); + return 0; + } + } } } S->result = PQexecPrepared(H->server, S->stmt_name, http://cvs.php.net/viewcvs.cgi/php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h?r1=1.13.2.2&r2=1.13.2.3&diff_format=u Index: php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h diff -u php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h:1.13.2.2 php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h:1.13.2.3 --- php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h:1.13.2.2 Tue Nov 29 02:11:38 2005 +++ php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h Sat Dec 17 17:59:05 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_pdo_pgsql_int.h,v 1.13.2.2 2005/11/29 02:11:38 wez Exp $ */ +/* $Id: php_pdo_pgsql_int.h,v 1.13.2.3 2005/12/17 17:59:05 iliaa Exp $ */ #ifndef PHP_PDO_PGSQL_INT_H #define PHP_PDO_PGSQL_INT_H @@ -65,6 +65,7 @@ int *param_lengths; int *param_formats; Oid *param_types; + zend_bool is_prepared; #endif } pdo_pgsql_stmt;

« previous php.cvs (#35995) next »