pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedescaping arrays in perl dbi
6+ messages / 5 participants
[nested] [flat]
* escaping arrays in perl dbi
@ 2002-05-09 14:12 Vincent Stoessel <vincent@xaymaca.com>
0 siblings, 3 replies; 6+ messages in thread
From: Vincent Stoessel @ 2002-05-09 14:12 UTC (permalink / raw)
To: pgsql-sql
Hello All,
I am trying to figure out how I need to change the string below in
order to do an insert into my table using perl dbi. perl seems to choke
on the curly brackets. Any help would be appriciated.
Thanks.
$dbh->do("update basket set f_order ='{"apple",0}' where cap ='I'");
--
Vincent Stoessel
Linux Systems Developer
vincent xaymaca.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: escaping arrays in perl dbi
@ 2002-05-09 14:36 Tod McQuillin <devin@spamcop.net>
parent: Vincent Stoessel <vincent@xaymaca.com>
2 siblings, 1 reply; 6+ messages in thread
From: Tod McQuillin @ 2002-05-09 14:36 UTC (permalink / raw)
To: Vincent Stoessel <vincent@xaymaca.com>; +Cc: pgsql-sql
On Thu, 9 May 2002, Vincent Stoessel wrote:
> I am trying to figure out how I need to change the string below in
> order to do an insert into my table using perl dbi. perl seems to choke
> on the curly brackets. Any help would be appriciated.
>
> $dbh->do("update basket set f_order ='{"apple",0}' where cap ='I'");
You are using double quotes as your string delimiter, and also double
quotes inside it.
Probably this would work:
$dbh->do("update basket set f_order ='{\"apple\",0}' where cap ='I'");
or this:
$dbh->do(qq/update basket set f_order ='{"apple",0}' where cap ='I'/);
But try using DBI parameters like this:
$dbh->prepare("update basket set f_order = ? where cap = ?");
$dbh->execute('{"apple",0}', 'I');
DBI should take care of all the quoting and escaping for you.
--
Tod McQuillin
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: escaping arrays in perl dbi
@ 2002-05-09 14:44 Andrew Perrin <aperrin@email.unc.edu>
parent: Vincent Stoessel <vincent@xaymaca.com>
2 siblings, 0 replies; 6+ messages in thread
From: Andrew Perrin @ 2002-05-09 14:44 UTC (permalink / raw)
To: Vincent Stoessel <vincent@xaymaca.com>; +Cc: pgsql-sql
It's not the curly brackets but the double quotes - when you hit the
opening " of "apple" it matches the original " of the string. Try:
$dbh->do(q{update basket set f_order='{"apple",0}' where cap='I'});
ap
----------------------------------------------------------------------
Andrew J Perrin - andrew_perrin@unc.edu - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
269 Hamilton Hall, CB#3210, Chapel Hill, NC 27599-3210 USA
On Thu, 9 May 2002, Vincent Stoessel wrote:
> Hello All,
> I am trying to figure out how I need to change the string below in
> order to do an insert into my table using perl dbi. perl seems to choke
> on the curly brackets. Any help would be appriciated.
> Thanks.
>
>
> $dbh->do("update basket set f_order ='{"apple",0}' where cap ='I'");
>
>
> --
> Vincent Stoessel
> Linux Systems Developer
> vincent xaymaca.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: escaping arrays in perl dbi
@ 2002-05-09 15:28 Dave Carrigan <dave@rudedog.org>
parent: Tod McQuillin <devin@spamcop.net>
0 siblings, 1 reply; 6+ messages in thread
From: Dave Carrigan @ 2002-05-09 15:28 UTC (permalink / raw)
To: Tod McQuillin <devin@spamcop.net>; +Cc: Vincent Stoessel <vincent@xaymaca.com>; pgsql-sql
Tod McQuillin <devin@spamcop.net> writes:
> But try using DBI parameters like this:
>
> $dbh->prepare("update basket set f_order = ? where cap = ?");
> $dbh->execute('{"apple",0}', 'I');
>
> DBI should take care of all the quoting and escaping for you.
This is the best way to do it, but you can shorten it with:
$dbh->do("update basket set f_order = ? where cap = ?",
undef, '{"apple",0}', 'I');
If you don't want to use the parameterized mechanism, Perl's qq operator
is your friend:
$dbh->do(qq(update basket set f_order = {"apple",0} where cap = 'I'));
--
Dave Carrigan (dave@rudedog.org) | Yow! Why am I in this ROOM in
UNIX-Apache-Perl-Linux-Firewalls-LDAP-C-DNS | DOWNTOWN PHILADELPHIA?
Seattle, WA, USA |
http://www.rudedog.org/ |
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: escaping arrays in perl dbi
@ 2002-05-09 21:00 Vincent Stoessel <vincent@xaymaca.com>
parent: Dave Carrigan <dave@rudedog.org>
0 siblings, 0 replies; 6+ messages in thread
From: Vincent Stoessel @ 2002-05-09 21:00 UTC (permalink / raw)
To: Dave Carrigan <dave@rudedog.org>; +Cc: Tod McQuillin <devin@spamcop.net>; pgsql-sql
Thank you everyone for all of the great answers.
Dave Carrigan wrote:
> Tod McQuillin <devin@spamcop.net> writes:
>
>
>>But try using DBI parameters like this:
>>
>>$dbh->prepare("update basket set f_order = ? where cap = ?");
>>$dbh->execute('{"apple",0}', 'I');
>>
>>DBI should take care of all the quoting and escaping for you.
>
>
> This is the best way to do it, but you can shorten it with:
>
> $dbh->do("update basket set f_order = ? where cap = ?",
> undef, '{"apple",0}', 'I');
>
> If you don't want to use the parameterized mechanism, Perl's qq operator
> is your friend:
>
> $dbh->do(qq(update basket set f_order = {"apple",0} where cap = 'I'));
>
--
Vincent Stoessel
Linux Systems Developer
vincent xaymaca.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: escaping arrays in perl dbi
@ 2002-05-09 23:09 Ian Barwick <barwick@gmx.net>
parent: Vincent Stoessel <vincent@xaymaca.com>
2 siblings, 0 replies; 6+ messages in thread
From: Ian Barwick @ 2002-05-09 23:09 UTC (permalink / raw)
To: Vincent Stoessel <vincent@xaymaca.com>; pgsql-sql
On Thursday 09 May 2002 16:12, Vincent Stoessel wrote:
> Hello All,
> I am trying to figure out how I need to change the string below in
> order to do an insert into my table using perl dbi. perl seems to choke
> on the curly brackets.
It's choking on the unescape quotes...
> $dbh->do("update basket set f_order ='{"apple",0}' where cap ='I'");
qq is your friend:
$dbh->do(qq|update basket set f_order ='{"apple",0}' where cap ='I'|);
Type
perldoc perlop
into a nearby commandline and look for the section "Quote and Quote-like
Operators" for more info.
Ian Barwick
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2002-05-09 23:09 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-09 14:12 escaping arrays in perl dbi Vincent Stoessel <vincent@xaymaca.com>
2002-05-09 14:36 ` Tod McQuillin <devin@spamcop.net>
2002-05-09 15:28 ` Dave Carrigan <dave@rudedog.org>
2002-05-09 21:00 ` Vincent Stoessel <vincent@xaymaca.com>
2002-05-09 14:44 ` Andrew Perrin <aperrin@email.unc.edu>
2002-05-09 23:09 ` Ian Barwick <barwick@gmx.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox