Handling Exact Numeric Values
Exact numeric types sometimes hold values that cannot be converted into integer values. They can be turned into floating-point values but with a loss in significant digits. Rogue Wave DB Link allows you to send or retrieve such values as character strings or objects to avoid that loss of precision.
Numeric As String
Very large numeric or decimal values can be handled as strings to preserve precision. To do so, turn on the
numeric as string feature before you use the string-dedicated Rogue Wave DB Link member functions
IldRequest::setParamValue and
IldRequest::getColStringValue.
To turn on the feature:
{
// Data selection
request->setStringNumericUse(IlTrue);
}
To send huge exact numeric values as strings:
{
request->setParamValue("9876543210987.654321098", 0);
}
To retrieve such huge numeric values as strings:
{
// Print selected item values.
do {
if (!request->fetch())
IldDisplayError("Fetch failed:", request);
else if (request->hasTuple()) {
cout << request->getColStringValue(0) << "\t"
<< request->getColDateValue(1) << endl;
}
} while (request->hasTuple());
}
Numeric As Object
To gain full independence from the RDBMS server and client host localization, an application can use the
numeric as object feature to handle values of data types
DECIMAL and
NUMERIC. The feature is enabled by a call to the function
IldIldBase::setNumericUse with an argument value of
IlTrue.
When using Oracle, due to the existence of the numeric type, NUMBER, numeric values are handled as objects as soon as that feature is turned on.
An
IlNumeric object can be converted to and from the type
IlInt but its value can also be accessed as a character string, which will be built following the
C locale (no thousands separator and a dot as the decimal separator).
To turn on the feature:
{
// Use numeric objects
request->setNumericUse(IlTrue);
}
To send numeric object values:
{
IlNumeric* num = new IlNumeric;
num->set("987654321.654321");
request->setParamValue(num, 0);
}
{
// Print selected item values.
do {
if (!request->fetch())
IldDisplayError("Fetch failed:", request);
else if (request->hasTuple()) {
IlNumeric num = request->getColNumericValue(0);
if (!request->isErrorRaised()) {
char numValue[ILD_MAX_NUM_LEN];
num.get(numValue, ILD_MAX_NUM_LEN);
cout << numValue << "";
}
}
} while (request->hasTuple());
}
Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.