Fixed bug #39971 (pg_insert/pg_update do not allow now() to be used for

timestamp fields).
This commit is contained in:
Ilia Alshanetsky 2006-12-29 00:34:30 +00:00
parent 2820e6c1fa
commit 79d524dc1e
3 changed files with 38 additions and 6 deletions

2
NEWS
View File

@ -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)

View 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:

View File

@ -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===