From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: PETER PAULY <ppauly@usa.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [SQL] Odd characters in inserted data...
Date: Mon, 30 Nov 1998 19:09:28 +0200
Message-ID: <l03110701b288800a97e0@[147.233.159.109]> (raw)
In-Reply-To: <28740.912442162@sss.pgh.pa.us>
References: <199811300400.XAA12425@hub.org>
(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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: herouth@oumail.openu.ac.il, ppauly@usa.net, tgl@sss.pgh.pa.us
Subject: Re: [SQL] Odd characters in inserted data...
In-Reply-To: <l03110701b288800a97e0@[147.233.159.109]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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