pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Boes <jboes@nexcerpt.com>
To: pgsql-sql@postgresql.org
Subject: Re: escape single quote in INSERT command
Date: Fri, 22 Nov 2002 13:38:17 -0500
Message-ID: <arltil$2l7q$1@news.hub.org> (raw)
References: <27ad91d2.0211220500.19633b93@posting.google.com>

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



view thread (8+ messages)  latest in thread

Message-ID: <arltil$2l7q$1@news.hub.org>
Permalink:  ../arltil$2l7q$1@news.hub.org/
Also on:    postgresql.org/message-id/arltil$2l7q$1@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jboes@nexcerpt.com
  Subject: Re: escape single quote in INSERT command
  In-Reply-To: <arltil$2l7q$1@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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