]> granicus.if.org Git - php/commitdiff
Fixed bug #39971 (pg_insert/pg_update do not allow now() to be used for
authorIlia Alshanetsky <iliaa@php.net>
Fri, 29 Dec 2006 00:34:30 +0000 (00:34 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 29 Dec 2006 00:34:30 +0000 (00:34 +0000)
timestamp fields).

NEWS
ext/pgsql/pgsql.c
ext/pgsql/tests/80_bug39971.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 0ad9ddafdf5a164ad3f52e11dc5bea0b0cb902d7..b0fc15a80a0333781280045fb9fe7e141a5cac48 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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)
index b1187b9c2ab69d839ba04b4c7104b7c3633ef4a0..285db9196eed4faeae87f021cf66658b1175d180 100644 (file)
@@ -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 (file)
index 0000000..45d2631
--- /dev/null
@@ -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===