Fix pg_last_notice()

This commit is contained in:
Zeev Suraski 2001-09-26 21:44:48 +00:00
parent 51e2a6b84e
commit dd01c11ee3
3 changed files with 13 additions and 11 deletions

1
NEWS
View file

@ -24,6 +24,7 @@ PHP 4.0 NEWS
- Improved support for autoconf-2.50+/libtool 1.4b+. (Jan Kneschke, Sascha) - Improved support for autoconf-2.50+/libtool 1.4b+. (Jan Kneschke, Sascha)
?? ??? 200?, Version 4.0.7 ?? ??? 200?, Version 4.0.7
- Fixed pg_last_notice() (Zeev)
- Fixed DOM-XML's error reporting, so E_WARNING errors are given instead of - Fixed DOM-XML's error reporting, so E_WARNING errors are given instead of
E_ERROR error's, this allows you to trap errors thrown by DOMXML functions. E_ERROR error's, this allows you to trap errors thrown by DOMXML functions.
(Sterling) (Sterling)

View file

@ -160,25 +160,22 @@ static void _close_pgsql_plink(zend_rsrc_list_entry *rsrc TSRMLS_DC)
PQfinish(link); PQfinish(link);
PGG(num_persistent)--; PGG(num_persistent)--;
PGG(num_links)--; PGG(num_links)--;
if(PGG(last_notice) != NULL) {
efree(PGG(last_notice));
}
} }
/* }}} */ /* }}} */
/* {{{ _notice_handler /* {{{ _notice_handler
*/ */
static void static void _notice_handler(void *arg, const char *message)
_notice_handler(void *arg, const char *message)
{ {
TSRMLS_FETCH(); TSRMLS_FETCH();
if (! PGG(ignore_notices)) { if (! PGG(ignore_notices)) {
php_log_err((char *) message TSRMLS_CC); php_log_err((char *) message TSRMLS_CC);
if (PGG(last_notice) != NULL) { if (PGG(last_notice)) {
efree(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(num_persistent) = 0;
PGG(ignore_notices) = 0; PGG(ignore_notices) = 0;
PGG(last_notice) = NULL;
} }
/* }}} */ /* }}} */
@ -283,6 +279,7 @@ PHP_RINIT_FUNCTION(pgsql)
{ {
PGG(default_link)=-1; PGG(default_link)=-1;
PGG(num_links) = PGG(num_persistent); PGG(num_links) = PGG(num_persistent);
PGG(last_notice) = NULL;
return SUCCESS; return SUCCESS;
} }
/* }}} */ /* }}} */
@ -291,6 +288,9 @@ PHP_RINIT_FUNCTION(pgsql)
*/ */
PHP_RSHUTDOWN_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); zend_hash_apply(&EG(persistent_list), (apply_func_t) _rollback_transactions TSRMLS_CC);
return SUCCESS; return SUCCESS;
} }
@ -923,10 +923,10 @@ PHP_FUNCTION(pg_cmdtuples)
Returns the last notice set by the backend */ Returns the last notice set by the backend */
PHP_FUNCTION(pg_last_notice) PHP_FUNCTION(pg_last_notice)
{ {
if (PGG(last_notice) == NULL) { if (PGG(last_notice)) {
RETURN_FALSE; RETURN_STRINGL(PGG(last_notice), PGG(last_notice_len), 0);
} else { } else {
RETURN_STRING(PGG(last_notice),0); RETURN_FALSE;
} }
} }
/* }}} */ /* }}} */

View file

@ -123,6 +123,7 @@ typedef struct {
int le_lofp,le_string; int le_lofp,le_string;
int ignore_notices; int ignore_notices;
char *last_notice; char *last_notice;
uint last_notice_len;
} php_pgsql_globals; } php_pgsql_globals;