pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
handling special characters in sql strings
2+ messages / 2 participants
[nested] [flat]

* handling special characters in sql strings
@ 2001-03-19 12:14  Markus Wagner <wagner@imsd.uni-mainz.de>
  0 siblings, 1 reply; 2+ messages in thread

From: Markus Wagner @ 2001-03-19 12:14 UTC (permalink / raw)
  To: pgsql-sql

Hi,

I need to insert and retrieve strings containing special characters (e.
g. "'") and I want a C function to prepare my strings automatically. Is
it ok to just insert a "\" before each special character? And what range
of characters will need this handling?

Thanks,

Markus



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

* Re: handling special characters in sql strings
@ 2001-03-19 14:58  tjk@tksoft.com <tjk@tksoft.com>
  parent: Markus Wagner <wagner@imsd.uni-mainz.de>
  0 siblings, 0 replies; 2+ messages in thread

From: tjk@tksoft.com @ 2001-03-19 14:58 UTC (permalink / raw)
  To: wagner@imsd.uni-mainz.de; +Cc: pgsql-sql

Markus,

Here are comments from a C function which does what you
need. You won't have the regex functions available, so the
function itself would be useless. You get the idea though.


1. First change backslashed backslashes back to single backslashes. 

2. Find backslash single quote combinations (i.e. "\'") and convert them to 
   single quotes (i.e. "'"). Use a while loop to be sure.
   Now there should be no single quotes preceded by backslashes left.

3. Find all backslashes and convert them to double backslashes.
   Now all characters preceded by a backslash should be in their
   original state, while all backslashed single quotes are
   just single quotes. E.g. "\1ABC'ABC\2\q"

5. Find all single quotes and backslash them.
   (Note: There are no single quotes preceded by a backslash, so
   it is not possible to have a backslash which would hide a
   backslash preceding a single quote.)

That's it.



Troy


> 
> Hi,
> 
> I need to insert and retrieve strings containing special characters (e.
> g. "'") and I want a C function to prepare my strings automatically. Is
> it ok to just insert a "\" before each special character? And what range
> of characters will need this handling?
> 
> Thanks,
> 
> Markus
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 




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


end of thread, other threads:[~2001-03-19 14:58 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-19 12:14 handling special characters in sql strings Markus Wagner <wagner@imsd.uni-mainz.de>
2001-03-19 14:58 ` tjk@tksoft.com <tjk@tksoft.com>

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