diff options
author | Yasuo Ohgaki <yohgaki@php.net> | 2014-01-15 14:37:24 +0900 |
---|---|---|
committer | Yasuo Ohgaki <yohgaki@php.net> | 2014-01-15 14:37:24 +0900 |
commit | 28be6aea9c4b1915d55595db8789e386c194c938 (patch) | |
tree | c382c6342673a41b7c4c67b29c58086c7af87a97 | |
parent | c58329fccc8bb521251dea7f52e991783b44d3da (diff) | |
download | php-git-28be6aea9c4b1915d55595db8789e386c194c938.tar.gz |
Added pg_lo_truncate() and 64bit large object support from PostgreSQL 9.3 and up
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ext/pgsql/config.m4 | 2 | ||||
-rw-r--r-- | ext/pgsql/pgsql.c | 68 | ||||
-rw-r--r-- | ext/pgsql/php_pgsql.h | 3 |
4 files changed, 73 insertions, 3 deletions
@@ -75,6 +75,9 @@ PHP NEWS - pgsql: . pg_version() returns full report which obtained by PQparameterStatus(). + (Yasuo) + . Added pg_lo_truncate(). (Yasuo) + . Added 64bit large object support for PostgreSQL 9.3 and later. (Yasuo) - Session: . Fixed Bug #65315 (session.hash_function silently fallback to default md5) diff --git a/ext/pgsql/config.m4 b/ext/pgsql/config.m4 index 13837bd832..186469861f 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 d2dfc34f16..20b281e6c7 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -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) @@ -3614,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(); @@ -3628,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; @@ -3641,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(); @@ -3651,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 d6dab56c4c..016f3aa5a8 100644 --- a/ext/pgsql/php_pgsql.h +++ b/ext/pgsql/php_pgsql.h @@ -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); |