Thread: Quoting '?' placeholder in Perl's DBD::Pg?
Hi anyone know how I can quote or turn off the ? placeholder in Perl's DBD::Pg? I've asked on the perl modules newsgroups but I didn't get any satisfactory answer. Say I'm constructing a custom SQL query and it turns out that there is a ? somewhere, how do I quote it out? It gets recognised as a placeholder by the DBD::Pg driver. e.g. my $SQL=<<"EOT"; insert into blah (a,b) values ('asdad?rerwe','blah') EOT The ? gets interpreted as a placeholder. Sure I can do my $SQL=<<"EOT"; insert into blah (a,b) values (?,?) EOT And do the execute thing. But if the number of columns changes from query to query, and so on it might be less convenient to use placeholders. If it really can't be done, then yeah I'll use placeholders. But it seems strange if you can't. Cheerio, Link.
$dbh->quote() won't do it? I haven't tried this. $string = 'asdad?rerwe'; $quoted = $dbh->quote($string); insert into blah (a) values ($quoted); Just a thought. David On 9/27/01 12:40 PM, "Lincoln Yeoh" <lyeoh@pop.jaring.my> wrote: > Hi anyone know how I can quote or turn off the ? placeholder in Perl's > DBD::Pg? > > I've asked on the perl modules newsgroups but I didn't get any satisfactory > answer. > > Say I'm constructing a custom SQL query and it turns out that there is a ? > somewhere, how do I quote it out? It gets recognised as a placeholder by > the DBD::Pg driver. > e.g. > my $SQL=<<"EOT"; > insert into blah (a,b) values ('asdad?rerwe','blah') > EOT > > The ? gets interpreted as a placeholder. > > Sure I can do > my $SQL=<<"EOT"; > insert into blah (a,b) values (?,?) > EOT > > And do the execute thing. But if the number of columns changes from query > to query, and so on it might be less convenient to use placeholders. > > If it really can't be done, then yeah I'll use placeholders. But it seems > strange if you can't. > > Cheerio, > Link. > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org >
I think you are supposed to escape placeholder markers by doubling them: ?? should be effectively changed to '?' before passed to PG. I haven't come across this yet, but I think that's the correct (although undocumented) syntax. Keary Suska Esoteritech, Inc. "Leveraging Open Source for a better Internet" > From: Lincoln Yeoh <lyeoh@pop.jaring.my> > Date: Fri, 28 Sep 2001 00:40:50 +0800 > To: pgsql-general@postgresql.org > Subject: [GENERAL] Quoting '?' placeholder in Perl's DBD::Pg? > > Hi anyone know how I can quote or turn off the ? placeholder in Perl's > DBD::Pg? > > I've asked on the perl modules newsgroups but I didn't get any satisfactory > answer. > > Say I'm constructing a custom SQL query and it turns out that there is a ? > somewhere, how do I quote it out? It gets recognised as a placeholder by > the DBD::Pg driver. > e.g. > my $SQL=<<"EOT"; > insert into blah (a,b) values ('asdad?rerwe','blah') > EOT > > The ? gets interpreted as a placeholder. > > Sure I can do > my $SQL=<<"EOT"; > insert into blah (a,b) values (?,?) > EOT > > And do the execute thing. But if the number of columns changes from query > to query, and so on it might be less convenient to use placeholders. > > If it really can't be done, then yeah I'll use placeholders. But it seems > strange if you can't. > > Cheerio, > Link. > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org >
Hey thanks! I'll try that, sounds promising. Haven't seen this mentioned in the docs either. So even if it works, would probably have to try to get the DBI/DBD people to make an official decision on this undocumented feature. I wanted to check first before bothering them directly. I was starting to wonder if I'm weird and the only one to be bothered by this issue. Cheerio, Link. OK so I'm probably still weird. :). At 02:15 PM 9/27/01 -0600, Keary Suska wrote: >I think you are supposed to escape placeholder markers by doubling them: ?? >should be effectively changed to '?' before passed to PG. I haven't come >across this yet, but I think that's the correct (although undocumented) >syntax. > >Keary Suska >Esoteritech, Inc. >"Leveraging Open Source for a better Internet"
If that doesn't work, I would like to know, to avoid any hidden gotchas. I suppose it is considered uncommon to need this since most search techniques do not include punctuation. However, if one were to make extensive use of regex searches, this issue could occur often and engender much hair pulling. Keary Suska Esoteritech, Inc. "Leveraging Open Source for a better Internet" > From: Lincoln Yeoh <lyeoh@pop.jaring.my> > Date: Fri, 28 Sep 2001 23:15:28 +0800 > To: Keary Suska <hierophant@pcisys.net>, PostgreSQL > <pgsql-general@postgresql.org> > Subject: Re: Quoting '?' placeholder in Perl's DBD::Pg? > > Hey thanks! I'll try that, sounds promising. > > Haven't seen this mentioned in the docs either. So even if it works, would > probably have to try to get the DBI/DBD people to make an official decision > on this undocumented feature. I wanted to check first before bothering them > directly. > > I was starting to wonder if I'm weird and the only one to be bothered by > this issue. > > Cheerio, > Link. > > OK so I'm probably still weird. :). > > At 02:15 PM 9/27/01 -0600, Keary Suska wrote: >> I think you are supposed to escape placeholder markers by doubling them: ?? >> should be effectively changed to '?' before passed to PG. I haven't come >> across this yet, but I think that's the correct (although undocumented) >> syntax. >> >> Keary Suska >> Esoteritech, Inc. >> "Leveraging Open Source for a better Internet" > >