summaryrefslogtreecommitdiff
path: root/ext/pgsql
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pgsql')
-rw-r--r--ext/pgsql/README2
-rw-r--r--ext/pgsql/pgsql.c50
-rw-r--r--ext/pgsql/php_pgsql.h2
-rw-r--r--ext/pgsql/tests/bug65119.phpt40
-rw-r--r--ext/pgsql/tests/config.inc10
5 files changed, 81 insertions, 23 deletions
diff --git a/ext/pgsql/README b/ext/pgsql/README
index 785b4f034..86df804fb 100644
--- a/ext/pgsql/README
+++ b/ext/pgsql/README
@@ -43,7 +43,7 @@ module with specific version. You need to install PostgreSQL
somewhere in your system to build PHP with PostgreSQL support.
==== Note For PostgreSQL 7.2 ====
-I've tested upto 7.2.2.
+I've tested up to 7.2.2.
==== TODO List ===
Make pg_convert() smater.
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 6a433af0f..ed7bf0b61 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2014 The PHP Group |
+ | Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -1370,7 +1370,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
/* ensure that the link did not die */
if (PGG(auto_reset_persistent) & 1) {
/* need to send & get something from backend to
- make sure we catch CONNECTION_BAD everytime */
+ make sure we catch CONNECTION_BAD every time */
PGresult *pg_result;
pg_result = PQexec(le->ptr, "select 1");
PQclear(pg_result);
@@ -1478,7 +1478,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
}
PGG(num_links)++;
}
- /* set notice processer */
+ /* set notice processor */
if (! PGG(ignore_notices) && Z_TYPE_P(return_value) == IS_RESOURCE) {
PQsetNoticeProcessor(pgsql, _php_pgsql_notice_handler, (void*)Z_RESVAL_P(return_value));
}
@@ -3731,10 +3731,10 @@ PHP_FUNCTION(pg_lo_export)
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
- if (lo_export(pgsql, oid, file_out)) {
- RETURN_TRUE;
+ if (lo_export(pgsql, oid, file_out) == -1) {
+ RETURN_FALSE;
}
- RETURN_FALSE;
+ RETURN_TRUE;
}
/* }}} */
@@ -4211,18 +4211,26 @@ PHP_FUNCTION(pg_copy_from)
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(pg_rows), &pos);
#if HAVE_PQPUTCOPYDATA
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) {
- convert_to_string_ex(tmp);
- query = (char *)emalloc(Z_STRLEN_PP(tmp) + 2);
- strlcpy(query, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) + 2);
- if(Z_STRLEN_PP(tmp) > 0 && *(query + Z_STRLEN_PP(tmp) - 1) != '\n') {
- strlcat(query, "\n", Z_STRLEN_PP(tmp) + 2);
+ zval *value;
+ ALLOC_ZVAL(value);
+ INIT_PZVAL_COPY(value, *tmp);
+ zval_copy_ctor(value);
+ convert_to_string_ex(&value);
+ query = (char *)emalloc(Z_STRLEN_P(value) + 2);
+ strlcpy(query, Z_STRVAL_P(value), Z_STRLEN_P(value) + 2);
+ if(Z_STRLEN_P(value) > 0 && *(query + Z_STRLEN_P(value) - 1) != '\n') {
+ strlcat(query, "\n", Z_STRLEN_P(value) + 2);
}
if (PQputCopyData(pgsql, query, strlen(query)) != 1) {
efree(query);
+ zval_dtor(value);
+ efree(value);
PHP_PQ_ERROR("copy failed: %s", pgsql);
RETURN_FALSE;
}
efree(query);
+ zval_dtor(value);
+ efree(value);
zend_hash_move_forward_ex(Z_ARRVAL_P(pg_rows), &pos);
}
if (PQputCopyEnd(pgsql, NULL) != 1) {
@@ -4231,18 +4239,26 @@ PHP_FUNCTION(pg_copy_from)
}
#else
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(pg_rows), (void **) &tmp, &pos) == SUCCESS) {
- convert_to_string_ex(tmp);
- query = (char *)emalloc(Z_STRLEN_PP(tmp) + 2);
- strlcpy(query, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp) + 2);
- if(Z_STRLEN_PP(tmp) > 0 && *(query + Z_STRLEN_PP(tmp) - 1) != '\n') {
- strlcat(query, "\n", Z_STRLEN_PP(tmp) + 2);
+ zval *value;
+ ALLOC_ZVAL(value);
+ INIT_PZVAL_COPY(value, *tmp);
+ zval_copy_ctor(value);
+ convert_to_string_ex(&value);
+ query = (char *)emalloc(Z_STRLEN_P(value) + 2);
+ strlcpy(query, Z_STRVAL_P(value), Z_STRLEN_P(value) + 2);
+ if(Z_STRLEN_P(value) > 0 && *(query + Z_STRLEN_P(value) - 1) != '\n') {
+ strlcat(query, "\n", Z_STRLEN_P(value) + 2);
}
if (PQputline(pgsql, query)==EOF) {
efree(query);
+ zval_dtor(value);
+ efree(value);
PHP_PQ_ERROR("copy failed: %s", pgsql);
RETURN_FALSE;
}
efree(query);
+ zval_dtor(value);
+ efree(value);
zend_hash_move_forward_ex(Z_ARRVAL_P(pg_rows), &pos);
}
if (PQputline(pgsql, "\\.\n") == EOF) {
@@ -4358,7 +4374,7 @@ PHP_FUNCTION(pg_escape_bytea)
#endif
to = (char *)PQescapeBytea((unsigned char*)from, from_len, &to_len);
- RETVAL_STRINGL(to, to_len-1, 1); /* to_len includes addtional '\0' */
+ RETVAL_STRINGL(to, to_len-1, 1); /* to_len includes additional '\0' */
PQfreemem(to);
}
/* }}} */
diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h
index 62f20dad5..560a47e32 100644
--- a/ext/pgsql/php_pgsql.h
+++ b/ext/pgsql/php_pgsql.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2014 The PHP Group |
+ | Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
diff --git a/ext/pgsql/tests/bug65119.phpt b/ext/pgsql/tests/bug65119.phpt
new file mode 100644
index 000000000..c02ff28f0
--- /dev/null
+++ b/ext/pgsql/tests/bug65119.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Bug #65119 (pg_copy_from() modifies input array variable)
+--SKIPIF--
+<?php
+include("skipif.inc");
+?>
+--FILE--
+<?php
+include 'config.inc';
+
+function test(Array $values, $conn_str) {
+ $connection = pg_pconnect($conn_str, PGSQL_CONNECT_FORCE_NEW);
+ pg_query("begin");
+ pg_query("CREATE TABLE bug65119 (i INTEGER)");
+ pg_copy_from($connection, "bug65119", $values, "\t", "NULL");
+ pg_query("rollback");
+}
+
+$values = Array(1,2,3);
+var_dump($values);
+test($values, $conn_str);
+var_dump($values);
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+}
+array(3) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+}
diff --git a/ext/pgsql/tests/config.inc b/ext/pgsql/tests/config.inc
index 367f1ef9b..e9944de79 100644
--- a/ext/pgsql/tests/config.inc
+++ b/ext/pgsql/tests/config.inc
@@ -1,10 +1,12 @@
<?php
+
// These vars are used to connect db and create test table.
-// values can be set to meet your environment
+// values can be set to meet your environment with the
+// environment var PGSQL_TEST_CONNSTR
+
+// "test" database must exist. i.e. "createdb test" before testing
+$conn_str = getenv('PGSQL_TEST_CONNSTR') ?: "host=localhost dbname=test port=5432"; // connection string
-// "test" database must be existed. i.e. "createdb test" before testing
-// PostgreSQL uses login name as username, user must have access to "test" database.
-$conn_str = "host=localhost dbname=test port=5432"; // connection string
$table_name = "php_pgsql_test"; // test table that will be created
$table_name_92 = "php_pgsql_test_92"; // test table that will be created
$num_test_record = 1000; // Number of records to create