Re: Problem with character ' (single quote) in text fields - Mailing list pgsql-general

From Jordi
Subject Re: Problem with character ' (single quote) in text fields
Date
Msg-id a2jaq9$m6i$1@news.tht.net
Whole thread Raw
In response to Problem with character ' (single quote) in text fields  ("Jordi" <jordil2@hotmail.com>)
Responses Re: Problem with character ' (single quote) in text fields  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
Yes, this is the method I use but the problem is that I need to parse/change
every text.  For example, if I have a struct Person with a char *Firstname =
"D'Innocenzo" I can not use:

  sprintf (output, "select X where FirstName=%s and Description=%s",
Person.Firstname, Person.Description)

so I need a lot of temporary buffers just to create the SELECT... and some
of the structures I need to dump to the database have lots of text fields...

Anyway, it is not a big problem but I tried to find a workaround  but I
think it doesn't exist.

Jordi


"Asim Khan" <goaway@byteme.com> wrote in message
news:zB638.55451$zk4.12540147@typhoon.columbus.rr.com...
> Try this...where ever you have single quote, replace it with two single
> quotes.
>
> Example:
>
> 'John's cat is sitting on the table' will become 'John''s cat is sitting
on
> the table'
>
> AK
>
> "Jordi" <jordil2@hotmail.com> wrote in message
> news:a2gqr0$968$1@news.tht.net...
> > Hi,
> >
> > I have an old problem using the single quote (') character in text field
> > because Postgresql thinks it is the "end of text" character.   The '
> > characther is used a lot in my language.  As a workaround I'm parsing
the
> > fields duplicating the ' characters inside the text but this is a bad
> > solution because:
> >
> >    Assuming field1 and field2 are text field, as I usually use in my
> > programs something like :
> >     ...
> >     sprintf (auxstr, "SELECT field WHERE field=%s AND field2=%s" ,
> vartext1,
> > vartext2);
> >    ..
> >
> >   As vartext1 and vartext2 can contain the ' so I need to create
> char[size]
> > variables to save the output of my "duplicate ' characters"  function.
> > Something like:
> >
> >   char[SIZE] vartext1;
> >   char[SIZE] vartext2;
> >
> >   DuplicateSingleQuote (OriginalText1, vartext1); //vartext1 is the new
> > valid text to insert
> >   DuplicateSingleQuote(OriginalText2, vartext2);
> >   sprintf(...)
> >
> > So the code is full of temporary chart[] variables.
> >
> > Is there any way to change the start/end of Text field character or do
you
> > know a better workaround to avoid parsing/changing all the text fields
> just
> > in case they contain the single quote ( ') character??.
> >
> > Best regards,
> >
> > Jordi
> >
> >
>
>



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: PostgreSQL Licence: GNU/GPL
Next
From: Lincoln Yeoh
Date:
Subject: Re: PostgreSQL Licence: GNU/GPL