php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #64542
Patch patch_pdo_meta.diff revision 2013-03-28 14:37 UTC by vaksenov at avito dot ru

Patch patch_pdo_meta.diff for PDO PgSQL Bug #64542

Patch version 2013-03-28 14:37 UTC

Return to Bug #64542 | Download this patch
Patch Revisions:

Developer: vaksenov@avito.ru

diff --git a/ext/pdo_pgsql/pdo_pgsql.c b/ext/pdo_pgsql/pdo_pgsql.c
index 7c37a60..4635d39 100644
--- a/ext/pdo_pgsql/pdo_pgsql.c
+++ b/ext/pdo_pgsql/pdo_pgsql.c
@@ -86,12 +86,12 @@ ZEND_GET_MODULE(pdo_pgsql)
 PHP_MINIT_FUNCTION(pdo_pgsql)
 {
 	REGISTER_PDO_CLASS_CONST_LONG("PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT", PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT);
+	REGISTER_PDO_CLASS_CONST_LONG("PGSQL_ATTR_DISABLE_RESOLV_NATIVE_TYPE_ON_META", PDO_PGSQL_ATTR_DISABLE_RESOLV_NATIVE_TYPE_ON_META);
 	REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_IDLE", (long)PGSQL_TRANSACTION_IDLE);
 	REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_ACTIVE", (long)PGSQL_TRANSACTION_ACTIVE);
 	REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_INTRANS", (long)PGSQL_TRANSACTION_INTRANS);
 	REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_INERROR", (long)PGSQL_TRANSACTION_INERROR);
 	REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_UNKNOWN", (long)PGSQL_TRANSACTION_UNKNOWN);
-
 	php_pdo_register_driver(&pdo_pgsql_driver);
 	return SUCCESS;
 }
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index a54fccd..fb46f5d 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -1010,6 +1010,9 @@ static int pdo_pgsql_set_attr(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC)
 			H->disable_native_prepares = Z_LVAL_P(val);
 			return 1;
 #endif
+		case PDO_PGSQL_ATTR_DISABLE_RESOLV_NATIVE_TYPE_ON_META:
+			H->disable_resolv_native_type_on_meta = Z_LVAL_P(val);
+			return 1;
 
 		default:
 			return 0;
diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c
index d58eebf..1f7ecd5 100644
--- a/ext/pdo_pgsql/pgsql_statement.c
+++ b/ext/pdo_pgsql/pgsql_statement.c
@@ -586,28 +586,31 @@ static int pgsql_stmt_get_column_meta(pdo_stmt_t *stmt, long colno, zval *return
 	array_init(return_value);
 	add_assoc_long(return_value, "pgsql:oid", S->cols[colno].pgsql_type);
 
-	/* Fetch metadata from Postgres system catalogue */
-	spprintf(&q, 0, "SELECT TYPNAME FROM PG_TYPE WHERE OID=%d", S->cols[colno].pgsql_type);
-	res = PQexec(S->H->server, q);
-	efree(q);
-	
-	status = PQresultStatus(res);
-	
-	if (status != PGRES_TUPLES_OK) {
-		/* Failed to get system catalogue, but return success
-		 * with the data we have collected so far
-		 */
-		goto done;
-	}
+	if (!S->H->disable_resolv_native_type_on_meta) {
+		/* Fetch metadata from Postgres system catalogue */
+		spprintf(&q, 0, "SELECT TYPNAME FROM PG_TYPE WHERE OID=%d", S->cols[colno].pgsql_type);
+		res = PQexec(S->H->server, q);
+		efree(q);
+		
+		status = PQresultStatus(res);
+		
+		if (status != PGRES_TUPLES_OK) {
+			/* Failed to get system catalogue, but return success
+			 * with the data we have collected so far
+			 */
+			goto done;
+		}
 
-	/* We want exactly one row returned */
-	if (1 != PQntuples(res)) {
-		goto done;
-	}
+		/* We want exactly one row returned */
+		if (1 != PQntuples(res)) {
+			goto done;
+		}
 
-	add_assoc_string(return_value, "native_type", PQgetvalue(res, 0, 0), 1);
-done:
-	PQclear(res);		
+		add_assoc_string(return_value, "native_type", PQgetvalue(res, 0, 0), 1);
+		done:
+		PQclear(res);		
+		
+	}
 	return 1;
 }
 
diff --git a/ext/pdo_pgsql/php_pdo_pgsql_int.h b/ext/pdo_pgsql/php_pdo_pgsql_int.h
index 02a6717..edb0998 100644
--- a/ext/pdo_pgsql/php_pdo_pgsql_int.h
+++ b/ext/pdo_pgsql/php_pdo_pgsql_int.h
@@ -51,6 +51,7 @@ typedef struct {
 	int		disable_native_prepares;
 #endif
 	unsigned int stmt_counter;
+	unsigned int disable_resolv_native_type_on_meta;
 } pdo_pgsql_db_handle;
 
 typedef struct {
@@ -93,6 +94,7 @@ extern struct pdo_stmt_methods pgsql_stmt_methods;
 
 enum {
 	PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT = PDO_ATTR_DRIVER_SPECIFIC,
+	PDO_PGSQL_ATTR_DISABLE_RESOLV_NATIVE_TYPE_ON_META,
 };
 
 struct pdo_pgsql_lob_self {
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 19:01:32 2024 UTC