Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

2.3 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. If you need to use RWDBValue, however, Table 1 shows how SQL Server datatypes are mapped to RWDBValue datatypes, as well as appropriate C++ datatypes.

Table 1 -- Datatype mapping when retrieving data 

 
SQL Server datatypeRWDBValue::ValueTypeC++ datatype
char(n),
varchar(n),
text

String
RWCString
1nchar(n),
nvarchar(n),
ntext
WString
RWWString
binary(n),
varbinary(n), image

Blob
RWDBBlob
bit,
tinyint,
smallint

Short
short int
int
Long
long int
float(p)
Double
double
real
Float
float
decimal(p,s),
money,
smallmoney

Decimal
RWDecimalPortable
timestamp
Blob
RWDBBlob
datetime,
smalldatetime

DateTime
RWDBDateTime
1Note: SQLServer 6.5 doesn't support the nchar, varchar, and ntext datatypes.

When an application uses DBTools.h++ to create a SQL Server table, an 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
Blob
varbinary if length < 256,
otherwise image (SQL Server 6.5)
varbinary if length < 8000,
otherwise image (SQL Server 7.0)
Char,
UnsignedChar

tinyint
Date,
DateTime

datetime
Decimal
decimal(p,s) using
precision and scale of column.
Duration
Not supported by Microsoft SQL Server
Float
real
Double
float(p), using precision of column
Int,
UnsignedInt

int
Long,
UnsignedLong

int
MBString
Not supported by Microsoft SQL Server
Short,
UnsignedShort

smallint
String
varchar if length < 256 bytes,
otherwise text (SQL Server 6.5)
varchar if length < 8000 bytes,
otherwise text (SQL Server 7.0)
1WString
varchar if length < 256 bytes,
otherwise text (SQL Server 6.5)
nvarchar if length < 8000 bytes,
otherwise ntext (SQL Server 7.0)
1SQL Server 6.5 doesn't support the nchar, nvarchar, or ntext datatypes.

2.3.1 Restrictions on the Use of Datatypes

Microsoft SQL Server places 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. In these cases your application must 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
Blob
No restrictions.
Char,
UnsignedChar

No restrictions.
Date
No restrictions.
DateTime
No restrictions.
Decimal
No restrictions.
Double
No restrictions.
Duration
Not supported by Microsoft SQL Server
Float
No restrictions.
Int, UnsignedInt
No restrictions.
Long, UnsignedLong
No restrictions.
MBString
Not supported by Microsoft SQL Server
Short, UnsignedShort
No restrictions.
String,
WString

No restrictions.

2.3.2 Using Identity Columns

Microsoft SQL Server supports identity columns. Identity columns can be used within DBTools.h++, following the restrictions specified by the Microsoft SQL Server documentation. For more information, see the Microsoft SQL Server ODBC driver documentation.

Applications can create tables with identity columns by providing the native SQL statement, then executing 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 SQL server to provide values. In general, you should only provide values for identity columns if an application requires a specific value. All values must follow the restrictions of the SQL server.

Of course, updating the identity columns is strictly forbidden by the SQL server.


Previous fileTop of DocumentContentsIndexNext file

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