Re: escape single quote in INSERT command - Mailing list pgsql-sql

From Jeff Boes
Subject Re: escape single quote in INSERT command
Date
Msg-id arltil$2l7q$1@news.hub.org
Whole thread Raw
List pgsql-sql
On Fri, 22 Nov 2002 08:00:01 -0500, Hunter wrote:


> I have a perl application for a registration form. I'd like to put
> escape characters in my insert command to accommodate for ' (i.e.
> O'Brien, O'Malley, etc). I've tired double quotes, single quotes, back
> tick, forward ticks, curly bracket, round brackets - no success.

Are you using the DBI interface?  That's the most straightforward way to
accomplish this.  Something like this:

use strict;
use DBI;
my $dbh = DBI->new(...see docs for details...);
$dbh->do(q|INSERT INTO mytable (col1) VALUES (?)|, undef, q|O'Malley|) or die $DBI::errstr;
$dbh->commit;

By using the '?' placeholder format for statements, you can pass in any
data without having to worry about quoting.

-- 
Jeff Boes                                      vox 616.226.9550 ext 24
Database Engineer                                     fax 616.349.9076
Nexcerpt, Inc.                                 http://www.nexcerpt.com          ...Nexcerpt... Extend your Expertise


pgsql-sql by date:

Previous
From: Jeff Boes
Date:
Subject: Re: calculating interval
Next
From: "Dan Langille"
Date:
Subject: Re: Trees: maintaining pathnames