Skip Menu |
 

This queue is for tickets about the DBD-Pg CPAN distribution.

Report information
The Basics
Id: 65922
Status: rejected
Priority: 0/
Queue: DBD-Pg

People
Owner: Nobody in particular
Requestors: aldis [...] bsdroot.lv
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.17.2
Fixed in: (no value)



Subject: Fails to execute queries with interval
Download (untitled) / with headers
text/plain 474b
It is not possible to correctly execute SQL query that contains interval. Currently to work around this problem you have to insert value directly in query. # works $stm = $db->prepare("SELECT interval '3 hours'"); $stm->execute(); # fails $stm = $db->prepare("SELECT interval '? hours'"); $stm->execute(3); # fails $stm = $db->prepare("SELECT interval ?"); $stm->execute('3 hours'); I came across this problem on my FreeBSD-8.1 with perl 5.10.1 and PostgreSQL 9.0.3
Download (untitled) / with headers
text/plain 619b
On Sat Feb 19 15:04:34 2011, killasmurf86 wrote: Show quoted text
> It is not possible to correctly execute SQL query that contains > interval. > > Currently to work around this problem you have to insert value directly > in query. > > # works > $stm = $db->prepare("SELECT interval '3 hours'"); > $stm->execute(); > > # fails > $stm = $db->prepare("SELECT interval '? hours'"); > $stm->execute(3); > > # fails > $stm = $db->prepare("SELECT interval ?"); > $stm->execute('3 hours');
The interval is not 3. It's "3 hours". You need to do this: $stm = $db->prepare("SELECT interval ?"); $stm->execute('3 hours'); Best, David
From: aldis [...] bsdroot.lv
Download (untitled) / with headers
text/plain 938b
On Sat Feb 19 16:25:33 2011, DWHEELER wrote: Show quoted text
> On Sat Feb 19 15:04:34 2011, killasmurf86 wrote:
> > It is not possible to correctly execute SQL query that contains > > interval. > > > > Currently to work around this problem you have to insert value
directly Show quoted text
> > in query. > > > > # works > > $stm = $db->prepare("SELECT interval '3 hours'"); > > $stm->execute(); > > > > # fails > > $stm = $db->prepare("SELECT interval '? hours'"); > > $stm->execute(3); > > > > # fails > > $stm = $db->prepare("SELECT interval ?"); > > $stm->execute('3 hours');
> > The interval is not 3. It's "3 hours". You need to do this: > > $stm = $db->prepare("SELECT interval ?"); > $stm->execute('3 hours'); > > Best, > > David
Hmm, That doesn't seam to work. Just copy paste your example... it fails DBD::Pg::st execute failed: ERROR: syntax error at or near "$1" LINE 1: SELECT interval $1 ^ at ./Linx.pl line 2048.
Subject: Re: [rt.cpan.org #65922] Fails to execute queries with interval
Date: Sun, 27 Feb 2011 16:57:16 -0800
To: bug-DBD-Pg [...] rt.cpan.org
From: "David E. Wheeler" <david [...] kineticode.com>
Download (untitled) / with headers
text/plain 364b
On Feb 27, 2011, at 3:59 PM, Aldis Berjoza via RT wrote: Show quoted text
> Hmm, That doesn't seam to work. > Just copy paste your example... it fails > > > DBD::Pg::st execute failed: ERROR: syntax error at or near "$1" > LINE 1: SELECT interval $1 > ^ at ./Linx.pl line 2048.
Try this then: $stm = $db->prepare("SELECT ?::interval"); Best, David


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.