Re: libpq / SQL3 - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: libpq / SQL3
Date
Msg-id Pine.LNX.4.21.0007091825340.10288-100000@localhost.localdomain
Whole thread Raw
In response to Re: libpq / SQL3  (Chris Bitmead <chris@bitmead.com>)
List 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
Lis not greater than (TL-NB), then the first (L+NB)        octets of T are set to V concatenated with a single
implementation-definednull 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
concatenatedwith 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



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: es_BaseId/cs_base_id seem to be dead code?
Next
From: Chris Bitmead
Date:
Subject: Re: libpq / SQL3