]> granicus.if.org Git - php/commitdiff
Add pg_last_notice() function
authorRasmus Lerdorf <rasmus@php.net>
Sun, 6 May 2001 01:34:56 +0000 (01:34 +0000)
committerRasmus Lerdorf <rasmus@php.net>
Sun, 6 May 2001 01:34:56 +0000 (01:34 +0000)
NEWS
ext/pgsql/pgsql.c
ext/pgsql/php_pgsql.h

diff --git a/NEWS b/NEWS
index 873dc0c5e2d1daf17a5bb6618590e0573b421b83..64b099485d3f280fa60e4ea572eb44d270b99c03 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
 PHP 4.0                                                                    NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+?? ??? 200?, Version 4.0.7
+- Add pg_last_notice() function (Rasmus from suggestion by Dirk@rackspace.com)
 
 ?? ??? 200?, Version 4.0.6
 - Fixed a bug in preg_split() that would incorrectly limit the number of
index 7a4f8dbabf426dda05f3668699f6c3280914b360..90070c042c8be6ac0dd17ea60359c0215c30701f 100644 (file)
@@ -46,6 +46,7 @@ function_entry pgsql_functions[] = {
        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)
@@ -145,6 +146,9 @@ static void _close_pgsql_plink(zend_rsrc_list_entry *rsrc)
        PQfinish(link);
        PGG(num_persistent)--;
        PGG(num_links)--;
+       if(PGG(last_notice) != NULL) {
+               efree(PGG(last_notice));
+       }
 }
 
 
@@ -155,10 +159,13 @@ _notice_handler(void *arg, const char *message)
 
        if (! PGG(ignore_notices)) {
                php_log_err(message);
+               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;
@@ -197,6 +204,7 @@ static void php_pgsql_init_globals(PGLS_D)
 {
        PGG(num_persistent) = 0;
        PGG(ignore_notices) = 0;
+       PGG(last_notice) = NULL;
 }
 
 PHP_MINIT_FUNCTION(pgsql)
@@ -866,6 +874,16 @@ PHP_FUNCTION(pg_cmdtuples)
 }
 /* }}} */
 
+/* {{{ 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)
 {
index fed9741fd616db237326bbf5dd4cc9e7a324c5c6..4fd7032b4f3af7f9a023a5732357248e8788caff 100644 (file)
@@ -64,6 +64,7 @@ PHP_FUNCTION(pg_exec);
 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);
@@ -120,6 +121,7 @@ typedef struct {
        long allow_persistent;
        int le_lofp,le_string;
        int ignore_notices;
+       char *last_notice;
 } php_pgsql_globals;