Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

2.3 Datatypes

Data fetched from a database into a DBTools.h++ application is stored internally by DBTools.h++ in instances of the RWDBValue class. Most applications can ignore RWDBValue and fetch data directly into C++ variables. Table 1 shows how Adaptive Server datatypes are mapped to RWDBValue datatypes, as well as appropriate C++ datatypes.

Table 1 -- Datatype mapping when retrieving data 

 
Adaptive 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 Adaptive Server usertype value, when available, is used to differentiate standard and national character strings. See Section 2.9.1 on return types.
2See the previous footnote.

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

Table 2 -- Datatype mapping when creating tables 

 
RWDBValue::ValueTypeAdaptive Server Datatype
Char, UnsignedChar
tinyint
String
varchar if length is < 256, otherwise text
WString, MBString
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 Client-Library

2.3.1 Restrictions on the Use of Datatypes

Sybase Client-Library and servers place restrictions on the use of 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, WString, MBString
Not supported on RWDBBoundExpr if string size is bigger than 256 bytes.
Blob
Not supported on RWDBBoundExpr.
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 Client-Library and server. Consistent versions of clients and servers can eliminate difficulties in conversions.
Date
No restrictions.
DateTime
No restrictions.
Duration
Not supported by Client-Library

2.3.2 Using Identity Columns

Sybase Adaptive Servers support identity columns. Identity columns can be used within DBTools.h++, subject to the restrictions specified by the Sybase documentation. For more information, see the Transact-SQL User's Guide.

Applications can create tables with identity columns by providing the native SQL statement, and execute it using RWDBConnection::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 the identity column of a table to use it correctly.

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

Of course, updating identity columns is strictly forbidden by Adaptive Server.


Previous fileTop of DocumentContentsIndexNext file

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