Re: Problem with character ' (single quote) in text fields

From: "Jordi" <jordil2(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with character ' (single quote) in text fields
Date: 2002-01-22 09:27:24
Message-ID: a2jaq9$m6i$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)byteme(dot)com> wrote in message
news:zB638(dot)55451$zk4(dot)12540147(at)typhoon(dot)columbus(dot)rr(dot)com(dot)(dot)(dot)
> 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(at)hotmail(dot)com> wrote in message
> news:a2gqr0$968$1(at)news(dot)tht(dot)net(dot)(dot)(dot)
> > 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
> >
> >
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lincoln Yeoh 2002-01-22 09:55:20 Re: PostgreSQL Licence: GNU/GPL
Previous Message Tom Lane 2002-01-22 08:50:09 Re: [GENERAL] PostgreSQL Licence: GNU/GPL