[unixODBC-support] numeric type scale problem

Scott Goodwin scott.goodwin at erxnetwork.com
Thu Jun 14 22:52:27 BST 2007


I am having problems retrieving a numeric column with the correct scale.

I have been successful in changing the precision, but the scale will not
change.  The column is defined as numeric(10,2). Below is my code.

 

 

      SQL_NUMERIC_STRUCT num;

      SQLINTEGER cbNum;

 

      rc = SQLPrepare(sqlStmt, (SQLCHAR *)

               "SELECT usual_and_customary from mtdme.claim WHERE
claim_id=104", SQL_NTS);

 

      if (!SQL_SUCCEEDED(rc)) printf ("*** ERROR *** SQLPrepare
fails\n");

 

      rc = SQLBindCol(sqlStmt, 1, SQL_C_NUMERIC, &num, sizeof(num),
&cbNum);

      if (!SQL_SUCCEEDED(rc)) printf ("*** ERROR *** SQLBindCol
fails\n");

 

      rc = SQLGetStmtAttr(sqlStmt, SQL_ATTR_APP_ROW_DESC, &sqlDesc, 0,
NULL);

      if (!SQL_SUCCEEDED(rc)) printf ("*** ERROR *** SQLGetStmtAttr
fails\n");

 

      rc = SQLSetDescField(sqlDesc, 1, SQL_DESC_TYPE,
(SQLPOINTER)SQL_C_NUMERIC, 0);

      if (!SQL_SUCCEEDED(rc)) printf ("*** ERROR *** SQLSetDescField
fails\n");

 

      rc = SQLSetDescField(sqlDesc, 1, SQL_DESC_PRECISION,
(SQLPOINTER)10, 0);

      if (!SQL_SUCCEEDED(rc)) printf ("*** ERROR *** SQLSetDescField
fails\n");

 

      rc = SQLSetDescField(sqlDesc, 1, SQL_DESC_SCALE, (SQLPOINTER)2,
0);

      if (!SQL_SUCCEEDED(rc)) printf ("*** ERROR *** SQLSetDescField
fails\n");

 

      rc = SQLExecute(sqlStmt);

      if (!SQL_SUCCEEDED(rc)) printf("*** ERROR *** SQLExecute
fails\n");

 

      rc = SQLFetch(sqlStmt);

      if (!SQL_SUCCEEDED(rc)) printf ("*** ERROR *** SQLFetch fails\n");

 

      SQLCloseCursor(sqlStmt);

 

      printf ("Raw value string: ");

      for (idx=0; idx<num.precision; idx++)

        printf ("%.2x ", num.val[idx]);

      val = (int *)num.val;

      printf("\nValue is %d, precision is %d, scale is %d\n", *val,
num.precision, num.scale);

      return 0;

 

The actual column value is 11.07.  The output from this code is below.

 

Raw value string: 0b 00 00 00 00 00 00 00 00 00 

 

Value is 11, precision is 10, scale is 0

 

I know I must be doing something wrong because isql returns 11.07.  

 

Any help is appreciated.
--------------------------------------------------------

This communication, including any attachments, may contain PRIVILEGED AND CONFIDENTIAL information and may be exempt from disclosure under applicable law. It is intended solely for the use of the individual or entity to which it is addressed and may be covered by copyrights, business partner confidentiality agreements, nondisclosures or other legally binding instruments. If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender. Thank you for your cooperation.

WARNING: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20070614/ac63c01f/attachment.html>


More information about the unixODBC-support mailing list