Hi, attached is a patch which implements a function pg_result_sqlstate. This function is needed because the error messages returned by pg_result_error is localized and can therefor not be parsed reliably.
The patch is against PHP5. Barring any objections please apply the patch for PHP 5.0.3. Thanks -- Markus Bertheau <[EMAIL PROTECTED]>
diff -ru php-5.0.2.orig/ext/pgsql/pgsql.c php-5.0.2/ext/pgsql/pgsql.c --- php-5.0.2.orig/ext/pgsql/pgsql.c 2004-05-12 18:49:47.000000000 +0200 +++ php-5.0.2/ext/pgsql/pgsql.c 2004-11-08 13:13:21.609596470 +0100 @@ -124,6 +124,7 @@ PHP_FE(pg_get_pid, NULL) /* error message functions */ PHP_FE(pg_result_error, NULL) + PHP_FE(pg_result_sqlstate, NULL) PHP_FE(pg_last_error, NULL) PHP_FE(pg_last_notice, NULL) /* copy functions */ @@ -2991,6 +2992,31 @@ /* }}} */ #endif +/* {{{ proto string pg_result_sqlstate(resource result) + Get sqlstate associated with result */ +PHP_FUNCTION(pg_result_sqlstate) +{ + zval *result; + PGresult *pgsql_result; + pgsql_result_handle *pg_result; + char *err = NULL; + + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r", + &result) == FAILURE) { + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); + + pgsql_result = pg_result->result; + if (!pgsql_result) { + RETURN_FALSE; + } + err = (char *)PQresultErrorField(pgsql_result, PG_DIAG_SQLSTATE); + RETURN_STRING(err,1); +} +/* }}} */ + /* {{{ proto string pg_result_error(resource result) Get error message associated with result */ PHP_FUNCTION(pg_result_error) diff -ru php-5.0.2.orig/ext/pgsql/php_pgsql.h php-5.0.2/ext/pgsql/php_pgsql.h --- php-5.0.2.orig/ext/pgsql/php_pgsql.h 2004-01-08 18:32:40.000000000 +0100 +++ php-5.0.2/ext/pgsql/php_pgsql.h 2004-11-08 13:13:00.357428297 +0100 @@ -105,6 +105,7 @@ PHP_FUNCTION(pg_get_pid); /* error message functions */ PHP_FUNCTION(pg_result_error); +PHP_FUNCTION(pg_result_sqlstate); PHP_FUNCTION(pg_last_error); PHP_FUNCTION(pg_last_notice); /* copy functions */
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php