summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--ext/pgsql/pgsql.c20
-rw-r--r--ext/pgsql/php_pgsql.h2
3 files changed, 23 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 873dc0c5e2..64b099485d 100644
--- 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
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 7a4f8dbabf..90070c042c 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -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)
{
diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h
index fed9741fd6..4fd7032b4f 100644
--- a/ext/pgsql/php_pgsql.h
+++ b/ext/pgsql/php_pgsql.h
@@ -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;