Patch bug63344.patch for PostgreSQL related Bug #63344
Patch version 2012-10-24 06:35 UTC
Return to Bug #63344 |
Download this patch
Patch Revisions:
Developer: laruence@php.net
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index ad66779..48e1370 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -1683,6 +1683,8 @@ PHP_FUNCTION(pg_query_params)
int leftover = 0;
int num_params = 0;
char **params = NULL;
+ int *param_lengths = NULL;
+ int *param_formaters = NULL;
PGconn *pgsql;
PGresult *pgsql_result;
ExecStatusType status;
@@ -1723,16 +1725,23 @@ PHP_FUNCTION(pg_query_params)
if (num_params > 0) {
int i = 0;
params = (char **)safe_emalloc(sizeof(char *), num_params, 0);
-
+ param_lengths = (int *)safe_emalloc(sizeof(int), num_params, 0);
+ param_formaters = (int *)safe_emalloc(sizeof(int), num_params, 0);
+
for(i = 0; i < num_params; i++) {
+ /* make the data in binary format */
+ param_formaters[i] = 1;
if (zend_hash_get_current_data(Z_ARRVAL_P(pv_param_arr), (void **) &tmp) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Error getting parameter");
_php_pgsql_free_params(params, num_params);
+ efree(param_lengths);
+ efree(param_formaters);
RETURN_FALSE;
}
if (Z_TYPE_PP(tmp) == IS_NULL) {
params[i] = NULL;
+ param_lengths[i] = 0;
} else {
zval tmp_val = **tmp;
zval_copy_ctor(&tmp_val);
@@ -1744,6 +1753,7 @@ PHP_FUNCTION(pg_query_params)
RETURN_FALSE;
}
params[i] = estrndup(Z_STRVAL(tmp_val), Z_STRLEN(tmp_val));
+ param_lengths[i] = Z_STRLEN(tmp_val);
zval_dtor(&tmp_val);
}
@@ -1752,12 +1762,12 @@ PHP_FUNCTION(pg_query_params)
}
pgsql_result = PQexecParams(pgsql, query, num_params,
- NULL, (const char * const *)params, NULL, NULL, 0);
+ NULL, (const char * const *)params, (const int *)param_lengths, (const int *)param_formaters, 0);
if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) {
PQclear(pgsql_result);
PQreset(pgsql);
pgsql_result = PQexecParams(pgsql, query, num_params,
- NULL, (const char * const *)params, NULL, NULL, 0);
+ NULL, (const char * const *)params, (const int *)param_lengths, (const int *)param_formaters, 0);
}
if (pgsql_result) {
@@ -1765,8 +1775,13 @@ PHP_FUNCTION(pg_query_params)
} else {
status = (ExecStatusType) PQstatus(pgsql);
}
-
+
_php_pgsql_free_params(params, num_params);
+ if (param_lengths) {
+ efree(param_lengths);
+ efree(param_formaters);
+ }
+
switch (status) {
case PGRES_EMPTY_QUERY:
|