HELP NEEDED FOR SQL SERVER DB-LIBRARY :- ERROR WHILE RETRIEVING/CONVERTED DECIMAL DATA 
Author Message
 HELP NEEDED FOR SQL SERVER DB-LIBRARY :- ERROR WHILE RETRIEVING/CONVERTED DECIMAL DATA

I am facing a problem with the retrieval of decimal values
from an MS-SQLSERVER database.
I have a table with a column of type decimal with a precision
of 28 and scale 0, I am using the following C program
with the SQL SERVER DB-Library 6.0  interface.
Once the program is executed , It appears that the numbers with
around 16 significant(non decimal) digits are
retrieved/converted correctly.
I am not sure whether the truncation of the numbers occurs
during the retrieval time  or it is done by the dbconvert
routine, I have not been able to gather much information
about the limitations of the dbconvert routine from the SQL
SERVER BOOKS ONLINE HELP.

Could someone suggest a method to overcome this problem ?.

Thanks in anticipation
Armstrong Monteiro

TABLE NAME :- newtab
Column name & type :- decimaldata(28,0)

Database Column Values as retrieved through Microsoft ISQL/W
-------------------------

999999999999999999999
6666666666
66666666666666666666
11111111111111111111
99999999999999999
9999999999999999
8888888888888888888888888
77777777777777777

RESULTs of the DB-LIBRARY PROGRAM
----------------------------------

1000000000000000000000.0
6666666666.0
66666666666666664000.0
11111111111111111000.0
100000000000000000.0
9999999999999998.0
8888888888888888700000000.0
77777777777777776.0

------------------------------------------------

#define DBNTWIN32
#include <stdio.h>
#include <windows.h>
#include <sqlfront.h>
#include <sqldb.h>
// Forward declarations of the error handler and message handler.
int err_handler(PDBPROCESS, INT, INT, INT, LPCSTR, LPCSTR);
int msg_handler(PDBPROCESS, DBINT, INT, INT, LPCSTR, LPCSTR,
                LPCSTR, DBUSMALLINT);
main()
{
    PDBPROCESS  dbproc;    // The connection with SQL Server.
    PLOGINREC   login;     // The login information.
    DBCHAR      converted[100];
 int null_val,ret;
 DBDECIMAL decval;

    // Install user-supplied error- and message-handling functions.
    dberrhandle (err_handler);
    dbmsghandle (msg_handler);

    // Initialize DB-Library.
    dbinit ();

    // Get a LOGINREC.
    login = dblogin ();
    DBSETLUSER (login, "sa");
    DBSETLPWD (login, "sa123");

    // Get a DBPROCESS structure for communication with SQL Server.
    dbproc = dbopen (login, "armstrong");
 dbuse(dbproc,"datatypes");
    dbcmd (dbproc, "select decimaldata from newtab where decimaldata is
not null");
 dbcmd (dbproc, " ");

    // Send the command to SQL Server and start execution.
    dbsqlexec (dbproc);

    // Process the results.
    if (dbresults (dbproc) == SUCCEED)
    {

  dbbind (dbproc, 1, SRCDECIMALBIND, 0,(BYTE *)&decval);
  dbnullbind(dbproc,1,&null_val);
  for(;;)
  {

   do  ret=dbnextrow(dbproc);
   while(ret !=  NO_MORE_ROWS && ret != REG_ROW && ret != FAIL);

   if (ret == NO_MORE_ROWS)
   break;

      if(null_val != -1)
   {
    if(ret != FAIL)
    {

dbconvert(NULL,SQLNUMERIC,(BYTE*)&decval,sizeof(DBNUMERIC),SQLCHAR,converted,-1);

     printf ("%s\n", converted);
    }
    else
     printf("%s\n","FAILED CONVERSION");
   }
  }
 }

    // Close the connection to SQL Server.
    dbexit ();

    return (0);

Quote:
}

int err_handler (PDBPROCESS dbproc, INT severity,
    INT dberr, INT oserr, LPCSTR dberrstr, LPCSTR oserrstr)
{
    printf ("DB-Library Error %i: %s\n", dberr, dberrstr);
    if (oserr != DBNOERR)
    {
        printf ("Operating System Error %i: %s\n", oserr, oserrstr);
    }
    return (INT_CANCEL);

Quote:
}

int msg_handler (PDBPROCESS dbproc, DBINT msgno, INT msgstate,
    INT severity, LPCSTR msgtext, LPCSTR server,
    LPCSTR procedure, DBUSMALLINT line)
{
    printf ("SQL Server Message %ld: %s\n", msgno, msgtext);
    return (0);
Quote:
}



Wed, 12 Jul 2000 03:00:00 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. Help:copy decimal data from SQL server to file using db-library functions

2. bcp db-library problem: how to convert decimal to varchar correctly

3. HELP NEEDED FOR RETRIEVAL OF DECIMAL DATA IN USING DBLIBRARY

4. Need help on sql syntax to convert values from decimal to characters

5. need help converting a SQL Server DB to Access

6. DB-Library error 10040: DB-Library network communication layer not loaded

7. Error converting numeric data type to decimal?

8. begginner needs help with error - OLE DB Provider for SQL Server (0x80004005) Login failed

9. Data Type SQL Server7.0 need a non decimal 1 E 19 data type

10. Db Library error No SQl server connected to query

11. SQL Server 6.5 Error: DB-Library Process Dead - Connection Broken


 
Powered by phpBB® Forum Software