Re: [SQL] Odd characters in inserted data...

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: PETER PAULY <ppauly(at)usa(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [SQL] Odd characters in inserted data...
Date: 1998-11-30 17:09:28
Message-ID: l03110701b288800a97e0@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces pgsql-sql

(Redirected to the INTERFACES list, which is more appropriate for this than
the SQL list)

At 18:09 +0200 on 30/11/98, Tom Lane wrote:

> This is a lot easier to get right in C++, where the function can return
> a temporary string object that will get deallocated automatically after
> use. In C the most reasonable way to proceed is to have SQLstring
> return a pointer to a static area, which means you can't invoke
> SQLstring more than once per sprintf :-(. You end up with klugery like
> sprintf(query, "update tablename set field1 = %s,",
> SQLstring(field1));
> sprintf(query + strlen(query), " field2 = %s where ...",
> SQLstring(field2), ...);
> Ugh. It works (I've done it a lot), but it's not pretty, and it's
> easy to get wrong.

If it were me, I'd malloc the pointer inside the function, and explicitly
free it after sprintf'ing. If you want to be more elegant (in C???), you
can malloc it in advance, pass the malloced pointer to the function and
free it afterwards, to make it consistent with the way str functions work.

I should think this was a good function to add to libpq. At least, the part
that does the quoting, maybe without the other frills. It's a function
*everybody* who uses C will use, and it makes more sense to have it
centralized, so if characters other than backslash and quote need to be
escaped, it will be done within the central source, and not break
everybody's programs.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Dallas Hockley 1998-11-30 18:59:25 1.2 JVM and such
Previous Message Jan Wieck 1998-11-30 17:08:29 Re: [SQL] Re: Odd characters in inserted data...

Browse pgsql-sql by date

  From Date Subject
Next Message advance 1998-11-30 18:13:41 Select the duplicated rows ?
Previous Message Jan Wieck 1998-11-30 17:08:29 Re: [SQL] Re: Odd characters in inserted data...