Re: [PHP-CVS] cvs: php-src /ext/pgsql pgsql.c php_pgsql.h
1.74 2006/01/01 13:09:53 sniper Exp $ */ +/* $Id: php_pgsql.h,v 1.75 2006/03/16 14:58:56 edink Exp $ */ #ifndef PHP_PGSQL_H #define PHP_PGSQL_H @@ -125,6 +125,7 @@ PHP_FUNCTION(pg_field_type_oid); PHP_FUNCTION(pg_field_prtlen); PHP_FUNCTION(pg_field_is_null); +PHP_FUNCTION(pg_field_table); /* async message functions */ PHP_FUNCTION(pg_get_notify); PHP_FUNCTION(pg_get_pid); -- Christopher Kings-Lynne Web Team Leader CalorieKing Tel: +618.9389.8777 Fax: +618.9389.8444 [EMAIL PROTECTED] www.calorieking.com -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src / NEWS /ext/pgsql pgsql.c php_pgsql.h
Done. Dunno if i have to put new files anywhere else other than just added them Surely it should be the function writer's job to document what they add? This function should probably also be called 'pg_fetch_column' to be consistent. Chris Antony Dovgal wrote: Send a patch to the docs list? On Fri, 08 Jul 2005 15:48:38 +0800 Christopher Kings-Lynne [EMAIL PROTECTED] wrote: Docs? Ilia Alshanetsky wrote: iliaa Thu Jul 7 20:40:33 2005 EDT Modified files: /php-src NEWS /php-src/ext/pgsql pgsql.c php_pgsql.h Log: Added pg_fetch_all_columns() function to fetch all values of a column from a result cursor. http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1987r2=1.1988ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1987 php-src/NEWS:1.1988 --- php-src/NEWS:1.1987 Thu Jul 7 12:07:08 2005 +++ php-src/NEWSThu Jul 7 20:40:32 2005 @@ -5,6 +5,8 @@ - Added PDO_MYSQL_ATTR_USE_BUFFERED_QUERY parameter for pdo_mysql. (Ilia) - Added date_timezone_set() function to set the timezone that the date functions will use. (Derick) +- Added pg_fetch_all_columns() function to fetch all values of a column from + a result cursor. (Ilia) - Implemented feature request #33452 (Year belonging to ISO week). (Derick) - Fixed support for shared extensions on AIX. (Dmitry) - Fixed memory corruption in pg_copy_from() in case the as_null parameter was http://cvs.php.net/diff.php/php-src/ext/pgsql/pgsql.c?r1=1.329r2=1.330ty=u Index: php-src/ext/pgsql/pgsql.c diff -u php-src/ext/pgsql/pgsql.c:1.329 php-src/ext/pgsql/pgsql.c:1.330 --- php-src/ext/pgsql/pgsql.c:1.329 Tue Jul 5 10:49:22 2005 +++ php-src/ext/pgsql/pgsql.c Thu Jul 7 20:40:32 2005 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: pgsql.c,v 1.329 2005/07/05 14:49:22 edink Exp $ */ +/* $Id: pgsql.c,v 1.330 2005/07/08 00:40:32 iliaa Exp $ */ #include stdlib.h @@ -127,6 +127,7 @@ PHP_FE(pg_fetch_array, NULL) PHP_FE(pg_fetch_object, NULL) PHP_FE(pg_fetch_all,NULL) + PHP_FE(pg_fetch_all_columns,NULL) #if HAVE_PQCMDTUPLES PHP_FE(pg_affected_rows,NULL) #endif @@ -2101,6 +2102,47 @@ } /* }}} */ +/* {{{ proto array pg_fetch_all_columns(resource result [, int column_number]) + Fetch all rows into array */ +PHP_FUNCTION(pg_fetch_all_columns) +{ + zval *result; + PGresult *pgsql_result; + pgsql_result_handle *pg_result; + long colno=0; + int pg_numrows, pg_row; + size_t num_fields; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r|l, result, colno) == FAILURE) { + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, result, -1, PostgreSQL result, le_result); + + pgsql_result = pg_result-result; + + num_fields = PQnfields(pgsql_result); + if (colno = num_fields || colno 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Invalid column number '%ld', colno); + RETURN_FALSE; + } + + array_init(return_value); + +if ((pg_numrows = PQntuples(pgsql_result)) = 0) { + return; + } + + for (pg_row = 0; pg_row pg_numrows; pg_row++) { + if (PQgetisnull(pgsql_result, pg_row, colno)) { + add_next_index_null(return_value); + } else { + add_next_index_string(return_value, PQgetvalue(pgsql_result, pg_row, colno), 1); + } + } +} +/* }}} */ + /* {{{ proto bool pg_result_seek(resource result, int offset) Set internal row offset */ PHP_FUNCTION(pg_result_seek) http://cvs.php.net/diff.php/php-src/ext/pgsql/php_pgsql.h?r1=1.71r2=1.72ty=u Index: php-src/ext/pgsql/php_pgsql.h diff -u php-src/ext/pgsql/php_pgsql.h:1.71 php-src/ext/pgsql/php_pgsql.h:1.72 --- php-src/ext/pgsql/php_pgsql.h:1.71 Wed Apr 13 17:48:33 2005 +++ php-src/ext/pgsql/php_pgsql.h Thu Jul 7 20:40:32 2005 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: php_pgsql.h,v 1.71 2005/04/13 21:48:33 derick Exp $ */ +/* $Id: php_pgsql.h,v 1.72 2005/07/08 00:40:32 iliaa Exp $ */ #ifndef PHP_PGSQL_H #define PHP_PGSQL_H @@ -107,6 +107,7 @@ PHP_FUNCTION(pg_fetch_result); PHP_FUNCTION(pg_fetch_row); PHP_FUNCTION(pg_fetch_all); +PHP_FUNCTION(pg_fetch_all_columns); #if HAVE_PQCMDTUPLES PHP_FUNCTION(pg_affected_rows); #endif -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src / NEWS /ext/pgsql pgsql.c php_pgsql.h
Docs? Ilia Alshanetsky wrote: iliaa Thu Jul 7 20:40:33 2005 EDT Modified files: /php-src NEWS /php-src/ext/pgsql pgsql.c php_pgsql.h Log: Added pg_fetch_all_columns() function to fetch all values of a column from a result cursor. http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1987r2=1.1988ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1987 php-src/NEWS:1.1988 --- php-src/NEWS:1.1987 Thu Jul 7 12:07:08 2005 +++ php-src/NEWSThu Jul 7 20:40:32 2005 @@ -5,6 +5,8 @@ - Added PDO_MYSQL_ATTR_USE_BUFFERED_QUERY parameter for pdo_mysql. (Ilia) - Added date_timezone_set() function to set the timezone that the date functions will use. (Derick) +- Added pg_fetch_all_columns() function to fetch all values of a column from + a result cursor. (Ilia) - Implemented feature request #33452 (Year belonging to ISO week). (Derick) - Fixed support for shared extensions on AIX. (Dmitry) - Fixed memory corruption in pg_copy_from() in case the as_null parameter was http://cvs.php.net/diff.php/php-src/ext/pgsql/pgsql.c?r1=1.329r2=1.330ty=u Index: php-src/ext/pgsql/pgsql.c diff -u php-src/ext/pgsql/pgsql.c:1.329 php-src/ext/pgsql/pgsql.c:1.330 --- php-src/ext/pgsql/pgsql.c:1.329 Tue Jul 5 10:49:22 2005 +++ php-src/ext/pgsql/pgsql.c Thu Jul 7 20:40:32 2005 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: pgsql.c,v 1.329 2005/07/05 14:49:22 edink Exp $ */ +/* $Id: pgsql.c,v 1.330 2005/07/08 00:40:32 iliaa Exp $ */ #include stdlib.h @@ -127,6 +127,7 @@ PHP_FE(pg_fetch_array, NULL) PHP_FE(pg_fetch_object, NULL) PHP_FE(pg_fetch_all,NULL) + PHP_FE(pg_fetch_all_columns,NULL) #if HAVE_PQCMDTUPLES PHP_FE(pg_affected_rows,NULL) #endif @@ -2101,6 +2102,47 @@ } /* }}} */ +/* {{{ proto array pg_fetch_all_columns(resource result [, int column_number]) + Fetch all rows into array */ +PHP_FUNCTION(pg_fetch_all_columns) +{ + zval *result; + PGresult *pgsql_result; + pgsql_result_handle *pg_result; + long colno=0; + int pg_numrows, pg_row; + size_t num_fields; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r|l, result, colno) == FAILURE) { + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, result, -1, PostgreSQL result, le_result); + + pgsql_result = pg_result-result; + + num_fields = PQnfields(pgsql_result); + if (colno = num_fields || colno 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Invalid column number '%ld', colno); + RETURN_FALSE; + } + + array_init(return_value); + +if ((pg_numrows = PQntuples(pgsql_result)) = 0) { + return; + } + + for (pg_row = 0; pg_row pg_numrows; pg_row++) { + if (PQgetisnull(pgsql_result, pg_row, colno)) { + add_next_index_null(return_value); + } else { + add_next_index_string(return_value, PQgetvalue(pgsql_result, pg_row, colno), 1); + } + } +} +/* }}} */ + /* {{{ proto bool pg_result_seek(resource result, int offset) Set internal row offset */ PHP_FUNCTION(pg_result_seek) http://cvs.php.net/diff.php/php-src/ext/pgsql/php_pgsql.h?r1=1.71r2=1.72ty=u Index: php-src/ext/pgsql/php_pgsql.h diff -u php-src/ext/pgsql/php_pgsql.h:1.71 php-src/ext/pgsql/php_pgsql.h:1.72 --- php-src/ext/pgsql/php_pgsql.h:1.71 Wed Apr 13 17:48:33 2005 +++ php-src/ext/pgsql/php_pgsql.h Thu Jul 7 20:40:32 2005 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: php_pgsql.h,v 1.71 2005/04/13 21:48:33 derick Exp $ */ +/* $Id: php_pgsql.h,v 1.72 2005/07/08 00:40:32 iliaa Exp $ */ #ifndef PHP_PGSQL_H #define PHP_PGSQL_H @@ -107,6 +107,7 @@ PHP_FUNCTION(pg_fetch_result); PHP_FUNCTION(pg_fetch_row); PHP_FUNCTION(pg_fetch_all); +PHP_FUNCTION(pg_fetch_all_columns); #if HAVE_PQCMDTUPLES PHP_FUNCTION(pg_affected_rows); #endif -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/pdo_pgsql pgsql_driver.c
It is malloc + PQescapeString + free, which in most cases are completely unnecessary. While as Christopher demonstrates sequence name could contain special chars, I'd wager that is a VERY uncommon situation. Uncommon is totally irrelevant. Stable, robust code is what is. What is this - the Cross your fingers and hope it works programming language?? Chris -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/pdo_pgsql config.m4 pgsql_driver.c
Thanks - I think that's the best solution. Chris Ilia Alshanetsky wrote: iliaa Thu Jul 7 09:35:41 2005 EDT Modified files: /php-src/ext/pdo_pgsql config.m4 pgsql_driver.c Log: Use PQexecParams() when available, use original case in all other instances. http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/config.m4?r1=1.10r2=1.11ty=u Index: php-src/ext/pdo_pgsql/config.m4 diff -u php-src/ext/pdo_pgsql/config.m4:1.10 php-src/ext/pdo_pgsql/config.m4:1.11 --- php-src/ext/pdo_pgsql/config.m4:1.10Mon Jun 13 20:00:53 2005 +++ php-src/ext/pdo_pgsql/config.m4 Thu Jul 7 09:35:39 2005 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.10 2005/06/14 00:00:53 sniper Exp $ +dnl $Id: config.m4,v 1.11 2005/07/07 13:35:39 iliaa Exp $ dnl if test $PHP_PDO != no; then @@ -90,6 +90,7 @@ AC_CHECK_LIB(pq, PQprotocolVersion,AC_DEFINE(HAVE_PQPROTOCOLVERSION,1,[PostgreSQL 7.4 or later])) AC_CHECK_LIB(pq, PQtransactionStatus,AC_DEFINE(HAVE_PGTRANSACTIONSTATUS,1,[PostgreSQL 7.4 or later])) AC_CHECK_LIB(pq, PQunescapeBytea,AC_DEFINE(HAVE_PQUNESCAPEBYTEA,1,[PostgreSQL 7.4 or later])) + AC_CHECK_LIB(pq, PQExecParams,AC_DEFINE(HAVE_PQEXECPARAMS,1,[PostgreSQL 7.4 or later])) AC_CHECK_LIB(pq, PQresultErrorField,AC_DEFINE(HAVE_PQRESULTERRORFIELD,1,[PostgreSQL 7.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])) LIBS=$old_LIBS http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pgsql_driver.c?r1=1.48r2=1.49ty=u Index: php-src/ext/pdo_pgsql/pgsql_driver.c diff -u php-src/ext/pdo_pgsql/pgsql_driver.c:1.48 php-src/ext/pdo_pgsql/pgsql_driver.c:1.49 --- php-src/ext/pdo_pgsql/pgsql_driver.c:1.48 Wed Jul 6 22:17:20 2005 +++ php-src/ext/pdo_pgsql/pgsql_driver.cThu Jul 7 09:35:39 2005 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: pgsql_driver.c,v 1.48 2005/07/07 02:17:20 iliaa Exp $ */ +/* $Id: pgsql_driver.c,v 1.49 2005/07/07 13:35:39 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -210,12 +210,22 @@ *len = spprintf(id, 0, %ld, (long) H-pgoid); } else { PGresult *res; - char *q; ExecStatusType status; - - spprintf(q, sizeof(SELECT CURRVAL('')) + strlen(name), SELECT CURRVAL('%s'), name); +#ifdef HAVE_PQEXECPARAMS + const char *q[1]; + q[0] = name; + res = PQexecParams(H-server, SELECT CURRVAL($1), 1, NULL, q, NULL, NULL, 0); +#else + char *name_escaped, *q; + size_t l = strlen(name); + + name_escaped = safe_emalloc(l, 2, 1); + PQescapeString(name_escaped, name, l); + spprintf(q, 0, SELECT CURRVAL('%s'), name_escaped); res = PQexec(H-server, q); + efree(name_escaped); efree(q); +#endif status = PQresultStatus(res); if (res (status == PGRES_TUPLES_OK)) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/pdo pdo_stmt.c
Wez Furlong wrote: wez Thu Jul 7 08:45:41 2005 EDT Modified files: /php-src/ext/pdo pdo_stmt.c Log: Fix bug in bindColumn() for drivers that implement native prepared statements and that use the PDO rewriter to handle non-native parameter syntax. Is there any chance we can get native prepared statements in pdo_pgsql? What's involved? Chris -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/pdo pdo_stmt.c
Pointing me at some good documentation for it would help; I find the postgres site really difficult to extract information from. I've looked on two occasions but got fed up with lack of info. Interesting. I find the PostgreSQL manual elegant, simple and orthogonal and I find the MySQL one a total cross-version jumbled mess :) This is the URL you want: http://www.postgresql.org/docs/8.0/interactive/libpq-exec.html#LIBPQ-EXEC-MAIN You can use the PQprepare/PQexecPrepared combo to have separated prepare and execute steps. Or, you can use PQexecParams to simple execute a statement with separate parameters. If you can show me some C code that does it, I'll install postgres and hack up something to make it work. Just look at php-src/ext/pgsql/pgsql.c. Find the pg_prepare, pg_execute and pg_query_params function implementations. The basic thing in PostgreSQL is that it uses positional parameters: $1, $2, $3 instead of ?, ?, ? or :var1, :var2, :var3. Chris -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/pdo_pgsql pgsql_driver.c
Leave it up to the user to decide if to escape the sequence name or not. What was wrong with the original coding? Can't you juse leave teh PQescapeString in there? Chris http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pgsql_driver.c?r1=1.47r2=1.48ty=u Index: php-src/ext/pdo_pgsql/pgsql_driver.c diff -u php-src/ext/pdo_pgsql/pgsql_driver.c:1.47 php-src/ext/pdo_pgsql/pgsql_driver.c:1.48 --- php-src/ext/pdo_pgsql/pgsql_driver.c:1.47 Wed Jul 6 20:52:19 2005 +++ php-src/ext/pdo_pgsql/pgsql_driver.cWed Jul 6 22:17:20 2005 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: pgsql_driver.c,v 1.47 2005/07/07 00:52:19 iliaa Exp $ */ +/* $Id: pgsql_driver.c,v 1.48 2005/07/07 02:17:20 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -213,11 +213,6 @@ char *q; ExecStatusType status; - /* SQL injection protection */ - if (strchr(name, '\'')) { - return NULL; - } - spprintf(q, sizeof(SELECT CURRVAL('')) + strlen(name), SELECT CURRVAL('%s'), name); res = PQexec(H-server, q); efree(q); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/pdo_pgsql pgsql_driver.c
By the way, using PQexecParams is by far the easiest fastest and safest way of doing this... Chris Ilia Alshanetsky wrote: iliaa Wed Jul 6 22:17:21 2005 EDT Modified files: /php-src/ext/pdo_pgsql pgsql_driver.c Log: Leave it up to the user to decide if to escape the sequence name or not. http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pgsql_driver.c?r1=1.47r2=1.48ty=u Index: php-src/ext/pdo_pgsql/pgsql_driver.c diff -u php-src/ext/pdo_pgsql/pgsql_driver.c:1.47 php-src/ext/pdo_pgsql/pgsql_driver.c:1.48 --- php-src/ext/pdo_pgsql/pgsql_driver.c:1.47 Wed Jul 6 20:52:19 2005 +++ php-src/ext/pdo_pgsql/pgsql_driver.cWed Jul 6 22:17:20 2005 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: pgsql_driver.c,v 1.47 2005/07/07 00:52:19 iliaa Exp $ */ +/* $Id: pgsql_driver.c,v 1.48 2005/07/07 02:17:20 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -213,11 +213,6 @@ char *q; ExecStatusType status; - /* SQL injection protection */ - if (strchr(name, '\'')) { - return NULL; - } - spprintf(q, sizeof(SELECT CURRVAL('')) + strlen(name), SELECT CURRVAL('%s'), name); res = PQexec(H-server, q); efree(q); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/pdo_pgsql pgsql_driver.c
I don't get this at all? How come you reject sequences that contain apostrophes? Chris Ilia Alshanetsky wrote: iliaa Wed Jul 6 20:52:20 2005 EDT Modified files: /php-src/ext/pdo_pgsql pgsql_driver.c Log: Faster sequence id retrieval. http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pgsql_driver.c?r1=1.46r2=1.47ty=u Index: php-src/ext/pdo_pgsql/pgsql_driver.c diff -u php-src/ext/pdo_pgsql/pgsql_driver.c:1.46 php-src/ext/pdo_pgsql/pgsql_driver.c:1.47 --- php-src/ext/pdo_pgsql/pgsql_driver.c:1.46 Fri Jul 1 18:43:16 2005 +++ php-src/ext/pdo_pgsql/pgsql_driver.cWed Jul 6 20:52:19 2005 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: pgsql_driver.c,v 1.46 2005/07/01 22:43:16 edink Exp $ */ +/* $Id: pgsql_driver.c,v 1.47 2005/07/07 00:52:19 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -210,15 +210,16 @@ *len = spprintf(id, 0, %ld, (long) H-pgoid); } else { PGresult *res; - char *name_escaped, *q; - size_t l = strlen(name); + char *q; ExecStatusType status; - name_escaped = safe_emalloc(l, 2, 1); - PQescapeString(name_escaped, name, l); - spprintf(q, 0, SELECT CURRVAL('%s'), name_escaped); + /* SQL injection protection */ + if (strchr(name, '\'')) { + return NULL; + } + + spprintf(q, sizeof(SELECT CURRVAL('')) + strlen(name), SELECT CURRVAL('%s'), name); res = PQexec(H-server, q); - efree(name_escaped); efree(q); status = PQresultStatus(res); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/pdo_pgsql pgsql_driver.c
Have you ever tried creating a sequence with an apostrophes in its name in PostgreSQL? Easily, and don't forget about schema qualification either: test=# create sequence isn't this grand?; CREATE SEQUENCE test=# \ds List of relations Schema |Name | Type | Owner +-+--+- public | isn't this grand? | sequence | chriskl (1 row) test=# select nextval('isn''t this grand?'); nextval - 1 (1 row) test=# select currval('isn''t this grand?'); currval - 1 (1 row) test=# select currval('public.isn''t this grand?'); currval - 1 (1 row) Chris -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src /ext/pdo_pgsql pgsql_driver.c
It does impose a v7.4 and above libpq requirement, however. Chris Andi Gutmans wrote: Yeah, definitely seems like PQexecParams is the safest and easiest way of doing so. In general, I'm always in favor of using bound parameters exactly for this reason. Andi At 10:44 AM 7/7/2005 +0800, Christopher Kings-Lynne wrote: By the way, using PQexecParams is by far the easiest fastest and safest way of doing this... Chris Ilia Alshanetsky wrote: iliaa Wed Jul 6 22:17:21 2005 EDT Modified files: /php-src/ext/pdo_pgsql pgsql_driver.c Log: Leave it up to the user to decide if to escape the sequence name or not. http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pgsql_driver.c?r1=1.47r2=1.48ty=u Index: php-src/ext/pdo_pgsql/pgsql_driver.c diff -u php-src/ext/pdo_pgsql/pgsql_driver.c:1.47 php-src/ext/pdo_pgsql/pgsql_driver.c:1.48 --- php-src/ext/pdo_pgsql/pgsql_driver.c:1.47 Wed Jul 6 20:52:19 2005 +++ php-src/ext/pdo_pgsql/pgsql_driver.cWed Jul 6 22:17:20 2005 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: pgsql_driver.c,v 1.47 2005/07/07 00:52:19 iliaa Exp $ */ +/* $Id: pgsql_driver.c,v 1.48 2005/07/07 02:17:20 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -213,11 +213,6 @@ char *q; ExecStatusType status; - /* SQL injection protection */ - if (strchr(name, '\'')) { - return NULL; - } - spprintf(q, sizeof(SELECT CURRVAL('')) + strlen(name), SELECT CURRVAL('%s'), name); res = PQexec(H-server, q); efree(q); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php-src / NEWS /ext/pgsql config.m4 config.w32 pgsql.c /ext/pgsql/tests 08escape.phpt 25async_query_params.phpt
This is needed on windows when you link dynamic libpq (dll). We link libpq statically into the php extension so we have no such problems. So you don't need to give windows build any special consideration. Hmmm, well I get memory leaks if I change it :( Is it because PQunescapeBytea returns a string that was not allocated using emalloc? In which case, PHP automatically tries to efree() it, resulting in a miscount? What can I do about this? Chris -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src / NEWS /ext/pgsql config.m4 config.w32 pgsql.c /ext/pgsql/tests 08escape.phpt 25async_query_params.phpt
chriskl Fri Mar 25 01:26:31 2005 EDT Modified files: /php-srcNEWS /php-src/ext/pgsql config.m4 config.w32 pgsql.c /php-src/ext/pgsql/tests08escape.phpt 25async_query_params.phpt Log: (PHP pg_unescape_bytea) Use libpq version of PQunescapeBytea if it exists. # The version in libpq is newer and faster than the one in PHP, but it is # necessary for me to add a string copy for freeing purposes. This copy # is only needed in Windows AFAIK, how can I detect that? http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1858r2=1.1859ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1858 php-src/NEWS:1.1859 --- php-src/NEWS:1.1858 Tue Mar 22 19:37:34 2005 +++ php-src/NEWSFri Mar 25 01:26:30 2005 @@ -1,6 +1,8 @@ PHPNEWS ||| ?? ??? 2004, PHP 5.1.0 +- Changed pg_unescape_bytea() to use the libpq version of PQunescapeBytea if + it is available. - Moved extensions to PECL: . ext/cpdf(Tony, Derick) . ext/dio (Jani, Derick) http://cvs.php.net/diff.php/php-src/ext/pgsql/config.m4?r1=1.41r2=1.42ty=u Index: php-src/ext/pgsql/config.m4 diff -u php-src/ext/pgsql/config.m4:1.41 php-src/ext/pgsql/config.m4:1.42 --- php-src/ext/pgsql/config.m4:1.41Tue Mar 22 03:51:21 2005 +++ php-src/ext/pgsql/config.m4 Fri Mar 25 01:26:30 2005 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.41 2005/03/22 08:51:21 chriskl Exp $ +dnl $Id: config.m4,v 1.42 2005/03/25 06:26:30 chriskl Exp $ dnl AC_DEFUN([PHP_PGSQL_CHECK_FUNCTIONS],[ @@ -69,6 +69,7 @@ old_LDFLAGS=$LDFLAGS LDFLAGS=$LDFLAGS -L$PGSQL_LIBDIR AC_CHECK_LIB(pq, PQescapeString,AC_DEFINE(HAVE_PQESCAPE,1,[PostgreSQL 7.2.0 or later])) + AC_CHECK_LIB(pq, PQunescapeBytea,AC_DEFINE(HAVE_PQUNESCAPEBYTEA,1,[PostgreSQL 7.3.0 or later])) AC_CHECK_LIB(pq, PQsetnonblocking,AC_DEFINE(HAVE_PQSETNONBLOCKING,1,[PostgreSQL 7.0.x or later])) AC_CHECK_LIB(pq, PQcmdTuples,AC_DEFINE(HAVE_PQCMDTUPLES,1,[Broken libpq under windows])) AC_CHECK_LIB(pq, PQoidValue,AC_DEFINE(HAVE_PQOIDVALUE,1,[Older PostgreSQL])) http://cvs.php.net/diff.php/php-src/ext/pgsql/config.w32?r1=1.5r2=1.6ty=u Index: php-src/ext/pgsql/config.w32 diff -u php-src/ext/pgsql/config.w32:1.5 php-src/ext/pgsql/config.w32:1.6 --- php-src/ext/pgsql/config.w32:1.5Tue Mar 22 03:51:21 2005 +++ php-src/ext/pgsql/config.w32Fri Mar 25 01:26:30 2005 @@ -1,4 +1,4 @@ -// $Id: config.w32,v 1.5 2005/03/22 08:51:21 chriskl Exp $ +// $Id: config.w32,v 1.6 2005/03/25 06:26:30 chriskl Exp $ // vim:ft=javascript ARG_WITH(pgsql, PostgreSQL support, no); @@ -8,7 +8,7 @@ CHECK_HEADER_ADD_INCLUDE(libpq-fe.h, CFLAGS_PGSQL, PHP_PHP_BUILD + \\include\\pgsql; + PHP_PGSQL)) { EXTENSION(pgsql, pgsql.c); AC_DEFINE('HAVE_PGSQL', 1, 'Have PostgreSQL library'); - ADD_FLAG(CFLAGS_PGSQL, /D HAVE_PG_CONFIG_H /D PGSQL_EXPORTS /D HAVE_PQSETNONBLOCKING /D HAVE_PQCMDTUPLES /D HAVE_PQCLIENTENCODING /D HAVE_PQESCAPE /D HAVE_PQPARAMETERSTATUS /D HAVE_PGTRANSACTIONSTATUS /D HAVE_PQEXECPARAMS /D HAVE_PQPREPARE /D HAVE_PQEXECPREPARED /D HAVE_PQRESULTERRORFIELD /D HAVE_PQSENDQUERYPARAMS /D HAVE_PQSENDPREPARE /D HAVE_PQSENDQUERYPREPARED /D HAVE_PQPUTCOPYDATA /D HAVE_PQPUTCOPYEND /D HAVE_PQGETCOPYDATA /D HAVE_PQSETERRORVERBOSITY); + ADD_FLAG(CFLAGS_PGSQL, /D HAVE_PG_CONFIG_H /D PGSQL_EXPORTS /D HAVE_PQSETNONBLOCKING /D HAVE_PQCMDTUPLES /D HAVE_PQCLIENTENCODING /D HAVE_PQESCAPE /D HAVE_PQPARAMETERSTATUS /D HAVE_PGTRANSACTIONSTATUS /D HAVE_PQEXECPARAMS /D HAVE_PQPREPARE /D HAVE_PQEXECPREPARED /D HAVE_PQRESULTERRORFIELD /D HAVE_PQSENDQUERYPARAMS /D HAVE_PQSENDPREPARE /D HAVE_PQSENDQUERYPREPARED /D HAVE_PQPUTCOPYDATA /D HAVE_PQPUTCOPYEND /D HAVE_PQGETCOPYDATA /D HAVE_PQSETERRORVERBOSITY /D HAVE_PQUNESCAPEBYTEA); } else { WARNING(pgsql not enabled; libraries and headers not found); } http://cvs.php.net/diff.php/php-src/ext/pgsql/pgsql.c?r1=1.321r2=1.322ty=u Index: php-src/ext/pgsql/pgsql.c diff -u php-src/ext/pgsql/pgsql.c:1.321 php-src/ext/pgsql/pgsql.c:1.322 --- php-src/ext/pgsql/pgsql.c:1.321 Thu Mar 24 19:30:43 2005 +++ php-src/ext/pgsql/pgsql.c Fri Mar 25 01:26:30 2005 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: pgsql.c,v 1.321 2005/03/25 00:30:43 iliaa Exp $ */ +/* $Id: pgsql.c,v 1.322 2005/03/25 06:26:30 chriskl Exp $ */ #include stdlib.h @@ -3414,6 +3414,7 @@ } /* }}} */ +#if !HAVE_PQUNESCAPEBYTEA /* PQunescapeBytea() from PostgreSQL 7.3 to provide bytea unescape feature to 7.2 users. Renamed to php_pgsql_unescape_bytea() */ /* @@ -3517,12 +3518,13 @@ *retbuflen = buflen; return buffer; } +#endif /* {{{ proto string pg_unescape_bytea(string data) Unescape binary for bytea type */
[PHP-CVS] cvs: php-src /ext/pdo_pgsql pgsql_statement.c
chriskl Wed Mar 23 03:52:41 2005 EDT Modified files: /php-src/ext/pdo_pgsql pgsql_statement.c Log: - Use a replacement for PQunescapeBytea so that linking against a pre-7.3 libpq is possible. This is exactly what ext/pgsql currently does. # I hope this is an acceptable improvement. http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pgsql_statement.c?r1=1.19r2=1.20ty=u Index: php-src/ext/pdo_pgsql/pgsql_statement.c diff -u php-src/ext/pdo_pgsql/pgsql_statement.c:1.19 php-src/ext/pdo_pgsql/pgsql_statement.c:1.20 --- php-src/ext/pdo_pgsql/pgsql_statement.c:1.19Thu Mar 10 13:48:00 2005 +++ php-src/ext/pdo_pgsql/pgsql_statement.c Wed Mar 23 03:52:40 2005 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: pgsql_statement.c,v 1.19 2005/03/10 18:48:00 helly Exp $ */ +/* $Id: pgsql_statement.c,v 1.20 2005/03/23 08:52:40 chriskl Exp $ */ #ifdef HAVE_CONFIG_H #include config.h @@ -208,6 +208,110 @@ return 1; } +/* PQunescapeBytea() from PostgreSQL 7.3 to provide bytea unescape feature to 7.2 users. + Renamed to php_pgsql_unescape_bytea() */ +/* + * PQunescapeBytea - converts the null terminated string representation + * of a bytea, strtext, into binary, filling a buffer. It returns a + * pointer to the buffer which is NULL on error, and the size of the + * buffer in retbuflen. The pointer may subsequently be used as an + * argument to the function free(3). It is the reverse of PQescapeBytea. + * + * The following transformations are reversed: + * '\0' == ASCII 0 == \000 + * '\'' == ASCII 39 == \' + * '\\' == ASCII 92 == \\ + * + * States: + * 0 normal 0-1-2-3-4 + * 1 \ 1-5 + * 2 \0 1-6 + * 3 \00 + * 4 \000 + * 5 \' + * 6 \\ + */ +static unsigned char * php_pgsql_unescape_bytea(unsigned char *strtext, size_t *retbuflen) +{ + size_t buflen; + unsigned char *buffer, + *sp, + *bp; + unsigned int state = 0; + + if (strtext == NULL) + return NULL; + buflen = strlen(strtext); /* will shrink, also we discover if +* strtext */ + buffer = (unsigned char *) emalloc(buflen); /* isn't NULL terminated */ + for (bp = buffer, sp = strtext; *sp != '\0'; bp++, sp++) + { + switch (state) + { + case 0: + if (*sp == '\\') + state = 1; + *bp = *sp; + break; + case 1: + if (*sp == '\'')/* state=5 */ + { /* replace \' with 39 */ + bp--; + *bp = '\''; + buflen--; + state = 0; + } + else if (*sp == '\\') /* state=6 */ + { /* replace \\ with 92 */ + bp--; + *bp = '\\'; + buflen--; + state = 0; + } + else + { + if (isdigit(*sp)) + state = 2; + else + state = 0; + *bp = *sp; + } + break; + case 2: + if (isdigit(*sp)) + state = 3; + else + state = 0; + *bp = *sp; + break; + case 3: + if (isdigit(*sp)) /* state=4 */ + { + unsigned char *start, *end, buf[4]; /* 000 + '\0' */ + + bp -= 3; + memcpy(buf, sp-2, 3); + buf[3] = '\0'; +
Re: [PHP-CVS] cvs: php-src /ext/pdo_pgsql pgsql_statement.c
Modified files: /php-src/ext/pdo_pgsql pgsql_statement.c Log: - Use a replacement for PQunescapeBytea so that linking against a pre-7.3 libpq is possible. This is exactly what ext/pgsql currently does. # I hope this is an acceptable improvement. Wouldn't it be better to only use this when it's really needed? Yes, I came to the same conclusion. I've got a commit to do that for ext/pgsql and i'll commit it to pdo_pgsql too (tomorrow). Chris -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src / NEWS /ext/pgsql CREDITS config.m4 config.w32 pgsql.c php_pgsql.h /ext/pgsql/tests 06copy.phpt 07optional.phpt
chriskl Tue Mar 22 03:51:24 2005 EDT Modified files: /php-srcNEWS /php-src/ext/pgsql CREDITS config.m4 config.w32 pgsql.c php_pgsql.h /php-src/ext/pgsql/tests06copy.phpt 07optional.phpt Log: Tweak some #if's to be more orthogonal. (PHP pg_set_error_verbosity) New function to set PostgreSQL error verbosity (PHP pg_copy_from) Use non-deprecated API if it is available (PHP pg_copy_to) Use non-deprecated API if it is available http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1856r2=1.1857ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1856 php-src/NEWS:1.1857 --- php-src/NEWS:1.1856 Sat Mar 19 09:37:09 2005 +++ php-src/NEWSTue Mar 22 03:51:19 2005 @@ -8,6 +8,8 @@ . ext/mnogosearch (Jani, Derick) . ext/w32api (Jani, Derick) . ext/yp (Jani, Derick) +- Updated pg_copy_from and pg_copy_to to use non-deprecated COPY API if + it exists (Christopher) - Changed stream_filter_(ap|pre)pend() to return resource. (Sara) - Changed mysqli_exception and sqlite_exception to use RuntimeException as base if SPL extension is present. (Georg, Marcus) @@ -39,6 +41,7 @@ . pg_send_execute() - async equivalent of pg_execute(). . pg_result_error_field() - highly detailed error information, most importantly the SQLSTATE error code. + . pg_set_error_verbosity() - set verbosity of errors - Added optional fifth parameter count to preg_replace_callback() and preg_replace() to count the number of replacements made. FR #32275. (Andrey) - Added optional third parameter charlist to str_word_count() which http://cvs.php.net/diff.php/php-src/ext/pgsql/CREDITS?r1=1.2r2=1.3ty=u Index: php-src/ext/pgsql/CREDITS diff -u php-src/ext/pgsql/CREDITS:1.2 php-src/ext/pgsql/CREDITS:1.3 --- php-src/ext/pgsql/CREDITS:1.2 Tue Dec 11 02:44:46 2001 +++ php-src/ext/pgsql/CREDITS Tue Mar 22 03:51:21 2005 @@ -1,2 +1,2 @@ PostgreSQL -Jouni Ahto, Zeev Suraski, Yasuo Ohgaki +Jouni Ahto, Zeev Suraski, Yasuo Ohgaki, Chris Kings-Lynne http://cvs.php.net/diff.php/php-src/ext/pgsql/config.m4?r1=1.40r2=1.41ty=u Index: php-src/ext/pgsql/config.m4 diff -u php-src/ext/pgsql/config.m4:1.40 php-src/ext/pgsql/config.m4:1.41 --- php-src/ext/pgsql/config.m4:1.40Sat Mar 19 03:46:55 2005 +++ php-src/ext/pgsql/config.m4 Tue Mar 22 03:51:21 2005 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.40 2005/03/19 08:46:55 chriskl Exp $ +dnl $Id: config.m4,v 1.41 2005/03/22 08:51:21 chriskl Exp $ dnl AC_DEFUN([PHP_PGSQL_CHECK_FUNCTIONS],[ @@ -83,6 +83,10 @@ AC_CHECK_LIB(pq, PQsendQueryParams,AC_DEFINE(HAVE_PQSENDQUERYPARAMS,1,[PostgreSQL 7.4 or later])) AC_CHECK_LIB(pq, PQsendPrepare,AC_DEFINE(HAVE_PQSENDPREPARE,1,[PostgreSQL 7.4 or later])) AC_CHECK_LIB(pq, PQsendQueryPrepared,AC_DEFINE(HAVE_PQSENDQUERYPREPARED,1,[PostgreSQL 7.4 or later])) + AC_CHECK_LIB(pq, PQputCopyData,AC_DEFINE(HAVE_PQPUTCOPYDATA,1,[PostgreSQL 7.4 or later])) + AC_CHECK_LIB(pq, PQputCopyEnd,AC_DEFINE(HAVE_PQPUTCOPYEND,1,[PostgreSQL 7.4 or later])) + AC_CHECK_LIB(pq, PQgetCopyData,AC_DEFINE(HAVE_PQGETCOPYDATA,1,[PostgreSQL 7.4 or later])) + AC_CHECK_LIB(pq, PQsetErrorVerbosity,AC_DEFINE(HAVE_PQSETERRORVERBOSITY,1,[PostgreSQL 7.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-multibye])) LIBS=$old_LIBS LDFLAGS=$old_LDFLAGS http://cvs.php.net/diff.php/php-src/ext/pgsql/config.w32?r1=1.4r2=1.5ty=u Index: php-src/ext/pgsql/config.w32 diff -u php-src/ext/pgsql/config.w32:1.4 php-src/ext/pgsql/config.w32:1.5 --- php-src/ext/pgsql/config.w32:1.4Sat Mar 19 03:46:55 2005 +++ php-src/ext/pgsql/config.w32Tue Mar 22 03:51:21 2005 @@ -1,4 +1,4 @@ -// $Id: config.w32,v 1.4 2005/03/19 08:46:55 chriskl Exp $ +// $Id: config.w32,v 1.5 2005/03/22 08:51:21 chriskl Exp $ // vim:ft=javascript ARG_WITH(pgsql, PostgreSQL support, no); @@ -8,7 +8,7 @@ CHECK_HEADER_ADD_INCLUDE(libpq-fe.h, CFLAGS_PGSQL, PHP_PHP_BUILD + \\include\\pgsql; + PHP_PGSQL)) { EXTENSION(pgsql, pgsql.c); AC_DEFINE('HAVE_PGSQL', 1, 'Have PostgreSQL library'); - ADD_FLAG(CFLAGS_PGSQL, /D HAVE_PG_CONFIG_H /D PGSQL_EXPORTS /D HAVE_PQSETNONBLOCKING /D HAVE_PQCMDTUPLES /D HAVE_PQCLIENTENCODING /D HAVE_PQESCAPE /D HAVE_PQPARAMETERSTATUS /D HAVE_PGTRANSACTIONSTATUS /D HAVE_PQEXECPARAMS /D HAVE_PQPREPARE /D HAVE_PQEXECPREPARED /D HAVE_PQRESULTERRORFIELD /D HAVE_PQSENDQUERYPARAMS /D HAVE_PQSENDPREPARE /D HAVE_PQSENDQUERYPREPARED ); + ADD_FLAG(CFLAGS_PGSQL, /D HAVE_PG_CONFIG_H /D PGSQL_EXPORTS /D HAVE_PQSETNONBLOCKING /D HAVE_PQCMDTUPLES /D HAVE_PQCLIENTENCODING /D HAVE_PQESCAPE /D HAVE_PQPARAMETERSTATUS /D HAVE_PGTRANSACTIONSTATUS /D HAVE_PQEXECPARAMS /D HAVE_PQPREPARE /D HAVE_PQEXECPREPARED /D HAVE_PQRESULTERRORFIELD /D HAVE_PQSENDQUERYPARAMS /D HAVE_PQSENDPREPARE /D HAVE_PQSENDQUERYPREPARED /D HAVE_PQPUTCOPYDATA /D
[PHP-CVS] cvs: php-src /ext/pgsql/tests 02connection.phpt 03sync_query.phpt 23sync_query_params.phpt 24sync_query_prepared.phpt 25async_query_params.phpt 26async_query_prepared.phpt
chriskl Tue Mar 22 22:24:41 2005 EDT Modified files: /php-src/ext/pgsql/tests02connection.phpt 03sync_query.phpt 23sync_query_params.phpt 24sync_query_prepared.phpt 25async_query_params.phpt 26async_query_prepared.phpt Log: - Ensure that ext/pgsql tests work when linked against 7.2 or lower libpq http://cvs.php.net/diff.php/php-src/ext/pgsql/tests/02connection.phpt?r1=1.4r2=1.5ty=u Index: php-src/ext/pgsql/tests/02connection.phpt diff -u php-src/ext/pgsql/tests/02connection.phpt:1.4 php-src/ext/pgsql/tests/02connection.phpt:1.5 --- php-src/ext/pgsql/tests/02connection.phpt:1.4 Sat Mar 19 04:20:52 2005 +++ php-src/ext/pgsql/tests/02connection.phpt Tue Mar 22 22:24:41 2005 @@ -23,9 +23,11 @@ { echo pg_connection_busy() error\n; } -if (pg_transaction_status($db) != PGSQL_TRANSACTION_IDLE) -{ - echo pg_transaction_status() error\n; +if (function_exists('pg_transaction_status')) { + if (pg_transaction_status($db) != PGSQL_TRANSACTION_IDLE) + { + echo pg_transaction_status() error\n; + } } if (!pg_host($db)) { http://cvs.php.net/diff.php/php-src/ext/pgsql/tests/03sync_query.phpt?r1=1.5r2=1.6ty=u Index: php-src/ext/pgsql/tests/03sync_query.phpt diff -u php-src/ext/pgsql/tests/03sync_query.phpt:1.5 php-src/ext/pgsql/tests/03sync_query.phpt:1.6 --- php-src/ext/pgsql/tests/03sync_query.phpt:1.5 Sat Mar 19 21:46:02 2005 +++ php-src/ext/pgsql/tests/03sync_query.phpt Tue Mar 22 22:24:41 2005 @@ -32,24 +32,26 @@ } pg_result_error($result); -pg_result_error_field($result, PGSQL_DIAG_SEVERITY); -pg_result_error_field($result, PGSQL_DIAG_SQLSTATE); -pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY); -pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL); -pg_result_error_field($result, PGSQL_DIAG_MESSAGE_HINT); -pg_result_error_field($result, PGSQL_DIAG_STATEMENT_POSITION); -if (defined('PGSQL_DIAG_INTERNAL_POSITION')) -{ - pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION); +if (function_exists('pg_result_error_field')) { + pg_result_error_field($result, PGSQL_DIAG_SEVERITY); + pg_result_error_field($result, PGSQL_DIAG_SQLSTATE); + pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY); + pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL); + pg_result_error_field($result, PGSQL_DIAG_MESSAGE_HINT); + pg_result_error_field($result, PGSQL_DIAG_STATEMENT_POSITION); + if (defined('PGSQL_DIAG_INTERNAL_POSITION')) + { + pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION); + } + if (defined('PGSQL_DIAG_INTERNAL_QUERY')) + { + pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY); + } + pg_result_error_field($result, PGSQL_DIAG_CONTEXT); + pg_result_error_field($result, PGSQL_DIAG_SOURCE_FILE); + pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE); + pg_result_error_field($result, PGSQL_DIAG_SOURCE_FUNCTION); } -if (defined('PGSQL_DIAG_INTERNAL_QUERY')) -{ - pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY); -} -pg_result_error_field($result, PGSQL_DIAG_CONTEXT); -pg_result_error_field($result, PGSQL_DIAG_SOURCE_FILE); -pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE); -pg_result_error_field($result, PGSQL_DIAG_SOURCE_FUNCTION); pg_num_rows(pg_query($db, SELECT * FROM .$table_name.;)); pg_num_fields(pg_query($db, SELECT * FROM .$table_name.;)); pg_field_name($result, 0); http://cvs.php.net/diff.php/php-src/ext/pgsql/tests/23sync_query_params.phpt?r1=1.1r2=1.2ty=u Index: php-src/ext/pgsql/tests/23sync_query_params.phpt diff -u php-src/ext/pgsql/tests/23sync_query_params.phpt:1.1 php-src/ext/pgsql/tests/23sync_query_params.phpt:1.2 --- php-src/ext/pgsql/tests/23sync_query_params.phpt:1.1Sat Mar 19 03:46:56 2005 +++ php-src/ext/pgsql/tests/23sync_query_params.phptTue Mar 22 22:24:41 2005 @@ -1,7 +1,10 @@ --TEST-- PostgreSQL sync query params --SKIPIF-- -?php include(skipif.inc); ? +?php +include(skipif.inc); +if (!function_exists('pg_query_params')) die('skip function pg_query_params() does not exist'); +? --FILE-- ?php @@ -9,42 +12,45 @@ $db = pg_connect($conn_str); -$result = pg_query_params($db, SELECT * FROM .$table_name. WHERE num \$1;, array(100)); -if (!($rows = pg_num_rows($result))) -{ - echo pg_num_row() error\n; -} -for ($i=0; $i $rows; $i++) -{ - pg_fetch_array($result, $i, PGSQL_NUM); -} -for ($i=0; $i $rows; $i++) -{ - pg_fetch_object($result); -} -for ($i=0; $i $rows; $i++) -{ - pg_fetch_row($result, $i); -} -for ($i=0; $i $rows; $i++) -{ - pg_fetch_result($result, $i, 0); -} - -pg_result_error($result); -pg_num_rows(pg_query_params($db, SELECT * FROM .$table_name. WHERE num \$1;, array(100)));
Re: [PHP-CVS] cvs: php-src(PHP_5_0) /ext/standard http_fopen_wrapper.c
hyanantha Mon Mar 21 03:46:50 2005 EDT Modified files: (Branch: PHP_5_0) /php-src/ext/standard http_fopen_wrapper.c Log: NetWare LibC headers have sys/param.h Perhaps it's a good idea to commit more than one file at a time? That makes less noise on the CVS list and makes it also easier to figure out which commits belong to each other. Also shouldn't these be committed to HEAD as well? -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/pgsql pgsql.c
chriskl Sat Mar 19 04:07:21 2005 EDT Modified files: /php-src/ext/pgsql pgsql.c Log: Minor oversight in #if for an internal function http://cvs.php.net/diff.php/php-src/ext/pgsql/pgsql.c?r1=1.315r2=1.316ty=u Index: php-src/ext/pgsql/pgsql.c diff -u php-src/ext/pgsql/pgsql.c:1.315 php-src/ext/pgsql/pgsql.c:1.316 --- php-src/ext/pgsql/pgsql.c:1.315 Sat Mar 19 03:46:55 2005 +++ php-src/ext/pgsql/pgsql.c Sat Mar 19 04:07:20 2005 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: pgsql.c,v 1.315 2005/03/19 08:46:55 chriskl Exp $ */ +/* $Id: pgsql.c,v 1.316 2005/03/19 09:07:20 chriskl Exp $ */ #include stdlib.h @@ -1144,7 +1144,7 @@ } /* }}} */ -#if HAVE_PQEXECPARAMS || HAVE_PQEXECPREPARED +#if HAVE_PQEXECPARAMS || HAVE_PQEXECPREPARED || HAVE_PQSENDQUERYPARAMS || HAVE_PQSENDQUERYPREPARED /* {{{ _php_pgsql_free_params */ static void _php_pgsql_free_params(char **params, int num_params) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/pgsql/tests 02connection.phpt 03sync_query.phpt
chriskl Sat Mar 19 04:20:53 2005 EDT Modified files: /php-src/ext/pgsql/tests02connection.phpt 03sync_query.phpt Log: Add regression tests for pg_transaction_status and pg_result_error_field http://cvs.php.net/diff.php/php-src/ext/pgsql/tests/02connection.phpt?r1=1.3r2=1.4ty=u Index: php-src/ext/pgsql/tests/02connection.phpt diff -u php-src/ext/pgsql/tests/02connection.phpt:1.3 php-src/ext/pgsql/tests/02connection.phpt:1.4 --- php-src/ext/pgsql/tests/02connection.phpt:1.3 Tue Mar 9 09:37:49 2004 +++ php-src/ext/pgsql/tests/02connection.phpt Sat Mar 19 04:20:52 2005 @@ -23,6 +23,10 @@ { echo pg_connection_busy() error\n; } +if (pg_transaction_status($db) != PGSQL_TRANSACTION_IDLE) +{ + echo pg_transaction_status() error\n; +} if (!pg_host($db)) { echo pg_host() error\n; http://cvs.php.net/diff.php/php-src/ext/pgsql/tests/03sync_query.phpt?r1=1.3r2=1.4ty=u Index: php-src/ext/pgsql/tests/03sync_query.phpt diff -u php-src/ext/pgsql/tests/03sync_query.phpt:1.3 php-src/ext/pgsql/tests/03sync_query.phpt:1.4 --- php-src/ext/pgsql/tests/03sync_query.phpt:1.3 Sat Sep 6 14:34:55 2003 +++ php-src/ext/pgsql/tests/03sync_query.phpt Sat Mar 19 04:20:52 2005 @@ -32,6 +32,18 @@ } pg_result_error($result); +pg_result_error_field($result, PGSQL_DIAG_SEVERITY); +pg_result_error_field($result, PGSQL_DIAG_SQLSTATE); +pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY); +pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL); +pg_result_error_field($result, PGSQL_DIAG_MESSAGE_HINT); +pg_result_error_field($result, PGSQL_DIAG_STATEMENT_POSITION); +pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION); +pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY); +pg_result_error_field($result, PGSQL_DIAG_CONTEXT); +pg_result_error_field($result, PGSQL_DIAG_SOURCE_FILE); +pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE); +pg_result_error_field($result, PGSQL_DIAG_SOURCE_FUNCTION); pg_num_rows(pg_query($db, SELECT * FROM .$table_name.;)); pg_num_fields(pg_query($db, SELECT * FROM .$table_name.;)); pg_field_name($result, 0); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/pgsql pgsql.c
chriskl Sat Mar 19 04:21:51 2005 EDT Modified files: /php-src/ext/pgsql pgsql.c Log: Another oversight - make sure constants related to pg_result_error_field are #if'd as well as the function itself http://cvs.php.net/diff.php/php-src/ext/pgsql/pgsql.c?r1=1.316r2=1.317ty=u Index: php-src/ext/pgsql/pgsql.c diff -u php-src/ext/pgsql/pgsql.c:1.316 php-src/ext/pgsql/pgsql.c:1.317 --- php-src/ext/pgsql/pgsql.c:1.316 Sat Mar 19 04:07:20 2005 +++ php-src/ext/pgsql/pgsql.c Sat Mar 19 04:21:51 2005 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: pgsql.c,v 1.316 2005/03/19 09:07:20 chriskl Exp $ */ +/* $Id: pgsql.c,v 1.317 2005/03/19 09:21:51 chriskl Exp $ */ #include stdlib.h @@ -483,6 +483,7 @@ REGISTER_LONG_CONSTANT(PGSQL_BAD_RESPONSE, PGRES_BAD_RESPONSE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(PGSQL_NONFATAL_ERROR, PGRES_NONFATAL_ERROR, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(PGSQL_FATAL_ERROR, PGRES_FATAL_ERROR, CONST_CS | CONST_PERSISTENT); +#if HAVE_PQRESULTERRORFIELD /* For pg_result_error_field() field codes */ REGISTER_LONG_CONSTANT(PGSQL_DIAG_SEVERITY, PG_DIAG_SEVERITY, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(PGSQL_DIAG_SQLSTATE, PG_DIAG_SQLSTATE, CONST_CS | CONST_PERSISTENT); @@ -496,6 +497,7 @@ REGISTER_LONG_CONSTANT(PGSQL_DIAG_SOURCE_FILE, PG_DIAG_SOURCE_FILE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(PGSQL_DIAG_SOURCE_LINE, PG_DIAG_SOURCE_LINE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(PGSQL_DIAG_SOURCE_FUNCTION, PG_DIAG_SOURCE_FUNCTION, CONST_CS | CONST_PERSISTENT); +#endif /* pg_convert options */ REGISTER_LONG_CONSTANT(PGSQL_CONV_IGNORE_DEFAULT, PGSQL_CONV_IGNORE_DEFAULT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(PGSQL_CONV_FORCE_NULL, PGSQL_CONV_FORCE_NULL, CONST_CS | CONST_PERSISTENT); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/pgsql pgsql.c /ext/pgsql/tests 03sync_query.phpt
chriskl Sat Mar 19 21:46:03 2005 EDT Modified files: /php-src/ext/pgsql pgsql.c /php-src/ext/pgsql/tests03sync_query.phpt Log: Two of the diagnostic definitions were added in 8.0. Add appropriate #ifdefs. http://cvs.php.net/diff.php/php-src/ext/pgsql/pgsql.c?r1=1.317r2=1.318ty=u Index: php-src/ext/pgsql/pgsql.c diff -u php-src/ext/pgsql/pgsql.c:1.317 php-src/ext/pgsql/pgsql.c:1.318 --- php-src/ext/pgsql/pgsql.c:1.317 Sat Mar 19 04:21:51 2005 +++ php-src/ext/pgsql/pgsql.c Sat Mar 19 21:46:01 2005 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: pgsql.c,v 1.317 2005/03/19 09:21:51 chriskl Exp $ */ +/* $Id: pgsql.c,v 1.318 2005/03/20 02:46:01 chriskl Exp $ */ #include stdlib.h @@ -491,8 +491,12 @@ REGISTER_LONG_CONSTANT(PGSQL_DIAG_MESSAGE_DETAIL, PG_DIAG_MESSAGE_DETAIL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(PGSQL_DIAG_MESSAGE_HINT, PG_DIAG_MESSAGE_HINT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(PGSQL_DIAG_STATEMENT_POSITION, PG_DIAG_STATEMENT_POSITION, CONST_CS | CONST_PERSISTENT); +#ifdef PG_DIAG_INTERNAL_POSITION REGISTER_LONG_CONSTANT(PGSQL_DIAG_INTERNAL_POSITION, PG_DIAG_INTERNAL_POSITION, CONST_CS | CONST_PERSISTENT); +#endif +#ifdef PG_DIAG_INTERNAL_QUERY REGISTER_LONG_CONSTANT(PGSQL_DIAG_INTERNAL_QUERY, PG_DIAG_INTERNAL_QUERY, CONST_CS | CONST_PERSISTENT); +#endif REGISTER_LONG_CONSTANT(PGSQL_DIAG_CONTEXT, PG_DIAG_CONTEXT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(PGSQL_DIAG_SOURCE_FILE, PG_DIAG_SOURCE_FILE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(PGSQL_DIAG_SOURCE_LINE, PG_DIAG_SOURCE_LINE, CONST_CS | CONST_PERSISTENT); @@ -3484,8 +3488,11 @@ RETURN_FALSE; } if (fieldcode (PG_DIAG_SEVERITY|PG_DIAG_SQLSTATE|PG_DIAG_MESSAGE_PRIMARY|PG_DIAG_MESSAGE_DETAIL - |PG_DIAG_MESSAGE_HINT|PG_DIAG_STATEMENT_POSITION|PG_DIAG_INTERNAL_POSITION - |PG_DIAG_INTERNAL_QUERY|PG_DIAG_CONTEXT|PG_DIAG_SOURCE_FILE|PG_DIAG_SOURCE_LINE + |PG_DIAG_MESSAGE_HINT|PG_DIAG_STATEMENT_POSITION +#ifdef PG_DIAG_INTERNAL_POSITION PG_DIAG_INTERNAL_QUERY + |PG_DIAG_INTERNAL_POSITION|PG_DIAG_INTERNAL_QUERY +#endif + |PG_DIAG_CONTEXT|PG_DIAG_SOURCE_FILE|PG_DIAG_SOURCE_LINE |PG_DIAG_SOURCE_FUNCTION)) { field = (char *)PQresultErrorField(pgsql_result, fieldcode); if (field == NULL) { http://cvs.php.net/diff.php/php-src/ext/pgsql/tests/03sync_query.phpt?r1=1.4r2=1.5ty=u Index: php-src/ext/pgsql/tests/03sync_query.phpt diff -u php-src/ext/pgsql/tests/03sync_query.phpt:1.4 php-src/ext/pgsql/tests/03sync_query.phpt:1.5 --- php-src/ext/pgsql/tests/03sync_query.phpt:1.4 Sat Mar 19 04:20:52 2005 +++ php-src/ext/pgsql/tests/03sync_query.phpt Sat Mar 19 21:46:02 2005 @@ -38,8 +38,14 @@ pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL); pg_result_error_field($result, PGSQL_DIAG_MESSAGE_HINT); pg_result_error_field($result, PGSQL_DIAG_STATEMENT_POSITION); -pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION); -pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY); +if (defined('PGSQL_DIAG_INTERNAL_POSITION')) +{ + pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION); +} +if (defined('PGSQL_DIAG_INTERNAL_QUERY')) +{ + pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY); +} pg_result_error_field($result, PGSQL_DIAG_CONTEXT); pg_result_error_field($result, PGSQL_DIAG_SOURCE_FILE); pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php