pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to insert a string with single quotes in the text
3+ messages / 3 participants
[nested] [flat]

* How to insert a string with single quotes in the text
@ 2003-09-19 21:02 Louise Cofield <lcofield@box-works.com>
  2003-09-20 17:24 ` Re: How to insert a string with single quotes in the Oliver Elphick <olly@lfix.co.uk>
  2003-09-20 17:38 ` Re: How to insert a string with single quotes in the text Bruno Wolff III <bruno@wolff.to>
  0 siblings, 2 replies; 3+ messages in thread

From: Louise Cofield @ 2003-09-19 21:02 UTC (permalink / raw)
  To: pgsql-interfaces

Greetings:

 

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);

 

The insert blows up when it hits an item description that contains a
single quote in the text.  

 

Other than stripping the offending quote-marks from  the text prior to
processing, does anybody have any ideas how I can deal with this?

 

I appreciate all help!

 

Louise

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to insert a string with single quotes in the
  2003-09-19 21:02 How to insert a string with single quotes in the text Louise Cofield <lcofield@box-works.com>
@ 2003-09-20 17:24 ` Oliver Elphick <olly@lfix.co.uk>
  1 sibling, 0 replies; 3+ messages in thread

From: Oliver Elphick @ 2003-09-20 17:24 UTC (permalink / raw)
  To: Louise Cofield <lcofield@box-works.com>; +Cc: pgsql-interfaces

On Fri, 2003-09-19 at 22:02, Louise Cofield wrote:
> I am creating a Libpq program that reads a text file,
...
> The insert blows up when it hits an item description that contains a
> single quote in the text.  

You also have to look out for backslashes.

> Other than stripping the offending quote-marks from  the text prior to
> processing, does anybody have any ideas how I can deal with this?

The libpq library includes the function PQescapeString, as described in
the manual.

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "But my God shall supply all your need according to his
      riches in glory by Christ Jesus."     Philippians 4:19




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to insert a string with single quotes in the text
  2003-09-19 21:02 How to insert a string with single quotes in the text Louise Cofield <lcofield@box-works.com>
@ 2003-09-20 17:38 ` Bruno Wolff III <bruno@wolff.to>
  1 sibling, 0 replies; 3+ messages in thread

From: Bruno Wolff III @ 2003-09-20 17:38 UTC (permalink / raw)
  To: Louise Cofield <lcofield@box-works.com>; +Cc: pgsql-interfaces

On Fri, Sep 19, 2003 at 15:02:07 -0600,
  Louise Cofield <lcofield@box-works.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.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2003-09-20 17:38 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-09-19 21:02 How to insert a string with single quotes in the text Louise Cofield <lcofield@box-works.com>
2003-09-20 17:24 ` Re: How to insert a string with single quotes in the Oliver Elphick <olly@lfix.co.uk>
2003-09-20 17:38 ` Bruno Wolff III <bruno@wolff.to>

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