Re: How to insert a string with single quotes in the text

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Louise Cofield <lcofield(at)box-works(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: How to insert a string with single quotes in the text
Date: 2003-09-20 17:38:47
Message-ID: 20030920173847.GA17807@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Fri, Sep 19, 2003 at 15:02:07 -0600,
Louise Cofield <lcofield(at)box-works(dot)com> wrote:
>
> I am creating a Libpq program that reads a text file, and inserts values
> into a Postgres table. An example of my insert statement looks like
> this:
>
> SPRINTF(str, "INSERT INTO itm_table (itm_num, itm_desc) values ('%s',
> '%s');", sitmnum, sitmdesc);
>
> Other than stripping the offending quote-marks from the text prior to
> processing, does anybody have any ideas how I can deal with this?

Scan the input and put backslashes in front of backslashes and single quotes.

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Michael Palmer 2003-09-21 03:35:19
Previous Message Oliver Elphick 2003-09-20 17:24:08 Re: How to insert a string with single quotes in the