[freetds] Determining buffer size when retrieving data

Michael Peppler mpeppler at peppler.org
Sun Aug 15 02:32:00 EDT 2004


On Sun, 2004-08-15 at 01:29, Magnus Bäck wrote:
> Is there a way to determine what destination buffer size is required
> when using dbdata()/dbconvert() or dbbind() to retrieve and convert
> column data of any type to string form? If not an exact number of bytes,
> at least a worst-case figure? Because with newer protocol versions,
> a CHAR or VARCHAR can hold >255 characters, yes? Trial-and-error with
> increasing buffer size is of course always available, but it'd be nice
> to avoid that method.

dbdatlen() should return the size of the buffer that dbdata() points to.

It of course does NOT return the size of the corresponding char buffer
needed if you convert a non char datatype to char. The DBD::Sybase and
Sybase::CTlib source has a function called display_dlen() (I think) that
I borrowed (stole ;-) from somewhere else (might be sqsh, or more likely
the Sybase samples) that returns maximum lengths for most datatypes.

Michael
-- 
Michael Peppler                              Data Migrations, Inc.
mpeppler at peppler.org                       http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short
or long term contract positions - http://www.peppler.org/resume.html




More information about the FreeTDS mailing list