escaping arrays in perl dbi

Поиск
Список
Период
Сортировка
Искать

escaping arrays in perl dbi

От:
Vincent Stoessel <vincent@xaymaca.com>
Дата:
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


Re: escaping arrays in perl dbi

От:
Tod McQuillin <devin@spamcop.net>
Дата:
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



Re: escaping arrays in perl dbi

От:
Vincent Stoessel <vincent@xaymaca.com>
Дата:
Thank you everyone for all of the great answers.

Dave Carrigan wrote:
> Tod McQuillin  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


Re: escaping arrays in perl dbi

От:
Ian Barwick <barwick@gmx.net>
Дата:
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

Re: escaping arrays in perl dbi

От:
Andrew Perrin <aperrin@email.unc.edu>
Дата:
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/~aperrinAssistant 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
> 


Re: escaping arrays in perl dbi

От:
Dave Carrigan <dave@rudedog.org>
Дата:
Tod McQuillin  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/                     | 

FAQ