Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13787 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16837 invoked by uid 1010); 8 Nov 2004 12:45:26 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 13835 invoked from network); 8 Nov 2004 12:44:39 -0000 Received: from unknown (HELO web11.manitu.net) (217.11.48.111) by pb1.pair.com with SMTP; 8 Nov 2004 12:44:39 -0000 Received: from [62.165.4.166] (dicaprio.akademie1.de [62.165.4.166]) (authenticated) by web11.manitu.net (8.10.2-SOL3/8.10.2) with ESMTP id iA8CiVX20235; Mon, 8 Nov 2004 13:44:31 +0100 To: internals@lists.php.net Cc: Yasuo Ohgaki Content-Type: multipart/mixed; boundary="=-i/K/vo7Bw1GqvcelvEti" Message-ID: <1099917871.2648.12.camel@dicaprio.akademie1.de> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Mon, 08 Nov 2004 13:44:31 +0100 Subject: [PATCH] pg_result_sqlstate From: twanger@bluetwanger.de (Markus Bertheau) --=-i/K/vo7Bw1GqvcelvEti Content-Type: text/plain Content-Transfer-Encoding: 7bit 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 --=-i/K/vo7Bw1GqvcelvEti Content-Disposition: attachment; filename=pg_result_sqlstate.patch Content-Type: text/x-patch; name=pg_result_sqlstate.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 */ --=-i/K/vo7Bw1GqvcelvEti--