[PHP-DEV] Bug #9541 Updated: New Feature Patch

2001-05-05 Thread rasmus

ID: 9541
Updated by: rasmus
Reported By: [EMAIL PROTECTED]
Status: Open
Bug Type: PostgreSQL related
PHP Version: 4.0.4pl1
Assigned To: 
Comments:

It is now in CVS.  Well, not exactly your patch, but there is a pg_last_notice() 
function.  Probably won't be in 4.0.6 either, but definitely in 4.0.7.

Previous Comments:
---

[2001-03-17 14:18:06] [EMAIL PROTECTED]
Is this going to make it into 4.0.5?

---

[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;
 
 


---



ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=9541edit=2


-- 
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]




[PHP-DEV] Bug #9541 Updated: New Feature Patch

2001-05-05 Thread rasmus

ID: 9541
Updated by: rasmus
Reported By: [EMAIL PROTECTED]
Old-Status: Open
Status: Closed
Bug Type: PostgreSQL related
PHP Version: 4.0.4pl1
Assigned To: 
Comments:

forgot to close

Previous Comments:
---

[2001-05-05 21:36:52] [EMAIL PROTECTED]
It is now in CVS.  Well, not exactly your patch, but there is a pg_last_notice() 
function.  Probably won't be in 4.0.6 either, but definitely in 4.0.7.

---

[2001-03-17 14:18:06] [EMAIL PROTECTED]
Is this going to make it into 4.0.5?

---

[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;
 
 


---



ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=9541edit=2


-- 
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]