RWDBValue
In the DB Interface Module, class
RWDBValue is the means of integrating data in the value layer with the pointer layer.
RWDBValue automatically converts between compatible C++ and structured types, allowing the value layer to be type safe. An
RWDBValue-based accessor and mutator are provided on
RWDBTBuffer<T>, giving the Open SQL interface the flexibility needed to support the value layer.
RWDBValue also adds null/not null semantics to the primitive types.
In application programs,
RWDBValue is especially useful when working with results where the type of data is not known. Programs can read data directly into
RWDBValue instances, and then interrogate the instance to find out what kind of data was placed in it.
RWDBValue instances can be held in collections and passed without knowing what type of data they are holding. Conversion methods on
RWDBValue allow applications to handle unknown data in a robust, predictable manner.
You will find a complete entry for
RWDBValue in the
SourcePro API Reference Guide, but its main components are listed here:
An enumerated type,
ValueType, which codes the datatype of the stored value. The possible ValueTypes are
NoType,
Tiny,
UnsignedTiny,
Char,
UnsignedChar,
Int,
UnsignedInt,
Short,
UnsignedShort,
Long,
UnsignedLong,
LongLong,
UnsignedLongLong, Float,
Double, LongDouble, String, Blob,
Date,
DateTime,
TimeTuple,
TimeTupleOffset,
Duration,
Decimal,
UString,
WString, and
MBString. To avoid polluting the global name space, all enums are scoped within classes. To refer to a member of the enumeration outside the scope of
RWDBValue, use the scoping operator
::, as in
RWDBValue::String, for example.
A friend,
rwdbNull, which is of type
RWDBValueManip, and represents a literal
NULL value. There is a constructor and an assignment operator that allow
RWDBValue instances to be formed from
rwdbNulls and other
RWDBValueManips.
A C++ union that can store a
Long,
Unsigned Long,
Long Long,
Unsigned Long Long, Double, Long Double,
RWCString,
RWDBMBString,
RWWString,
RWBasicUString,
RWDecimalPortable,
RWDBDuration, or
RWDBBlob.
Constructors and assignment operators that allow an
RWDBValue to be constructed or copied from any C++ primitive or from any structured type of the DB Interface Module.
The member function
canConvert(ValueType), which detects whether or not a given value can be converted to a specified type.
A collection of conversion routines such as
asInt(),
asDouble(),
asString(), and so on, which convert a given value to the type implied by the routine name.
The member function
typeString() returns the datatype of self in the form of a
string.
Member functions
isEqual(),
compareTo(),
binaryStoreSize(),
saveGuts(), and
restoreGuts(), which are required to make
RWDBValue persistable, as defined in the Essential Tools Module.
RWDBValue is derived from
RWCollectable.
As mentioned earlier,
RWDBValue is used internally to integrate the value and pointer layers of the DB Interface Module. Whenever data arrives from a database, routines in the database layer interrogate the database API for its type, and store the data into
RWDBTBuffer<T>, where
T is the primitive or structured type of the DB Interface Module best able to hold the data.
RWDBTBuffer<T> provides an accessor that automatically converts data elements into
RWDBValue instances for the value layer. Whenever the value layer requests data from the pointer layer,
RWDBValue’s
canConvert() routine is consulted to determine whether or not the conversion can be made. If not, an error condition arises. Otherwise, the appropriate
as<Type>() routine is invoked to convert to the requested type.