Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

2.2 Datatypes

DBTools.h++ stores data fetched from a database into a DBTools.h++ application in instances of the RWDBValue class. Most applications can ignore RWDBValue and fetch data directly into C++ variables. Table 1 shows how SQL Server datatypes map to both RWDBValue value types and C++ datatypes.

Table 1 -- Datatype mapping when retrieving data

 
SQL Server DatatypeRWDBValue::ValueTypeC++ Datatype
char(n), varchar(n),text
String
RWCString
nchar(n), nvarchar(n)
MBString1
RWDBMBString2
binary(n),
varbinary(n), image

Blob
RWDBBlob
bit, tinyint, smallint
Short
short int
int
Long
long int
float(p),
double precision

Double
double
real
Float
float
decimal(p,s),
numeric(p,s),
money, smallmoney

Decimal
RWDecimalPortable
datetime,
smalldatetime

DateTime
RWDBDateTime
1The Sybase SQL Server usertype value, if available, is used to differentiate standard and national character stings. See Section 2.7.1 on return types.
2See previous footnote.

When an application uses DBTools.h++ to create an SQL server table, the RWDBValue::ValueType is used to define the table's schema. Table 2 shows how DBTools.h++ maps its datatypes to SQL server datatypes when defining a schema

Table 2 -- Datatype mapping when creating tables

 
RWDBValue::ValueTypeSQL Server Datatype
Char, UnsignedChar
tinyint
String
varchar if length is < 256, otherwise text
MBString, WString
nvarchar if length is < 256, otherwise text
Blob
varbinary if length < 256, otherwise image
Short, UnsignedShort
smallint
Int, UnsignedInt
int
Long, UnsignedLong
int
Float
real
Double
float(p), using precision of column
Decimal
money or decimal(p,s) using precision and scale of column. See below.
Date, DateTime
datetime
Duration
Not supported by DB-Library

DBTools.h++ determines client and server support for the decimal and numeric datatypes, however not all combinations of clients and servers will be successful in data conversions. Applications that want to take full advantage of these datatypes should verify that both clients and servers support the decimal and numeric datatypes. This means that both the client and the server must be Sybase version 10.0.x or above.

2.2.1 Restrictions on the Use of Datatypes

Sybase DB-Library and servers place restrictions when using certain datatypes. Where possible, DBTools.h++ tries to be flexible about datatypes. However, there are some situations where conversions are not possible, and in these cases your application will need to be aware of the contexts in which certain datatypes can be used. Table 3 outlines the restrictions associated with each DBTools.h++ type.

Table 3 -- Restrictions on the use of DBTools.h++ datatypes

 
RWDBValue::ValueTypeRestrictions
Char, UnsignedChar
No restrictions.
String, MBString, WString
No restrictions.
Blob
No restrictions.
Short, UnsignedShort
No restrictions.
Int, UnsignedInt
No restrictions.
Long, UnsignedLong
No restrictions.
Double
No restrictions.
Float
No restrictions.
Decimal
The precision and scale of a value can vary depending on the version of DB-Library and server. Consistent versions of clients and servers can eliminate difficulties in conversions.
Date
No restrictions.
DateTime
No restrictions.
Duration
*Not supported by DB-Library

2.2.2 Using Identity Columns

Sybase SQL servers support identity columns from release 10.0. Identity columns can be used within DBTools.h++, following the restrictions specified by the Sybase documentation. For more information, see Sybase SQL Server Transact-SQL User's Guide.

Applications can create tables with identity columns by providing the native SQL statement then executing it with RWDBDatabase::executeSql().

Applications can also acquire the schema of a table that contains an identity column. The schema will return identity columns as RWDBValue::Decimal datatypes, however there is no way to determine if the column is actually an identity column. Applications must know which column is the identity column of a table to use it correctly.

New rows can be inserted into tables by not providing values for identity columns. This effectively allows the SQL server to provide values. Values for identity columns should only be provided if an application demands a specific value. All values must follow the restrictions of the SQL server.

Updating the identity columns is strictly forbidden by the SQL server.


Previous fileTop of DocumentContentsIndexNext file

©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.