diff options
author | Ondřej Surý <ondrej@sury.org> | 2014-01-28 10:57:59 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2014-01-28 10:57:59 +0100 |
commit | 575107aad92a460051e02de029067359083542b9 (patch) | |
tree | 462d4270312d11a5c064e151e3fdd2f671bd540b /ext/pgsql | |
parent | 650fb41a77b3a24ab4130b05fff243b64b241877 (diff) | |
download | php-575107aad92a460051e02de029067359083542b9.tar.gz |
New upstream version 5.6.0~alpha1+dfsgupstream/5.6.0_alpha1+dfsg
Diffstat (limited to 'ext/pgsql')
-rw-r--r-- | ext/pgsql/config.m4 | 2 | ||||
-rw-r--r-- | ext/pgsql/pgsql.c | 94 | ||||
-rw-r--r-- | ext/pgsql/php_pgsql.h | 5 | ||||
-rw-r--r-- | ext/pgsql/tests/00version.phpt | 50 | ||||
-rw-r--r-- | ext/pgsql/tests/14pg_update_9.phpt | 2 | ||||
-rw-r--r-- | ext/pgsql/tests/80_bug14383.phpt | 2 | ||||
-rw-r--r-- | ext/pgsql/tests/80_bug36625.phpt | 2 | ||||
-rw-r--r-- | ext/pgsql/tests/80_bug39971.phpt | 2 | ||||
-rw-r--r-- | ext/pgsql/tests/config.inc | 4 |
9 files changed, 152 insertions, 11 deletions
diff --git a/ext/pgsql/config.m4 b/ext/pgsql/config.m4 index 13837bd83..186469861 100644 --- a/ext/pgsql/config.m4 +++ b/ext/pgsql/config.m4 @@ -94,6 +94,8 @@ if test "$PHP_PGSQL" != "no"; then AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibyte])) AC_CHECK_LIB(pq, lo_create, AC_DEFINE(HAVE_PG_LO_CREATE,1,[PostgreSQL 8.1 or later])) AC_CHECK_LIB(pq, lo_import_with_oid, AC_DEFINE(HAVE_PG_LO_IMPORT_WITH_OID,1,[PostgreSQL 8.4 or later])) + AC_CHECK_LIB(pq, lo_truncate, AC_DEFINE(HAVE_PG_LO_TRUNCATE,1,[PostgreSQL 8.3 or later])) + AC_CHECK_LIB(pq, lo_truncate64, AC_DEFINE(HAVE_PG_LO64,1,[PostgreSQL 9.3 or later])) AC_CHECK_LIB(pq, PQescapeLiteral, AC_DEFINE(HAVE_PQESCAPELITERAL,1,[PostgreSQL 9.0 or later])) LIBS=$old_LIBS LDFLAGS=$old_LDFLAGS diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 32d407af7..20b281e6c 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2013 The PHP Group | + | Copyright (c) 1997-2014 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 | @@ -19,7 +19,7 @@ | Chris Kings-Lynne <chriskl@php.net> (v3 protocol) | +----------------------------------------------------------------------+ */ - + /* $Id$ */ #include <stdlib.h> @@ -367,6 +367,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_pg_lo_tell, 0, 0, 1) ZEND_ARG_INFO(0, large_object) ZEND_END_ARG_INFO() +#if HAVE_PG_LO_TRUNCATE +ZEND_BEGIN_ARG_INFO_EX(arginfo_pg_lo_truncate, 0, 0, 1) + ZEND_ARG_INFO(0, large_object) + ZEND_ARG_INFO(0, size) +ZEND_END_ARG_INFO() +#endif + #if HAVE_PQSETERRORVERBOSITY ZEND_BEGIN_ARG_INFO_EX(arginfo_pg_set_error_verbosity, 0, 0, 0) ZEND_ARG_INFO(0, connection) @@ -661,6 +668,9 @@ const zend_function_entry pgsql_functions[] = { PHP_FE(pg_lo_export, arginfo_pg_lo_export) PHP_FE(pg_lo_seek, arginfo_pg_lo_seek) PHP_FE(pg_lo_tell, arginfo_pg_lo_tell) +#if HAVE_PG_LO_TRUNCATE + PHP_FE(pg_lo_truncate, arginfo_pg_lo_truncate) +#endif /* utility functions */ #if HAVE_PQESCAPE PHP_FE(pg_escape_string, arginfo_pg_escape_string) @@ -1504,7 +1514,29 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type add_assoc_long(return_value, "protocol", PQprotocolVersion(pgsql)); #if HAVE_PQPARAMETERSTATUS if (PQprotocolVersion(pgsql) >= 3) { + /* 8.0 or grater supports protorol version 3 */ + char *tmp; add_assoc_string(return_value, "server", (char*)PQparameterStatus(pgsql, "server_version"), 1); + tmp = (char*)PQparameterStatus(pgsql, "server_encoding"); + add_assoc_string(return_value, "server_encoding", tmp, 1); + tmp = (char*)PQparameterStatus(pgsql, "client_encoding"); + add_assoc_string(return_value, "client_encoding", tmp, 1); + tmp = (char*)PQparameterStatus(pgsql, "is_superuser"); + add_assoc_string(return_value, "is_superuser", tmp, 1); + tmp = (char*)PQparameterStatus(pgsql, "session_authorization"); + add_assoc_string(return_value, "session_authorization", tmp, 1); + tmp = (char*)PQparameterStatus(pgsql, "DateStyle"); + add_assoc_string(return_value, "DateStyle", tmp, 1); + tmp = (char*)PQparameterStatus(pgsql, "IntervalStyle"); + add_assoc_string(return_value, "IntervalStyle", tmp ? tmp : "", 1); + tmp = (char*)PQparameterStatus(pgsql, "TimeZone"); + add_assoc_string(return_value, "TimeZone", tmp ? tmp : "", 1); + tmp = (char*)PQparameterStatus(pgsql, "integer_datetimes"); + add_assoc_string(return_value, "integer_datetimes", tmp ? tmp : "", 1); + tmp = (char*)PQparameterStatus(pgsql, "standard_conforming_strings"); + add_assoc_string(return_value, "standard_conforming_strings", tmp ? tmp : "", 1); + tmp = (char*)PQparameterStatus(pgsql, "application_name"); + add_assoc_string(return_value, "application_name", tmp ? tmp : "", 1); } #endif #endif @@ -3592,7 +3624,7 @@ PHP_FUNCTION(pg_lo_export) PHP_FUNCTION(pg_lo_seek) { zval *pgsql_id = NULL; - long offset = 0, whence = SEEK_CUR; + long result, offset = 0, whence = SEEK_CUR; pgLofp *pgsql; int argc = ZEND_NUM_ARGS(); @@ -3606,7 +3638,16 @@ PHP_FUNCTION(pg_lo_seek) ZEND_FETCH_RESOURCE(pgsql, pgLofp *, &pgsql_id, -1, "PostgreSQL large object", le_lofp); - if (lo_lseek((PGconn *)pgsql->conn, pgsql->lofd, offset, whence) > -1) { +#if HAVE_PG_LO64 + if (PQserverVersion((PGconn *)pgsql->conn) >= 90300) { + result = lo_lseek64((PGconn *)pgsql->conn, pgsql->lofd, offset, whence); + } else { + result = lo_lseek((PGconn *)pgsql->conn, pgsql->lofd, offset, whence); + } +#else + result = lo_lseek((PGconn *)pgsql->conn, pgsql->lofd, offset, whence); +#endif + if (result > -1) { RETURN_TRUE; } else { RETURN_FALSE; @@ -3619,7 +3660,7 @@ PHP_FUNCTION(pg_lo_seek) PHP_FUNCTION(pg_lo_tell) { zval *pgsql_id = NULL; - int offset = 0; + long offset = 0; pgLofp *pgsql; int argc = ZEND_NUM_ARGS(); @@ -3629,11 +3670,54 @@ PHP_FUNCTION(pg_lo_tell) ZEND_FETCH_RESOURCE(pgsql, pgLofp *, &pgsql_id, -1, "PostgreSQL large object", le_lofp); +#if HAVE_PG_LO64 + if (PQserverVersion((PGconn *)pgsql->conn) >= 90300) { + offset = lo_tell64((PGconn *)pgsql->conn, pgsql->lofd); + } else { + offset = lo_tell((PGconn *)pgsql->conn, pgsql->lofd); + } +#else offset = lo_tell((PGconn *)pgsql->conn, pgsql->lofd); +#endif RETURN_LONG(offset); } /* }}} */ +#if HAVE_PG_LO_TRUNCATE +/* {{{ proto bool pg_lo_truncate(resource large_object, int size) + Truncate large object to size */ +PHP_FUNCTION(pg_lo_truncate) +{ + zval *pgsql_id = NULL; + size_t size; + pgLofp *pgsql; + int argc = ZEND_NUM_ARGS(); + int result; + + if (zend_parse_parameters(argc TSRMLS_CC, "rl", &pgsql_id, &size) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(pgsql, pgLofp *, &pgsql_id, -1, "PostgreSQL large object", le_lofp); + +#if HAVE_PG_LO64 + if (PQserverVersion((PGconn *)pgsql->conn) >= 90300) { + result = lo_truncate64((PGconn *)pgsql->conn, pgsql->lofd, size); + } else { + result = lo_truncate((PGconn *)pgsql->conn, pgsql->lofd, size); + } +#else + result = lo_truncate((PGconn *)pgsql->conn, pgsql->lofd, size); +#endif + if (!result) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ +#endif + #if HAVE_PQSETERRORVERBOSITY /* {{{ proto int pg_set_error_verbosity([resource connection,] int verbosity) Set error verbosity */ diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h index 63f50f0f9..016f3aa5a 100644 --- a/ext/pgsql/php_pgsql.h +++ b/ext/pgsql/php_pgsql.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2013 The PHP Group | + | Copyright (c) 1997-2014 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 | @@ -157,6 +157,9 @@ PHP_FUNCTION(pg_lo_import); PHP_FUNCTION(pg_lo_export); PHP_FUNCTION(pg_lo_seek); PHP_FUNCTION(pg_lo_tell); +#if HAVE_PG_LO_TRUNCATE +PHP_FUNCTION(pg_lo_truncate); +#endif /* debugging functions */ PHP_FUNCTION(pg_trace); diff --git a/ext/pgsql/tests/00version.phpt b/ext/pgsql/tests/00version.phpt new file mode 100644 index 000000000..e4e442d01 --- /dev/null +++ b/ext/pgsql/tests/00version.phpt @@ -0,0 +1,50 @@ +--TEST-- +PostgreSQL version +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php +// Get postgresql version for easier debugging. +// Execute run-test.php with --keep-all to get version string in 00version.log or 00version.out +include('config.inc'); + +$db = pg_connect($conn_str); +var_dump(pg_version($db)); +pg_close($db); + +// Get environment vars for debugging +var_dump(serialize($_ENV)); + +echo "OK"; +?> +--EXPECTF-- +array(13) { + ["client"]=> + string(%d) "%s" + ["protocol"]=> + int(%d) + ["server"]=> + string(%d) "%s" + ["server_encoding"]=> + string(%d) "%s" + ["client_encoding"]=> + string(%d) "%s" + ["is_superuser"]=> + string(%d) "%s" + ["session_authorization"]=> + string(%d) "%s" + ["DateStyle"]=> + string(%d) "%s" + ["IntervalStyle"]=> + string(%d) %s + ["TimeZone"]=> + string(%d) "%s" + ["integer_datetimes"]=> + string(%d) "%s" + ["standard_conforming_strings"]=> + string(%d) "%s" + ["application_name"]=> + string(%d) %s +} +string(%d) "%s" +OK diff --git a/ext/pgsql/tests/14pg_update_9.phpt b/ext/pgsql/tests/14pg_update_9.phpt index e766c1f38..c33f1afbd 100644 --- a/ext/pgsql/tests/14pg_update_9.phpt +++ b/ext/pgsql/tests/14pg_update_9.phpt @@ -1,5 +1,5 @@ --TEST-- -PostgreSQL pg_update() (9.0) +PostgreSQL pg_update() (9.0+) --SKIPIF-- <?php include("skipif.inc"); diff --git a/ext/pgsql/tests/80_bug14383.phpt b/ext/pgsql/tests/80_bug14383.phpt index a736f34c9..cb54aa8df 100644 --- a/ext/pgsql/tests/80_bug14383.phpt +++ b/ext/pgsql/tests/80_bug14383.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #14383 (using postgres with DBA causes DBA not to be able to find any keys) +Bug #14383 (8.0+) (using postgres with DBA causes DBA not to be able to find any keys) --SKIPIF-- <?php require_once(dirname(__FILE__).'/../../dba/tests/skipif.inc'); diff --git a/ext/pgsql/tests/80_bug36625.phpt b/ext/pgsql/tests/80_bug36625.phpt index 9cc8a1d4f..e1b7fa1b5 100644 --- a/ext/pgsql/tests/80_bug36625.phpt +++ b/ext/pgsql/tests/80_bug36625.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #36625 (pg_trace() does not work) +Bug #36625 (8.0+) (pg_trace() does not work) --SKIPIF-- <?php require_once('skipif.inc'); diff --git a/ext/pgsql/tests/80_bug39971.phpt b/ext/pgsql/tests/80_bug39971.phpt index 45d26319d..49f370b88 100644 --- a/ext/pgsql/tests/80_bug39971.phpt +++ b/ext/pgsql/tests/80_bug39971.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #39971 (pg_insert/pg_update do not allow now() to be used for timestamp fields) +Bug #39971 (8.0+) (pg_insert/pg_update do not allow now() to be used for timestamp fields) --SKIPIF-- <?php require_once('skipif.inc'); diff --git a/ext/pgsql/tests/config.inc b/ext/pgsql/tests/config.inc index d4bbb3382..ffe31a875 100644 --- a/ext/pgsql/tests/config.inc +++ b/ext/pgsql/tests/config.inc @@ -2,8 +2,10 @@ // These vars are used to connect db and create test table. // values can be set to meet your environment +// "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 should be exist +$table_name = "php_pgsql_test"; // test table that will be created $num_test_record = 1000; // Number of records to create $table_def = "CREATE TABLE php_pgsql_test (num int, str text, bin bytea);"; // Test table |