iliaa Tue Nov 25 17:23:56 2003 EDT
Modified files: (Branch: PHP_4_3)
/php-src NEWS
/php-src/ext/pgsql pgsql.c
Log:
MFH: Fixed bug #25963 (PostgreSQL error message include \n characters).
Index: php-src/NEWS
diff -u php-src/NEWS:1.1247.2.478 php-src/NEWS:1.1247.2.479
--- php-src/NEWS:1.1247.2.478 Tue Nov 25 03:08:25 2003
+++ php-src/NEWS Tue Nov 25 17:23:53 2003
@@ -3,6 +3,8 @@
?? ??? 2003, Version 4.3.5
- Fixed header handler in NSAPI SAPI module (header->replace was ignored,
send_default_content_type now sends value from php.ini). (Uwe Schindler)
+- Fixed bug #25963 (PostgreSQL error message include \n characters).
+ (Marcus, Ilia)
- Fixed bug #26376 (typo in ext/odbc/config.m4: DBMaker test fails). (Jani)
- Fixed bug #26384 (crash in domxslt->process()). (Ilia)
- Fixed bug #26355 (flock() doesn't initialize the wouldblock argument). (Ilia)
Index: php-src/ext/pgsql/pgsql.c
diff -u php-src/ext/pgsql/pgsql.c:1.244.2.26 php-src/ext/pgsql/pgsql.c:1.244.2.27
--- php-src/ext/pgsql/pgsql.c:1.244.2.26 Sat Sep 6 11:31:14 2003
+++ php-src/ext/pgsql/pgsql.c Tue Nov 25 17:23:54 2003
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql.c,v 1.244.2.26 2003/09/06 15:31:14 helly Exp $ */
+/* $Id: pgsql.c,v 1.244.2.27 2003/11/25 22:23:54 iliaa Exp $ */
#include <stdlib.h>
@@ -214,6 +214,31 @@
ZEND_DECLARE_MODULE_GLOBALS(pgsql);
+/* {{{ _php_pgsql_trim_message */
+static char * _php_pgsql_trim_message(const char *message, int *len)
+{
+ register int i = strlen(message)-1;
+
+ if (i>1 && (message[i-1] == '\r' || message[i-1] == '\n') && message[i] ==
'.') {
+ --i;
+ }
+ while (i && (message[i] == '\r' || message[i] == '\n')) {
+ --i;
+ }
+ ++i;
+ if (len) {
+ *len = i;
+ }
+ return estrndup(message, i);
+}
+/* }}} */
+
+#define PHP_PQ_ERROR(text, pgsql) { \
+ char *msgbuf = _php_pgsql_trim_message(PQerrorMessage(pgsql), NULL); \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, text, msgbuf); \
+ efree(msgbuf); \
+} \
+
/* {{{ php_pgsql_set_default_link
*/
static void php_pgsql_set_default_link(int id TSRMLS_DC)
@@ -558,8 +583,7 @@
pgsql=PQsetdb(host,port,options,tty,dbname);
}
if (pgsql==NULL || PQstatus(pgsql)==CONNECTION_BAD) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
- "Unable to connect to
PostgreSQL server: %s.", PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("Unable to connect to PostgreSQL server:
%s.", pgsql)
if (pgsql) {
PQfinish(pgsql);
}
@@ -644,7 +668,7 @@
pgsql = PQsetdb(host,port,options,tty,dbname);
}
if (pgsql==NULL || PQstatus(pgsql)==CONNECTION_BAD) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to connect
to PostgreSQL server: %s.", PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("Unable to connect to PostgreSQL server: %s.",
pgsql);
goto err;
}
@@ -789,7 +813,8 @@
Z_STRVAL_P(return_value) = PQdb(pgsql);
break;
case PHP_PG_ERROR_MESSAGE:
- Z_STRVAL_P(return_value) = PQerrorMessage(pgsql);
+ Z_STRVAL_P(return_value) =
_php_pgsql_trim_message(PQerrorMessage(pgsql), &(Z_STRLEN_P(return_value)));
+ goto done;
break;
case PHP_PG_OPTIONS:
Z_STRVAL_P(return_value) = PQoptions(pgsql);
@@ -813,6 +838,7 @@
Z_STRLEN_P(return_value) = 0;
Z_STRVAL_P(return_value) = (char *) estrdup("");
}
+done:
Z_TYPE_P(return_value) = IS_STRING;
}
/* }}} */
@@ -963,7 +989,7 @@
case PGRES_BAD_RESPONSE:
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Query failed:
%s.", PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("Query failed: %s.", pgsql);
PQclear(pgsql_result);
RETURN_FALSE;
break;
@@ -2395,7 +2421,7 @@
result = PQendcopy(pgsql);
if (result!=0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Query failed: %s.",
PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("Query failed: %s.", pgsql);
RETURN_FALSE;
}
RETURN_TRUE;
@@ -2439,7 +2465,7 @@
result = PQputline(pgsql, Z_STRVAL_PP(query));
if (result==EOF) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Query failed: %s.",
PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("Query failed: %s.", pgsql);
RETURN_FALSE;
}
RETURN_TRUE;
@@ -2504,7 +2530,7 @@
while (!copydone)
{
if ((ret = PQgetline(pgsql, copybuf,
COPYBUFSIZ))) {
- php_error_docref(NULL TSRMLS_CC,
E_WARNING, "getline failed: %s.", PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("getline failed: %s.",
pgsql);
RETURN_FALSE;
}
@@ -2538,7 +2564,7 @@
}
}
if (PQendcopy(pgsql)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
"endcopy failed: %s.", PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("endcopy failed: %s.", pgsql);
RETURN_FALSE;
}
while ((pgsql_result = PQgetResult(pgsql))) {
@@ -2551,7 +2577,7 @@
break;
default:
PQclear(pgsql_result);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Copy command
failed: %s.", PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("Copy command failed: %s.", pgsql);
RETURN_FALSE;
break;
}
@@ -2619,18 +2645,18 @@
strcat(query, "\n");
if (PQputline(pgsql, query)) {
efree(query);
- php_error_docref(NULL TSRMLS_CC,
E_WARNING, "copy failed: %s.", PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("copy failed: %s.",
pgsql);
RETURN_FALSE;
}
efree(query);
zend_hash_move_forward_ex(Z_ARRVAL_P(pg_rows),
&pos);
}
if (PQputline(pgsql, "\\.\n") == EOF) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
"putline failed: %s.", PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("putline failed: %s.", pgsql);
RETURN_FALSE;
}
if (PQendcopy(pgsql)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
"endcopy failed: %s.", PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("endcopy failed: %s.", pgsql);
RETURN_FALSE;
}
while ((pgsql_result = PQgetResult(pgsql))) {
@@ -2644,7 +2670,7 @@
break;
default:
PQclear(pgsql_result);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Copy command
failed: %s.", PQerrorMessage(pgsql));
+ PHP_PQ_ERROR("Copy command failed: %s.", pgsql);
RETURN_FALSE;
break;
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php