Re: libpq / SQL3
Peter Eisentraut <peter_e@gmx.net>
From: Peter Eisentraut <peter_e@gmx.net>
To: Chris Bitmead <chris@bitmead.com>
Cc: Postgres Hackers List <hackers@postgresql.org>
Date: 2000-07-09T21:29:35Z
Lists: pgsql-hackers
Chris Bitmead writes:
> Can anybody (i.e Peter :) provide any insight on how the SQL99 API
> handles variable length datatypes where you don't know the length in a
> particular tuple in advance?
Clause 5.9 "Character string retrieval" might provide some insight,
although it's probably not what you had hoped for.
T = target (where you want to store it)
L = length of value
V = the value
b) Otherwise, let NB be the length in octets of a null
terminator in the character set of T.
Case:
i) If L is not greater than (TL-NB), then the first (L+NB)
octets of T are set to V concatenated with a single
implementation-defined null character that terminates a
C character string. The values of the remaining characters
of T are implementation-dependent.
ii) Otherwise, T is set to the first (TL-NB) octets of V
concatenated with a single implementation-defined null
character that terminates a C character string and a
-=> completion condition is raised: warning - string data,
-=> right truncation.
So highly robust applications would have to call DescribeCol before any
GetData or similar call in order to allocate a sufficiently sized buffer.
Which is a problem if DescribeCol doesn't know about user-defined data
types.
But remember that SQL does not provide any variable-without-limit length
types, so there is theoretically never any uncertainty about what kind of
buffer to allocate if you know the query.
--
Peter Eisentraut Sernanders väg 10:115
peter_e@gmx.net 75262 Uppsala
http://yi.org/peter-e/ Sweden