Sorry for delay. Here is the revised patches. I marged pg_lo_import_with_oid() into pg_lo_import(). -- Tatsuo Ishii SRA OSS, Inc. Japan
> > On 17.04.2008 18:50, Tatsuo Ishii wrote: > > > Here are the patches against 5.2 HEAD. > > > > First of all, please use `diff -u`, not just `diff` - unified diffs are > > much more readable. > > Ok. I'll do it next time. > > > > 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). > > > > Is there a real need for a new function? > > Can't we modify pg_lo_import() to accept one more argument? > > There's no techinical reason to add lo_import_with_oid(). I just > wanted to directly map the PostgreSQL API to PHP's API. If integrating > to pg_lo_import() is the PHP's way, I would be happy to update my > patches. > -- > Tatsuo Ishii > SRA OSS, Inc. Japan > > -- > 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 -u -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 1 Jul 2008 15:58:25 -0000 @@ -92,6 +92,8 @@ 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.28 diff -u -r1.331.2.13.2.28 pgsql.c --- pgsql.c 19 May 2008 15:18:39 -0000 1.331.2.13.2.28 +++ pgsql.c 1 Jul 2008 15:58:27 -0000 @@ -2514,48 +2514,101 @@ } /* }}} */ -/* {{{ proto int pg_lo_create([resource connection]) +/* {{{ proto int pg_lo_create([resource connection,] string large_object_oid) Create a large object */ PHP_FUNCTION(pg_lo_create) { - zval **pgsql_link = NULL; + zval *pgsql_link = NULL; + long oid_long; + char *oid_string, *end_ptr; + int oid_strlen; PGconn *pgsql; - Oid pgsql_oid; + Oid oid; + Oid out_oid; int id = -1; + int argc = ZEND_NUM_ARGS(); - 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: +#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; - break; + 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); - - /* 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) - */ + ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); - if ((pgsql_oid = lo_creat(pgsql, INV_READ|INV_WRITE)) == InvalidOid) { +#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(pgsql_oid); + PGSQL_RETURN_OID(out_oid); } /* }}} */ @@ -2892,16 +2945,19 @@ } /* }}} */ -/* {{{ proto int pg_lo_import([resource connection, ] string filename) +/* {{{ proto int pg_lo_import([resource connection, ] [ int objoid, ] string filename) Import large object direct from filesystem */ PHP_FUNCTION(pg_lo_import) { zval *pgsql_link = NULL; - char *file_in; + char *file_in, *oid_string, *end_ptr; + int oid_strlen; int id = -1, name_len; - int argc = ZEND_NUM_ARGS(); + long oid_long; + Oid oid = InvalidOid; + Oid out_oid; PGconn *pgsql; - Oid oid; + int argc = ZEND_NUM_ARGS(); if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "rs", &pgsql_link, &file_in, &name_len) == SUCCESS) { @@ -2916,8 +2972,29 @@ "sr", &file_in, &name_len, &pgsql_link ) == SUCCESS) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Old API is used"); } +#if HAVE_LO_IMPORT_WITH_OID + /* allow string to handle large OID value correctly */ + else 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; + } + } +#endif else { - WRONG_PARAM_COUNT; + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong arguments"); + RETURN_FALSE; } if (PG(safe_mode) &&(!php_checkuid(file_in, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { @@ -2934,12 +3011,17 @@ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink); - oid = lo_import(pgsql, file_in); +#if HAVE_LO_IMPORT_WITH_OID + out_oid = lo_import_with_oid(pgsql, file_in, oid); +#else + out_oid = lo_import(pgsql, file_in); +#endif - if (oid == InvalidOid) { + if (out_oid == InvalidOid) { RETURN_FALSE; - } - PGSQL_RETURN_OID(oid); + } + + PGSQL_RETURN_OID(out_oid); } /* }}} */
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php