freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
[freetds] Using numeric types with Sybase ASE 12.5
- From: Teemu Torma <teemu AT torma.org>
- To: freetds AT lists.ibiblio.org
- Subject: [freetds] Using numeric types with Sybase ASE 12.5
- Date: Thu, 7 Oct 2004 17:19:03 +0200
I tried recent (hmm, mandrake contrib package 0.62.4, whatever that is)
freetds with an application that has used Sybase OpenClient for years.
It appears to work fine after couple of minor patches to freetds when
usinc numeric types. Browsing the current CVS appears to do the same
thing, so I guess these are still current.
The first is when receiving a numeric type from the server, the actual
data length was forced to numeric data size instead of the actual size.
Since the byte array is received MSB first, the actual length is
crucial to know where LSB is. The following patch seems to correct the
problem in this case (might be mangled due to line wrapping) and
matches the Sybase behavior.
diff -ru freetds-0.62.4.old/src/tds/token.c
freetds-0.62.4/src/tds/token.c
--- freetds-0.62.4.old/src/tds/token.c 2004-04-06 10:34:03.000000000
+0200
+++ freetds-0.62.4/src/tds/token.c 2004-10-07 15:35:28.821401263
+0200
@@ -1935,7 +1935,7 @@
tds_get_n(tds, num->array, colsize);
/* corrected colsize for column_cur_size */
- colsize = sizeof(TDS_NUMERIC);
+ colsize += sizeof(num->precision) + sizeof(num->scale);
if (IS_TDS7_PLUS(tds)) {
tdsdump_log(TDS_DBG_INFO1, "%L swapping numeric
data..\
.\n");
tds_swap_datatype(tds_get_conversion_type(curcol->colu\
mn_type, colsize), (unsigned char *) num);
The second problem is the sending of numeric types as RPC parameter.
tds_put_data_info attempts to send column_prec as the precision, but
that is initialized to zero when sending RPC params, making the Sybase
server to complain about arithmetic error. I made the following hack
to dig it from the numeric parameter given in bind--it works at least
in this case (we use only RPC to communicate with the server).
I doubt this is right, but I guess someone has a better idea how to make
this work.
--- freetds-0.62.4.old/src/tds/query.c 2004-02-25 08:15:39.000000000
+0100
+++ freetds-0.62.4/src/tds/query.c 2004-10-07 16:45:14.363558236
+0200
@@ -1342,6 +1342,7 @@
tds_put_params(TDSSOCKET * tds, TDSPARAMINFO * info, int flags)
{
int i, len;
+ TDSCOLINFO *param;
/* column descriptions */
tds_put_byte(tds, TDS5_PARAMFMT_TOKEN);
@@ -1354,6 +1355,13 @@
tds_put_smallint(tds, info->num_cols);
/* column detail for each parameter */
for (i = 0; i < info->num_cols; i++) {
+ param = info->columns[i];
+ if (is_numeric_type(param->column_type)) {
+ TDS_NUMERIC *src;
+ src = (TDS_NUMERIC *)
&(info->current_row[param->colum\
n_offset]);
+ param->column_prec = src->precision;
+ }
+
/* FIXME add error handling */
tds_put_data_info(tds, info->columns[i], flags);
}
@@ -1515,6 +1523,12 @@
for (i = 0; i < num_params; i++) {
param = params->columns[i];
+ if (is_numeric_type(param->column_type)) {
+ TDS_NUMERIC *src;
+ src = (TDS_NUMERIC *)
&(params->current_row[pa\
ram->column_offset]);
+ param->column_prec = src->precision;
+ }
+
/* TODO check error */
tds_put_data_info(tds, param,
TDS_PUT_DATA_USE_NAME);
Teemu
- [freetds] Using numeric types with Sybase ASE 12.5, Teemu Torma, 10/07/2004
Archive powered by MHonArc 2.6.24.