iliaa Wed Oct 3 23:31:05 2007 UTC
Modified files:
/php-src/ext/pgsql/tests 80_bug42783.phpt
/php-src/ext/pgsql pgsql.c
Log:
MFB: Fixed bug #42783 (pg_insert() does not accept an empty list for
insertion)
http://cvs.php.net/viewvc.cgi/php-src/ext/pgsql/tests/80_bug42783.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/pgsql/tests/80_bug42783.phpt
diff -u /dev/null php-src/ext/pgsql/tests/80_bug42783.phpt:1.2
--- /dev/null Wed Oct 3 23:31:04 2007
+++ php-src/ext/pgsql/tests/80_bug42783.phpt Wed Oct 3 23:31:04 2007
@@ -0,0 +1,34 @@
+--TEST--
+Bug #42783 (pg_insert() does not support an empty value array)
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once('config.inc');
+
+$dbh = @pg_connect($conn_str);
+if (!$dbh) {
+ die ("Could not connect to the server");
+}
+
+pg_query("CREATE TABLE php_test (id SERIAL PRIMARY KEY, time TIMESTAMP NOT
NULL DEFAULT now())");
+
+pg_insert($dbh, 'php_test', array());
+
+var_dump(pg_fetch_assoc(pg_query("SELECT * FROM php_test")));
+
+pg_query($dbh, "DROP TABLE php_test");
+pg_close($dbh);
+?>
+===DONE===
+--EXPECTF--
+array(2) {
+ ["id"]=>
+ string(%d) "%d"
+ ["time"]=>
+ string(%d) "%s"
+}
+===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/pgsql/pgsql.c?r1=1.373&r2=1.374&diff_format=u
Index: php-src/ext/pgsql/pgsql.c
diff -u php-src/ext/pgsql/pgsql.c:1.373 php-src/ext/pgsql/pgsql.c:1.374
--- php-src/ext/pgsql/pgsql.c:1.373 Thu Sep 27 18:28:41 2007
+++ php-src/ext/pgsql/pgsql.c Wed Oct 3 23:31:04 2007
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql.c,v 1.373 2007/09/27 18:28:41 dmitry Exp $ */
+/* $Id: pgsql.c,v 1.374 2007/10/03 23:31:04 iliaa Exp $ */
#include <stdlib.h>
@@ -5344,7 +5344,11 @@
assert(Z_TYPE_P(var_array) == IS_ARRAY);
if (zend_hash_num_elements(Z_ARRVAL_P(var_array)) == 0) {
- return FAILURE;
+ smart_str_appends(&querystr, "INSERT INTO ");
+ smart_str_appends(&querystr, table);
+ smart_str_appends(&querystr, " DEFAULT VALUES");
+
+ goto no_values;
}
/* convert input array if needed */
@@ -5402,6 +5406,9 @@
/* Remove the trailing "," */
querystr.len--;
smart_str_appends(&querystr, ");");
+
+no_values:
+
smart_str_0(&querystr);
if ((opt & (PGSQL_DML_EXEC|PGSQL_DML_ASYNC)) &&
@@ -5413,7 +5420,7 @@
}
cleanup:
- if (!(opt & PGSQL_DML_NO_CONV)) {
+ if (!(opt & PGSQL_DML_NO_CONV) && converted) {
zval_dtor(converted);
FREE_ZVAL(converted);
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php