Re: Big numbers



On Jan 13, 11:56 am, Keith Thompson <ks...@xxxxxxx> wrote:
marc <marc.tes...@xxxxxxxxxxxx> writes:
On 13 jan, 20:17, Lew Pitcher <lpitc...@xxxxxxxxxxxx> wrote:
However, the onus is on the OP to determine what "Decimal" means.
Additionally, the documentation on his DBMS API would/should provide
information on how the API converts database values ("Decimal", etc.) to C
datatypes, and what C datatypes the API will populate.

Decimal is a standard Sybase data type.
It's converted into C double data type.

Finally, this is the information we needed.

Except that it's not correct.
The data is returned as the type you request. You can bind to char[]
or double or a decimal struct or any other type that allows for
conversion.
Further the conversion to double will not work 99.x% of the time if
the precision is greater than DBL_DIG (mathematically, it will fail
for most cases though pragmatically it will often succeed). However,
to bind a {for instance} decimal 18.2 field to a double probably
constitutes criminal negligence. [Imagine losing $1000 every time you
perform a transaction and you can imagine why the customers will be
non-plussed].

Is there a way to get the value in something other than a double?  C
has a built-in type "long double" that's typically bigger than double,
but it's still probably not big enough to represent
33748440199875750.25 exactly.  

You can bind to whatever you like. If he is using the native API, he
can do this:
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.mainframeconnect_12.6.occprc/html/occprc/X14642.htm

When using ODBC binding, this is what they would do:
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.sdk_12..5.1.aseodbc/html/aseodbc/CACFDIGH.htm
(as you can see the recommended bind types for NUMERIC or DECIMAL is
to a NUMERIC struct or a char string).

A numeric representation will need at
least 57 bits for this particular number, assuming 2 bits for the
fractional part -- plus a sign bit if you want to be able to represent
negative numbers, and some number of exponent bits if you're using a
floating-point representation.

This is a numeric struct as defined by the ODBC standard:

/* internal representation of numeric data type */
#if (ODBCVER >= 0x0300)
#define SQL_MAX_NUMERIC_LEN 16
typedef struct tagSQL_NUMERIC_STRUCT
{
SQLCHAR precision;
SQLSCHAR scale;
SQLCHAR sign; /* 1 if positive, 0 if negative */
SQLCHAR val[SQL_MAX_NUMERIC_LEN];
} SQL_NUMERIC_STRUCT;
#endif /* ODBCVER >= 0x0300 */


If your API can't provide the value other than as a double, then you
may be out of luck; if the DMBS won't export the value with full
precision, then there's nothing you can do in C to retrieve the lost
information.

If you can get the value as a string, then you can do some processing
on that.  For example, as jacob suggested, the integer type "long
long" is guaranteed to be at least 64 bits (63 value bits plus 1 sign
bit); you'll just have to keep track of the scaling yourself.  If you
might have values that won't fit in 64 bits, then C's built-in types
aren't enough; you might consider an arbitrary precision artithmetic
package, such as GNU's GMP (Google it).  But before you can use
anything like that, you'll need to get the information out of the DBMS
and into your C program, and you haven't told us how that can be done.

I guess that what the OP should do is:
1. Identify the type of data collection he wants to perform:
A. Native access e.g. via CT-Lib
B. OLEDB access using an OLEDB provider
C. ODBC access using an ODBC driver
D. .NET access using a .NET provider
E. JDBC access using a JDBC driver

Once the OP has settled on an API, then his questions will have
meaning in a group dedicated to that topic.
Database binding tends to be very specific either to the database (in
the case of native binding) or to the access method (in the case of
standards based binding).

The OP can definitely collect the data without loss. I suspect that
he should ask experts on database data binding if he wants accurate
answers.
.



Relevant Pages

  • Re: Database Query
    ... A standards based API call (such as ODBC, OLEDB, etc.) ... How to accomplish #1 will depend on your database. ...
    (comp.lang.c)
  • Re: DBD for SQL Server?
    ... >>Windows uses the Open Database Connectivity ... > Will be using the same api syntax regarless the ... > The database driver you are dealing with behind DBI. ... an ODBC driver on the machine. ...
    (perl.beginners)
  • Re: For the AdaOS folks
    ... API that says create/delete an integer? ... >>as an Ada binding, I can do another registry query and get the ... libraries can strengthen the typing of the Ada interface. ...
    (comp.lang.ada)
  • Re: 3vl 2vl and NULL
    ... > or API to the stored data is of primarily interest to me. ... >> designers are capable of defining the world for application programmers, ... I am more of an end-user (aka developer) looking to those ... But building an enterprise database is a lot more than succeeding at a lot ...
    (comp.databases.theory)
  • Re: Fastest Fetch for Client Application
    ... We ended up with ODBC but probably from a different start than you. ... provided the same API as the BDE but used ADO/OLEDB under the covers. ... as you said, you're only reading. ... any new features going into the DB server will most ...
    (microsoft.public.sqlserver.odbc)

Loading