#49643 [NEW]: Improper quoting on datetime bound parameters for postgresql
| From: | alandsidel at dnsstuff dot com | Date: | Wed, 23 Sep 2009 12:21:52 +0000 |
| Subject: | #49643 [NEW]: Improper quoting on datetime bound parameters for postgresql | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-142765@lists.php.net to get a copy of this message | ||
From: alandsidel at dnsstuff dot com
Operating system: FreeBSD
PHP version: 5.3.0
PHP Bug Type: PDO related
Bug description: Improper quoting on datetime bound parameters for postgresql
Description:
------------
Running PostGreSQL 8.4, given a simple table like:
When using a bound parameter in prepare (named or unnamed) to a timestamp
field, the parameter is improperly quoted resulting in errors on INSERT or
UPDATE statements that are using expressions rather than simple datetime
strings.
Reproduce code:
---------------
// In the postgresql database
CREATE TABLE foo
(
id SERIAL UNIQUE NOT NULL,
dtSometime TIMESTAMP WITH TIME ZONE NOT NULL
);
// Assuming $dbh is a connection to the above database
if ($stmt = $dbh->prepare('INSERT INTO foo (dtSometime) VALUES
(:dtsometime)')
{
if ($stmt->execute(array('now() + interval \'1 year\''))
{
print("ok!\n");
}
else
{
print_r($dbh->errorInfo());
}
}
Expected result:
----------------
Expect a row to be inserted and 'ok!' to print.
Actual result:
--------------
The following is printed on the console:
//--cut
(
[0] => 00000
[1] => 7
[2] => ERROR: invalid input syntax for type timestamp with time zone:
"now() + interval '1 year'"
)
//--cut
A direct insert with the given SQL works fine as expected, so this must be
a quoting issue that is forcing postgresql to interpret the expression as a
literal datetime.
--
Edit bug report at http://bugs.php.net/?id=49643&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49643&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49643&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49643&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=49643&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49643&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=49643&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=49643&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=49643&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=49643&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=49643&r=support
Expected behavior: http://bugs.php.net/fix.php?id=49643&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=49643&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=49643&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=49643&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49643&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49643&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=49643&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=49643&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=49643&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=49643&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=49643&r=mysqlcfg