cvs: php-src /ext/pdo_pgsql pdo_pgsql.c pgsql_driver.c php_pdo_pgsql_int.h

From: Date: Wed, 20 Jul 2005 02:37:58 +0000
Subject: cvs: php-src /ext/pdo_pgsql pdo_pgsql.c pgsql_driver.c php_pdo_pgsql_int.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-33005@lists.php.net to get a copy of this message
wez Tue Jul 19 22:37:58 2005 EDT Modified files: /php-src/ext/pdo_pgsql pdo_pgsql.c pgsql_driver.c php_pdo_pgsql_int.h Log: Add PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT attribute, which, when set to true, forces the driver to use PDO's own emulated prepared statement support. Why would you want that, considering that native prepared statements are supposed to be the best thing ever? "Often postgresql will have to plan the query without knowing the parameters - and it will choose a bad plan. In some cases it will plan based on the first parameters you send. " Ugh. So now we have a way to let you decide that you know better than the pgsql query planner. http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pdo_pgsql.c?r1=1.4&r2=1.5&ty=u Index: php-src/ext/pdo_pgsql/pdo_pgsql.c diff -u php-src/ext/pdo_pgsql/pdo_pgsql.c:1.4 php-src/ext/pdo_pgsql/pdo_pgsql.c:1.5 --- php-src/ext/pdo_pgsql/pdo_pgsql.c:1.4 Wed Jun 22 20:19:15 2005 +++ php-src/ext/pdo_pgsql/pdo_pgsql.c Tue Jul 19 22:37:57 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pdo_pgsql.c,v 1.4 2005/06/23 00:19:15 helly Exp $ */ +/* $Id: pdo_pgsql.c,v 1.5 2005/07/20 02:37:57 wez Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -77,6 +77,7 @@ PHP_MINIT_FUNCTION(pdo_pgsql) { php_pdo_register_driver(&pdo_pgsql_driver); + REGISTER_LONG_CONSTANT("PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT", PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT, CONST_CS|CONST_PERSISTENT); return SUCCESS; } /* }}} */ http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pgsql_driver.c?r1=1.51&r2=1.52&ty=u Index: php-src/ext/pdo_pgsql/pgsql_driver.c diff -u php-src/ext/pdo_pgsql/pgsql_driver.c:1.51 php-src/ext/pdo_pgsql/pgsql_driver.c:1.52 --- php-src/ext/pdo_pgsql/pgsql_driver.c:1.51 Sat Jul 9 00:54:04 2005 +++ php-src/ext/pdo_pgsql/pgsql_driver.c Tue Jul 19 22:37:57 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql_driver.c,v 1.51 2005/07/09 04:54:04 iliaa Exp $ */ +/* $Id: pgsql_driver.c,v 1.52 2005/07/20 02:37:57 wez Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -153,55 +153,58 @@ } #if HAVE_PQPREPARE - stmt->supports_placeholders = PDO_PLACEHOLDER_NAMED; - stmt->named_rewrite_template = "$%d"; - ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len TSRMLS_CC); - - if (ret == 1) { - /* query was re-written */ - sql = nsql; - } else if (ret == -1) { - /* couldn't grok it */ - strcpy(dbh->error_code, stmt->error_code); - return 0; - } - - spprintf(&S->stmt_name, 0, "pdo_pgsql_stmt_%08x", (unsigned int)stmt); - res = PQprepare(H->server, S->stmt_name, sql, 0, NULL); - if (nsql) { - efree(nsql); - } - if (!res) { - pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, NULL); - return 0; - } - - /* check if the connection is using protocol version 2.0. - * if that is the reason that the prepare failed, we want to fall - * through and let PDO emulate it for us */ - status = PQresultStatus(res); - switch (status) { - case PGRES_COMMAND_OK: - case PGRES_TUPLES_OK: - /* it worked */ - PQclear(res); - return 1; - - case PGRES_BAD_RESPONSE: - /* server is probably too old; fall through and let - * PDO emulate it */ - efree(S->stmt_name); - S->stmt_name = NULL; - PQclear(res); - break; + if (!driver_options || pdo_attr_lval(driver_options, + PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT, 0 TSRMLS_CC) == 0) { + stmt->supports_placeholders = PDO_PLACEHOLDER_NAMED; + stmt->named_rewrite_template = "$%d"; + ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len TSRMLS_CC); + + if (ret == 1) { + /* query was re-written */ + sql = nsql; + } else if (ret == -1) { + /* couldn't grok it */ + strcpy(dbh->error_code, stmt->error_code); + return 0; + } - default: - /* protocol 3.0 and above; hard error */ - pdo_pgsql_error(dbh, status, pdo_pgsql_sqlstate(res)); - PQclear(res); + spprintf(&S->stmt_name, 0, "pdo_pgsql_stmt_%08x", (unsigned int)stmt); + res = PQprepare(H->server, S->stmt_name, sql, 0, NULL); + if (nsql) { + efree(nsql); + } + if (!res) { + pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, NULL); return 0; + } + + /* check if the connection is using protocol version 2.0. + * if that is the reason that the prepare failed, we want to fall + * through and let PDO emulate it for us */ + status = PQresultStatus(res); + switch (status) { + case PGRES_COMMAND_OK: + case PGRES_TUPLES_OK: + /* it worked */ + PQclear(res); + return 1; + + case PGRES_BAD_RESPONSE: + /* server is probably too old; fall through and let + * PDO emulate it */ + efree(S->stmt_name); + S->stmt_name = NULL; + PQclear(res); + break; + + default: + /* protocol 3.0 and above; hard error */ + pdo_pgsql_error(dbh, status, pdo_pgsql_sqlstate(res)); + PQclear(res); + return 0; + } + /* fall through */ } - /* fall through */ #endif stmt->supports_placeholders = PDO_PLACEHOLDER_NONE; http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h?r1=1.12&r2=1.13&ty=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.12 php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h:1.13 --- php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h:1.12 Fri Jul 8 11:27:34 2005 +++ php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h Tue Jul 19 22:37:57 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_pdo_pgsql_int.h,v 1.12 2005/07/08 15:27:34 wez Exp $ */ +/* $Id: php_pdo_pgsql_int.h,v 1.13 2005/07/20 02:37:57 wez Exp $ */ #ifndef PHP_PDO_PGSQL_INT_H #define PHP_PDO_PGSQL_INT_H @@ -84,6 +84,10 @@ #define pdo_pgsql_sqlstate(r) (const char *)NULL #endif +enum { + PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT = PDO_ATTR_DRIVER_SPECIFIC, +}; + #endif /* PHP_PDO_PGSQL_INT_H */ /*

« previous php.cvs (#33005) next »