freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "James K. Lowden" <jklowden AT freetds.org>
- To: TDS Development Group <freetds AT lists.ibiblio.org>
- Subject: [freetds] tds_willconvert: new feature
- Date: Fri, 7 Dec 2007 00:27:53 -0500
If someone knows a standard way to answer the question:
"How big a buffer do I need to convert type X to a string?"
I'd like to hear about it. I looked and didn't find one.
We have three copies of tds_get_printable_size() (in dblib/bcp.c,
bsqldb.c, and fisql.c), all the same hack. I thought I'd try to improve
things a bit.
My solution: make tds_willconvert() (and thus dbwillconvert()) return a
length instead of just true/false. If the conversion would succeed and
the desttype is a variable-length type (e.g. SYBCHAR), the function
returns not 1, but the size of a buffer guaranteed to be big enough to
hold srctype if converted to a string.
I.e.
dbwillconvert(SYBINT1, SYBCHAR)
returns 3 instead of 1.
This would break code like:
if (dbwillconvert(...) == TRUE)
but I doubt much such code exists.
I think this is better than adding a whole new function.
Comments welcome....
--jkl
- [freetds] tds_willconvert: new feature, James K. Lowden, 12/07/2007
Archive powered by MHonArc 2.6.24.