ID: 9541 User Update by: [EMAIL PROTECTED] Status: Open Bug Type: PostgreSQL related Description: New Feature Patch Is this going to make it into 4.0.5? Previous Comments: --------------------------------------------------------------------------- [2001-03-04 01:16:57] [EMAIL PROTECTED] Hi - I ran into the problem that the notices that are sent from the postgres backend are being ignored by php. Most of the time this doesn't matter, but it would be nice to be able to profile an application by running explains (which show sql cost) on every sql statement that is executed that way you can find where your problems are as you develop the software. Below is a patch to add this php4 (Although I don't have a cvs I account - I did built it against the 200103031945 snap shot so it should be easy to integrate into the source tree) Can you please add this before the next release :) new php function - I wasn't sure how to document this in the code so here is is in the bug report pg_last_notice(int connection) returns either an empty string or the contents of the last notice sent out by the database. This can be useful to get the output from the explain command. see patch below --- php4-200103031945/ext/pgsql/pgsql.c Mon Feb 26 00:45:27 2001 +++ php4-200103031945/ext/pgsql/pgsql.c.notice Sat Mar 3 23:40:55 2001 @@ -46,6 +46,7 @@ PHP_FE(pg_pconnect, NULL) PHP_FE(pg_close, NULL) PHP_FE(pg_cmdtuples, NULL) + PHP_FE(pg_last_notice, NULL) PHP_FE(pg_dbname, NULL) PHP_FE(pg_errormessage, NULL) PHP_FE(pg_trace, NULL) @@ -146,12 +147,31 @@ PQfinish(link); PGG(num_persistent)--; PGG(num_links)--; + if (PGG(last_notice) != NULL) + { + efree(PGG(last_notice)); + } } +/* This function is used to silence the notice messages sent by the postgres back +end. This can be useful when you know you are going to trigger a notice and don't +care + */ static void _be_quiet(void * arg, const char * message) { } +/*This function is used to store the last notice for later retreval + */ +static void _store_notice(void * arg, const char * message) +{ + char *copy_of_message = NULL; + + if (PGG(last_notice) != NULL) + { + efree(PGG(last_notice)); + } + PGG(last_notice) = estrdup(message); +} + static int _rollback_transactions(zend_rsrc_list_entry *rsrc) { PGconn *link = (PGconn *)rsrc->ptr; @@ -194,6 +214,7 @@ static void php_pgsql_init_globals(PGLS_D) { PGG(num_persistent) = 0; + PGG(last_notice) = NULL; } PHP_MINIT_FUNCTION(pgsql) @@ -465,6 +486,9 @@ } efree(hashed_details); php_pgsql_set_default_link(return_value->value.lval); + /* Set the notice handler so we can keep notices for later*/ + PQsetNoticeProcessor(pgsql, _store_notice, NULL); + } @@ -854,6 +878,20 @@ } /* }}} */ +/* {{{ proto int pg_last_notice(int connection) + Returns the last notice set by the backend */ +PHP_FUNCTION(pg_last_notice) +{ + if (PGG(last_notice) == NULL) + { + RETURN_FALSE; + } + else + { + RETURN_STRING(PGG(last_notice),0); + } +} +/* }}} */ char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list) { --- php4-200103031945/ext/pgsql/php_pgsql.h Mon Feb 26 00:45:27 2001 +++ php4-200103031945/ext/pgsql/php_pgsql.h.notice Sat Mar 3 23:40:55 2001 @@ -64,6 +64,7 @@ PHP_FUNCTION(pg_numrows); PHP_FUNCTION(pg_numfields); PHP_FUNCTION(pg_cmdtuples); +PHP_FUNCTION(pg_last_notice); PHP_FUNCTION(pg_fieldname); PHP_FUNCTION(pg_fieldsize); PHP_FUNCTION(pg_fieldtype); @@ -119,6 +120,7 @@ long max_links,max_persistent; long allow_persistent; int le_lofp,le_string; + char *last_notice; } php_pgsql_globals; --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=9541 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]