Here are the patches against 5.2 HEAD. Modified API's are:
1) pg_lo_create now accepts an optional parameter (large object id). This corresponds to lo_create() which is new in PostgreSQL 8.1. 2) new API: pg_lo_import_with_oid. Same as pg_lo_import except that it accepts large object id. This corresponds to lo_import_with_oid() which is new in PostgreSQL 8.4 (current). -- Tatsuo Ishii SRA OSS, Inc. Japan > Hello Marcus, > > Thanks for guiding me. I'm going to make patches in a few days. > BTW, the problem I'm talking about does not seem to exist in the bug > database. > -- > Tatsuo Ishii > SRA OSS, Inc. Japan > > > Hello Tatsuo, > > > > first of all thanks for offering to help! > > > > the usual way is to provide a few patches. You can check > > http://bugs.php.net for open bugs in your area. When we like the patches > > we'll apply them and give you an account. > > > > marcus > > > > Monday, April 14, 2008, 1:21:47 PM, you wrote: > > > > > Hi, > > > > > I would like to contribute to ext/pgsql module. Could I have CVS > > > account? > > > > > I've been working on PostgreSQL development for years. My intention > > > is to catch up PostgreSQL develpment especially when new API is > > > added. For example an API added to PostgreSQL 8.1 (back to 2005) is > > > not in PHP yet. > > > > > I have talked to Yasuo Ohgaki (one of the pgsql module maintainers) > > > and he seems to be happy. > > > -- > > > Tatsuo Ishii > > > SRA OSS, Inc. Japan > > > > > > > > > > Best regards, > > Marcus > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
Index: config.m4 =================================================================== RCS file: /repository/php-src/ext/pgsql/config.m4,v retrieving revision 1.46.2.1.2.5 diff -c -r1.46.2.1.2.5 config.m4 *** config.m4 11 Jul 2007 21:51:55 -0000 1.46.2.1.2.5 --- config.m4 17 Apr 2008 14:41:04 -0000 *************** *** 92,97 **** --- 92,99 ---- AC_CHECK_LIB(pq, PQescapeStringConn, AC_DEFINE(HAVE_PQESCAPE_CONN,1,[PostgreSQL 8.1.4 or later])) AC_CHECK_LIB(pq, PQescapeByteaConn, AC_DEFINE(HAVE_PQESCAPE_BYTEA_CONN,1,[PostgreSQL 8.1.4 or later])) 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_LO_CREATE,1,[PostgreSQL 8.1 or later])) + AC_CHECK_LIB(pq, lo_import_with_oid, AC_DEFINE(HAVE_LO_IMPORT_WITH_OID,1,[PostgreSQL 8.4 or later])) LIBS=$old_LIBS LDFLAGS=$old_LDFLAGS Index: pgsql.c =================================================================== RCS file: /repository/php-src/ext/pgsql/pgsql.c,v retrieving revision 1.331.2.13.2.27 diff -c -r1.331.2.13.2.27 pgsql.c *** pgsql.c 31 Dec 2007 07:20:10 -0000 1.331.2.13.2.27 --- pgsql.c 17 Apr 2008 14:41:06 -0000 *************** *** 188,193 **** --- 188,196 ---- PHP_FE(pg_lo_write, NULL) PHP_FE(pg_lo_read_all, NULL) PHP_FE(pg_lo_import, NULL) + #if HAVE_LO_IMPORT_WITH_OID + PHP_FE(pg_lo_import_with_oid, NULL) + #endif PHP_FE(pg_lo_export, NULL) PHP_FE(pg_lo_seek, NULL) PHP_FE(pg_lo_tell, NULL) *************** *** 2514,2561 **** } /* }}} */ ! /* {{{ proto int pg_lo_create([resource connection]) Create a large object */ PHP_FUNCTION(pg_lo_create) { ! zval **pgsql_link = NULL; PGconn *pgsql; ! Oid pgsql_oid; int id = -1; ! switch(ZEND_NUM_ARGS()) { ! case 0: ! id = PGG(default_link); ! CHECK_DEFAULT_LINK(id); ! break; ! case 1: ! if (zend_get_parameters_ex(1, &pgsql_link)==FAILURE) { ! RETURN_FALSE; ! } ! break; ! default: WRONG_PARAM_COUNT; ! break; } if (pgsql_link == NULL && id == -1) { RETURN_FALSE; } ! ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); ! ! /* NOTE: Archive modes not supported until I get some more data. Don't think anybody's ! using it anyway. I believe it's also somehow related to the 'time travel' feature of ! PostgreSQL, that's on the list of features to be removed... Create modes not supported. ! What's the use of an object that can be only written to, but not read from, and vice ! versa? Beats me... And the access type (r/w) must be specified again when opening ! the object, probably (?) overrides this. (Jouni) ! */ ! if ((pgsql_oid = lo_creat(pgsql, INV_READ|INV_WRITE)) == InvalidOid) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create PostgreSQL large object"); RETURN_FALSE; } ! PGSQL_RETURN_OID(pgsql_oid); } /* }}} */ --- 2517,2617 ---- } /* }}} */ ! /* {{{ proto int pg_lo_create([resource connection,] string large_object_oid) Create a large object */ PHP_FUNCTION(pg_lo_create) { ! zval *pgsql_link = NULL; ! long oid_long; ! char *oid_string, *end_ptr; ! int oid_strlen; PGconn *pgsql; ! Oid oid; ! Oid out_oid; int id = -1; + int argc = ZEND_NUM_ARGS(); ! #ifndef HAVE_PQ_LO_CREATE ! int newapi = 1; ! #else ! int newapi = 0; ! #endif ! ! /* accept string type since Oid type is unsigned int */ ! if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, ! "rs", &pgsql_link, &oid_string, &oid_strlen) == SUCCESS) { ! if (newapi == 0) { WRONG_PARAM_COUNT; ! RETURN_FALSE; ! } ! oid = (Oid)strtoul(oid_string, &end_ptr, 10); ! if ((oid_string+oid_strlen) != end_ptr) { ! /* wrong integer format */ ! php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed"); ! RETURN_FALSE; ! } ! } ! else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, ! "rl", &pgsql_link, &oid_long) == SUCCESS) { ! if (newapi == 0) { ! WRONG_PARAM_COUNT; ! RETURN_FALSE; ! } ! if (oid_long < InvalidOid) { ! php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID specified"); ! RETURN_FALSE; ! } ! oid = (Oid)oid_long; ! } ! else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, ! "s", &oid_string, &oid_strlen) == SUCCESS) { ! oid = (Oid)strtoul(oid_string, &end_ptr, 10); ! if ((oid_string+oid_strlen) != end_ptr) { ! /* wrong integer format */ ! php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed"); ! RETURN_FALSE; ! } ! id = PGG(default_link); ! CHECK_DEFAULT_LINK(id); ! } ! else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, ! "l", &oid_long) == SUCCESS) { ! if (newapi == 0) { ! WRONG_PARAM_COUNT; ! RETURN_FALSE; ! } ! if (oid_long < InvalidOid) { ! php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID is specified"); ! RETURN_FALSE; ! } ! oid = (Oid)oid_long; ! id = PGG(default_link); ! CHECK_DEFAULT_LINK(id); ! } ! else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, ! "r", &pgsql_link) == SUCCESS) { ! oid = InvalidOid; ! } ! else { ! php_error_docref(NULL TSRMLS_CC, E_WARNING, "Requires 1 or 2 arguments"); ! RETURN_FALSE; } if (pgsql_link == NULL && id == -1) { RETURN_FALSE; } ! ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); ! #if HAVE_PQ_LO_CREATE ! out_oid = lo_create(pgsql, oid); ! #else ! out_oid = lo_creat(pgsql, INV_READ|INV_WRITE); ! #endif ! if (out_oid == InvalidOid) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create PostgreSQL large object"); RETURN_FALSE; } ! PGSQL_RETURN_OID(out_oid); } /* }}} */ *************** *** 2939,2948 **** --- 2995,3106 ---- if (oid == InvalidOid) { RETURN_FALSE; } + PGSQL_RETURN_OID(oid); } /* }}} */ + #if HAVE_LO_IMPORT_WITH_OID + /* {{{ proto int pg_lo_import_with_oid([resource connection, ] int objoid, string filename) + Import large object direct from filesystem */ + PHP_FUNCTION(pg_lo_import_with_oid) + { + zval *pgsql_link = NULL; + char *file_in, *oid_string, *end_ptr; + int oid_strlen; + int id = -1, name_len; + long oid_long; + Oid oid; + Oid out_oid; + PGconn *pgsql; + int argc = ZEND_NUM_ARGS(); + + /* allow string to handle large OID value correctly */ + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, + "rls", &pgsql_link, &oid_long, &file_in, &name_len) == SUCCESS) { + if (oid_long < InvalidOid) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID specified"); + RETURN_FALSE; + } + oid = (Oid)oid_long; + } + else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, + "rss", &pgsql_link, &oid_string, &oid_strlen, &file_in, &name_len) == SUCCESS) { + oid = (Oid)strtoul(oid_string, &end_ptr, 10); + if ((oid_string+oid_strlen) != end_ptr) { + /* wrong integer format */ + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed"); + RETURN_FALSE; + } + } + else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, + "ls", &oid_long, &file_in, &name_len) == SUCCESS) { + if (oid_long < InvalidOid) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID specified"); + RETURN_FALSE; + } + oid = (Oid)oid_long; + id = PGG(default_link); + CHECK_DEFAULT_LINK(id); + } + else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, + "ss", &oid_string, &oid_strlen, &file_in, &name_len) == SUCCESS) { + oid = (Oid)strtoul(oid_string, &end_ptr, 10); + if ((oid_string+oid_strlen) != end_ptr) { + /* wrong integer format */ + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed"); + RETURN_FALSE; + } + id = PGG(default_link); + CHECK_DEFAULT_LINK(id); + } + else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, + "ssr", &oid_string, &oid_strlen, &file_in, &name_len, &pgsql_link) == SUCCESS) { + oid = (Oid)strtoul(oid_string, &end_ptr, 10); + if ((oid_string+oid_strlen) != end_ptr) { + /* wrong integer format */ + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Wrong OID value passed"); + RETURN_FALSE; + } + } + else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, + "lsr", &oid_long, &file_in, &name_len, &pgsql_link) == SUCCESS) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Old API is used"); + if (oid_long < InvalidOid) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid OID specified"); + RETURN_FALSE; + } + oid = (Oid)oid_long; + } + else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Requires 2 or 3 arguments"); + RETURN_FALSE; + } + + if (PG(safe_mode) &&(!php_checkuid(file_in, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + RETURN_FALSE; + } + + if (php_check_open_basedir(file_in TSRMLS_CC)) { + RETURN_FALSE; + } + + if (pgsql_link == NULL && id == -1) { + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); + + out_oid = lo_import_with_oid(pgsql, file_in, oid); + if (out_oid == InvalidOid) { + RETURN_FALSE; + } + + PGSQL_RETURN_OID(out_oid); + } + /* }}} */ + #endif + /* {{{ proto bool pg_lo_export([resource connection, ] int objoid, string filename) Export large object direct to filesystem */ PHP_FUNCTION(pg_lo_export) Index: php_pgsql.h =================================================================== RCS file: /repository/php-src/ext/pgsql/php_pgsql.h,v retrieving revision 1.73.2.1.2.3 diff -c -r1.73.2.1.2.3 php_pgsql.h *** php_pgsql.h 31 Dec 2007 07:20:10 -0000 1.73.2.1.2.3 --- php_pgsql.h 17 Apr 2008 14:41:06 -0000 *************** *** 150,155 **** --- 150,156 ---- PHP_FUNCTION(pg_lo_write); PHP_FUNCTION(pg_lo_read_all); PHP_FUNCTION(pg_lo_import); + PHP_FUNCTION(pg_lo_import_with_oid); PHP_FUNCTION(pg_lo_export); PHP_FUNCTION(pg_lo_seek); PHP_FUNCTION(pg_lo_tell);
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php