diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2006-12-29 00:34:30 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2006-12-29 00:34:30 +0000 |
commit | 79d524dc1e320cd38bbf6716f2f9f43df68cc037 (patch) | |
tree | bf6b827cf7bb54117c47560f9af80623b00e2884 | |
parent | 2820e6c1faf174af4a432b8ca66bd82e3e2263c1 (diff) | |
download | php-git-79d524dc1e320cd38bbf6716f2f9f43df68cc037.tar.gz |
Fixed bug #39971 (pg_insert/pg_update do not allow now() to be used for
timestamp fields).
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | ext/pgsql/pgsql.c | 12 | ||||
-rw-r--r-- | ext/pgsql/tests/80_bug39971.phpt | 30 |
3 files changed, 38 insertions, 6 deletions
@@ -17,6 +17,8 @@ PHP NEWS __inet_pton() and inet_ntop() was named __inet_ntop(). (Hannes) - Fixed the validate email filter so that the letter "v" can also be used in the user part of the email address. (Derick) +- Fixed bug #39971 (pg_insert/pg_update do not allow now() to be used for + timestamp fields). (Ilia) - Fixed bug #39952 (zip ignoring --with-libdir on zlib checks) (judas dot iscariote at gmail dot com) - Fixed bug #39944 (References broken). (Dmitry) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index b1187b9c2a..285db9196e 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -4968,14 +4968,14 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con switch(Z_TYPE_PP(val)) { case IS_STRING: if (Z_STRLEN_PP(val) == 0) { - ZVAL_STRING(new_val, "NULL", 1); - } - else { + ZVAL_STRINGL(new_val, "NULL", sizeof("NULL")-1, 1); + } else if (!strcasecmp(Z_STRVAL_PP(val), "now()")) { + ZVAL_STRINGL(new_val, "NOW()", sizeof("NOW()")-1, 1); + } else { /* FIXME: better regex must be used */ if (php_pgsql_convert_match(Z_STRVAL_PP(val), "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})([ \\t]+(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1}(\\.[0-9]+){0,1}([ \\t]*([+-][0-9]{1,2}(:[0-9]{1,2}){0,1}|[a-zA-Z]{1,5})){0,1})){0,1}$", 1 TSRMLS_CC) == FAILURE) { err = 1; - } - else { + } else { ZVAL_STRING(new_val, Z_STRVAL_PP(val), 1); php_pgsql_add_quotes(new_val, 1 TSRMLS_CC); } @@ -4983,7 +4983,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con break; case IS_NULL: - ZVAL_STRING(new_val, "NULL", 1); + ZVAL_STRINGL(new_val, "NULL", sizeof("NULL")-1, 1); break; default: diff --git a/ext/pgsql/tests/80_bug39971.phpt b/ext/pgsql/tests/80_bug39971.phpt new file mode 100644 index 0000000000..45d26319d3 --- /dev/null +++ b/ext/pgsql/tests/80_bug39971.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #39971 (pg_insert/pg_update do not allow now() to be used for timestamp fields) +--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, tm timestamp NOT NULL)"); + +$values = array('tm' => 'now()'); +pg_insert($dbh, 'php_test', $values); + +$ids = array('id' => 1); +pg_update($dbh, 'php_test', $values, $ids); + +pg_query($dbh, "DROP TABLE php_test"); +pg_close($dbh); +?> +===DONE=== +--EXPECT-- +===DONE=== |