Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Oracle 10.2 ODBC driver: SQLDescribeCol returns too small a precision for numeric expressions

Oracle 10.2 ODBC driver: SQLDescribeCol returns too small a precision for numeric expressions

From: Wolfram Roesler <wr_at_spam.la>
Date: Wed, 25 Jul 2007 12:26:57 +0000 (UTC)
Message-ID: <Xns997892FCC103Bwrgrpde@news.albasani.net>


Hello,

I hope this is the correct newsgroup to ask about the Oracle ODBC driver but I didn't find any better place for this.

Short story: It seems that the Oracle 10.2 ODBC driver returns wrong (too small) precision values for expressions computed in SELECT statements.

Long story: I have an application that submits queries to an Oracle database using the SQLExecDirect/SQLFetch functions. The query contains both database columns and expressions, like

	SELECT colname,
	  DECODE(col2,0,0,col1/col2)
	FROM tablename
	WHERE ...

After SQLExecDirect I'm calling SQLDescribeCol for each column and expression in the query to determine the maximum size of the expected result:

	for(int ColId=...)
	{
		UCHAR ColName[50+1];
		SWORD ColNameLen=0,SQLType=0,Scale=0,Null=0;
		UDWORD Prec=0;
		rc = SQLDescribeCol(hstmt,ColId,
			ColName,sizeof(ColName),&ColNameLen,
			&SQLType,&Prec,&Scale,&Null);
		...
	}

Then, I allocate a buffer of size Scale+Prec+2 bytes and call SQLBindCol to tell ODBC about the buffer size and address. This has worked flawlessly for years and across many versions of the Oracle server, client, and ODBC driver.

Because there's a division, the computed expression has up to 16 digits after the decimal point. This is fine since SQLDescribeCol returns a precision of 38 so my buffer is large enough for the result.

Now, with the 10.2 ODBC driver, SQLDescribeCol returns a precision of 15 for that same expression. I thus allocate a buffer of 17 bytes, but the expression returned by Oracle is 18 bytes long (one digit before the decimal point, the decimal point itself, and 16 digits following). So, the result doesn't fit into the buffer, and the query aborts with the error "SQLSTATE=01004: [Oracle][ODBC]String data, right truncated".

The problem occurs with the Oracle ODBC drivers 10.2.0.1 and 10.2.0.3, which seems to be the latest 10.2 driver available from Oracle. It works fine with the 10.1.0.2 driver.

Is this a bug in the 10.2 ODBC driver, or am I doing something wrong? In either case, what can be done about it?

My platform is Visual Studio 7.0 on Windows XP. The database version is 10.2.

Thanks for any help
W. Rösler Received on Wed Jul 25 2007 - 07:26:57 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US