Skip to Content.
Sympa Menu

freetds - RE: [freetds] Numeric data types

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Thompson, Bill D (London)" <bill_d_thompson AT ml.com>
  • To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] Numeric data types
  • Date: Wed, 10 Dec 2003 16:17:09 -0000

Hi David,

You are doing something a BIT strange.
What are you going to do with a CS_NUMERIC in your program ? You can't print
it out, you can't do calculations on it....

You say "I DON'T WANT TO HARD CODE THE datafmt BECAUSE IT SHOULD BE DYNAMIC
AS I DON'T KNOW AHEAD THE DATA TYPE OF RESULT"

...but you know enough about it to declare a CS_NUMERIC in your program, and
presumably pass the address of that CS_NUMERIC to ct_bind().

The underlying issue is that NUMERICs on the database can vary in length
(depending on the precision and scale of the numeric).
Our CS_NUMERIC data structure is large enough to hold the biggest.

I'd be reluctant to go messing around with the numeric handling in freeTDS -
it's a can of worms!

The simple way round your problem is to set the datafmt.maxlength in your
call to ct_bind() as sizeof(CS_NUMERIC).
That reflects the truth, i.e. the variable you have assigned in ct_bind() to
receive the data is a CS_NUMERIC.

Bill



> -----Original Message-----
> From: David Nsengiyumva [SMTP:davidn AT finsolutions.co.za]
> Sent: 10 December 2003 16:06
> To: freetds AT lists.ibiblio.org
> Subject: [freetds] Numeric data types
>
>
> THANX BILL,
>
> > I can kind of see where the problem lies, but can you tell me ...
> >
> > a) what is the host variable you have bound the numeric column to ? is
> it
> a
> > CS_NUMERIC type ?
>
> YES IT IS.....CS_NUMERIC
>
> > b) how have you set up the DATAFMT structure (third argument to
> ct_bind()
> > when you bind the numeric columns ?
> >
> I CALL FIRST 'ct_results' AND THEN I DO CALL 'ct_describe' WITH A
> DECLARED
> datafmt. THE 'ct_describe' FUNCTION
> SETS THE MEMBERS OF THE datafmt AND THEN I USE IT AS A THIRD
> PARAMETER TO
> THE 'ct_bind' FUNCTION.
> I DON'T WANT TO HARD CODE THE datafmt BECAUSE IT SHOULD BE DYNAMIC
> AS I
> DON'T KNOW AHEAD THE DATA TYPE OF
> RESULT. THIS SHOULD BE ACHIEVED THOUGHT WITH THE 'ct_describe'
> FUNCTION.
>
> LET ME KNOW WHAT YOU THINK AND THANX A LOT FOR YOUR RESPONSE
>
> > Bill
> >>> -----Original Message-----
> >>> From: David Nsengiyumva [SMTP:davidn AT finsolutions.co.za]
> >>> Sent: 10 December 2003 14:00
> >>> To: freetds AT lists.ibiblio.org
> >>> Subject: [freetds] Numeric data types
> >>>
> >>> Hi there,
> >>>
> >>> I am having problems with SQL queries that return numeric and date
> data
> >>> types. First of all I am accessing a MS SQL Server 2000 from a Win2000
> >>> machine and I am using FreeTDS-0.61.2.
> >>> The Problem happens in the 'cs_convert' function. The 'if (src_type ==
> >>> desttype)' succeed and the switch statement 'switch(desttype)' goes
> to
> >>> the
> >>> SYBBITN, SYBNUMERIC, SYBDECIMAL case and since 'src_len > destlen'
> then
> >>> the
> >>> function returns CS_FAIL. Basically src_len=35 and destlen=17.
> >>>From what I can think of is that when I receive data (fecthing data) I
> >>> read
> >>> 17 bytes (that's where destlen=17 comes from) but the allocated space
> is
> >>> 35
> >>> (from the struct tdsnumeric)
> >>>
> >>> typedef struct tdsnumeric
> >>> {
> >>> unsigned char precision;
> >>> unsigned char scale;
> >>> unsigned char array[33]; // why this ?????
> >>> } TDS_NUMERIC;)
> >>>
>
> _______________________________________________
> FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds





Archive powered by MHonArc 2.6.24.

Top of Page