Skip site navigation (1) Skip section navigation (2)

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] (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-interfacespgsql-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

pgsql-interfaces by date

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

pgsql-sql by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group