Data fetched from a database into a DBTools.h++ application may be stored internally by DBTools.h++ in instances of the RWDBValue class. Most applications can ignore RWDBValue and fetch data directly into C++ variables. If you do need to use it, Table 1 shows how ODBC datatypes are mapped into RWDBValues, and lists the C++ class or datatype appropriate for each ODBC datatype.
ODBC Datatype | RWDBValue::ValueType | C++ Datatype |
SQL_BIGINT; SQL_NUMERIC; SQL_DECIMAL |
Decimal |
RWDecimalPortable |
SQL_BINARY; SQL_VARBINARY; SQL_LONGVARBINARY |
Blob |
RWDBBlob |
SQL_BIT |
UnsignedChar |
unsigned char |
SQL_DOUBLE; SQL_FLOAT |
Double |
double |
SQL_INTEGER |
Long |
long int |
SQL_INTERVAL* |
Duration |
RWDBDuration |
SQL_LONGVARCHAR; SQL_VARCHAR; SQL_CHAR |
String |
RWCString |
SQL_REAL |
Float |
float |
SQL_SMALLINT |
Short |
short int |
SQL_TYPE_DATE |
Date |
RWDate |
SQL_TYPE_TIME |
DateTime |
RWDBDateTime |
SQL_WLONGVARCHAR; SQL_WVARCHAR; SQL_WCHAR |
WString |
RWWString |
When an application uses DBTools.h++ to create a table through ODBC, RWDBValue::ValueTypes are used to define the table's schema. These RWDBValue::ValueTypes need to be mapped to a type name specific to the underlying database. Here is how that is done.
First, an ODBC SQL type associated with RWDBValue::ValueType must be found. This is complicated by the fact that not all drivers support all possible ODBC SQL types. For example, Intersolv's SQL Driver supports many different numeric types while the Intersolv Paradox Driver supports only the SQL_DOUBLE numeric type. Table 2 shows how DBTools.h++ chooses an ODBC SQL type to associate with a particular RWDBValue::ValueType:
RWDBValue::ValueType | Possible ODBC Datatypes: the type chosen is the first type supported by the underlying driver |
Blob |
If length>255 or length = 0, {SQL_LONGVARBINARY, SQL_VARBINARY, SQL_BINARY, SQL_LONGVARCHAR}; otherwise, {SQL_VARBINARY,SQLBINARY, SQL_LONGVARBINARY, SQL_LONGVARCHAR) |
Char, UnsignedChar |
{SQL_TINYINT, SQL_SMALLINT, SQL_INTEGER, SQL_DECIMAL} |
Date |
{SQL_TYPE_DATE, SQL_TYPE_TIMESTAMP} |
DateTime |
{SQL_TYPE_TIMESTAMP, SQL_TYPE_DATE} |
Decimal |
{SQL_DECIMAL, SQL_NUMERIC, SQL_DOUBLE} |
Double |
{SQL_DOUBLE, SQL_FLOAT, SQL_DECIMAL} |
Duration |
{SQL_INTERVAL_SECOND} |
Float |
{SQL_REAL, SQL_DOUBLE, SQL_FLOAT, SQL_DECIMAL} |
Int, UnsignedInt |
{SQL_SMALLINT, SQL_INTEGER, SQL_REAL, SQL_DOUBLE, SQL_FLOAT, SQL_DECIMAL} |
Long, UnsignedLong |
{SQL_INTEGER, SQL_REAL, SQL_DOUBLE, SQL_FLOAT, SQL_DECIMAL} |
Short, UnsignedShort |
{SQL_SMALLINT, SQL_INTEGER, SQL_REAL, SQL_DOUBLE, SQL_FLOAT, SQL_DECIMAL} |
String |
If length is > 254 or length = 0, {SQL_LONGVARCHAR}; otherwise, {SQL_VARCHAR, SQL_CHAR, SQL_LONGVARCHAR} |
WString |
If length is > 254 or length = 0, {SQL_WLONGVARCHAR}; otherwise, {SQL_WVARCHAR, SQL_WCHAR, SQL_WLONGVARCHAR} |
In Table 2, the column on the right holds a list of possible ODBC SQL types that could be used to associate with an RWDBValue::ValueType. The first type supported by the underlying driver is the type chosen.
After the type is selected, the ODBC API function SQLGetInfo() is used to find the data-source dependent type name associated with the chosen ODBC SQL type. The data-source dependent type name is then used by the DBTools.h++ access library for ODBC to create tables.
Neither DBTools.h++ nor the ODBC specification impose restrictions on the use of most datatypes, but individual ODBC drivers may. Check for specific restrictions in the documentation provided with your ODBC driver. Table 3 outlines the known restrictions associated with each DBTools.h++ type.
RWDBValue::ValueType | Restrictions |
Blob |
No restrictions. |
Char, UnsignedChar |
No restrictions. |
Date |
No restrictions. |
DateTime |
No restrictions. |
Decimal |
No restrictions. |
Double |
No restrictions. |
Duration |
No restrictions. |
Float |
No restrictions. |
Int, UnsignedInt |
No restrictions. |
Long, UnsignedLong |
No restrictions. |
MBString |
This datatype is not supported. |
String |
No restrictions. |
Short, UnsignedShort |
No restrictions. |
WString |
This datatype may not be supported--check your driver documentation. |
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.