From 1e6e22885d8550f8a868895e97660ef18d2d04d4 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 3 Oct 2007 23:31:04 +0000 Subject: [PATCH] MFB: Fixed bug #42783 (pg_insert() does not accept an empty list for insertion) --- ext/pgsql/pgsql.c | 11 +++++++++-- ext/pgsql/tests/80_bug42783.phpt | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 ext/pgsql/tests/80_bug42783.phpt diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 34ff103198..31c8aeefde 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -5344,7 +5344,11 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var 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 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var /* 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 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var } cleanup: - if (!(opt & PGSQL_DML_NO_CONV)) { + if (!(opt & PGSQL_DML_NO_CONV) && converted) { zval_dtor(converted); FREE_ZVAL(converted); } diff --git a/ext/pgsql/tests/80_bug42783.phpt b/ext/pgsql/tests/80_bug42783.phpt new file mode 100644 index 0000000000..575e527db9 --- /dev/null +++ b/ext/pgsql/tests/80_bug42783.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #42783 (pg_insert() does not support an empty value array) +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECTF-- +array(2) { + ["id"]=> + string(%d) "%d" + ["time"]=> + string(%d) "%s" +} +===DONE=== -- 2.40.0