summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2001-09-26 21:47:18 +0000
committerZeev Suraski <zeev@php.net>2001-09-26 21:47:18 +0000
commit4053948470c6b5850a56d70cdf6593c6728710b6 (patch)
treedf86aba2785212cca34ca935e85723fac67c45ea
parent333ce2d05074ca850824c1fe7e655b4e7315f87b (diff)
downloadphp-git-4053948470c6b5850a56d70cdf6593c6728710b6.tar.gz
MFH
-rw-r--r--ext/pgsql/pgsql.c22
-rw-r--r--ext/pgsql/php_pgsql.h1
2 files changed, 12 insertions, 11 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 4c2521d453..45f0d497ad 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -160,25 +160,22 @@ static void _close_pgsql_plink(zend_rsrc_list_entry *rsrc TSRMLS_DC)
PQfinish(link);
PGG(num_persistent)--;
PGG(num_links)--;
- if(PGG(last_notice) != NULL) {
- efree(PGG(last_notice));
- }
}
/* }}} */
/* {{{ _notice_handler
*/
-static void
-_notice_handler(void *arg, const char *message)
+static void _notice_handler(void *arg, const char *message)
{
TSRMLS_FETCH();
if (! PGG(ignore_notices)) {
php_log_err((char *) message TSRMLS_CC);
- if (PGG(last_notice) != NULL) {
+ if (PGG(last_notice)) {
efree(PGG(last_notice));
}
- PGG(last_notice) = estrdup(message);
+ PGG(last_notice_len) = strlen(message);
+ PGG(last_notice) = estrndup(message, PGG(last_notice_len));
}
}
/* }}} */
@@ -237,7 +234,6 @@ static void php_pgsql_init_globals(php_pgsql_globals *pgsql_globals_p TSRMLS_DC)
{
PGG(num_persistent) = 0;
PGG(ignore_notices) = 0;
- PGG(last_notice) = NULL;
}
/* }}} */
@@ -283,6 +279,7 @@ PHP_RINIT_FUNCTION(pgsql)
{
PGG(default_link)=-1;
PGG(num_links) = PGG(num_persistent);
+ PGG(last_notice) = NULL;
return SUCCESS;
}
/* }}} */
@@ -291,6 +288,9 @@ PHP_RINIT_FUNCTION(pgsql)
*/
PHP_RSHUTDOWN_FUNCTION(pgsql)
{
+ if (PGG(last_notice)) {
+ efree(PGG(last_notice));
+ }
zend_hash_apply(&EG(persistent_list), (apply_func_t) _rollback_transactions TSRMLS_CC);
return SUCCESS;
}
@@ -923,10 +923,10 @@ PHP_FUNCTION(pg_cmdtuples)
Returns the last notice set by the backend */
PHP_FUNCTION(pg_last_notice)
{
- if (PGG(last_notice) == NULL) {
- RETURN_FALSE;
+ if (PGG(last_notice)) {
+ RETURN_STRINGL(PGG(last_notice), PGG(last_notice_len), 0);
} else {
- RETURN_STRING(PGG(last_notice),0);
+ RETURN_FALSE;
}
}
/* }}} */
diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h
index 4dc190f3c9..f9295ac991 100644
--- a/ext/pgsql/php_pgsql.h
+++ b/ext/pgsql/php_pgsql.h
@@ -123,6 +123,7 @@ typedef struct {
int le_lofp,le_string;
int ignore_notices;
char *last_notice;
+ uint last_notice_len;
} php_pgsql_globals;