RWDBValue RWCollectable
Data Types | |
enum ValueType |
#include <rw/db/value.h> RWDBValue value; //null, no type value RWDBValue value(20); //integer value
RWDBValue provides storage for C++ primitive types, and for structured types used by DBTools.h++. It also adds Null/ not Null semantics to the primitive types. When DBTools.h++ fetches data from a database, it converts the data from the database vendor's datatypes into RWDBValues. When an application supplies DBTools.h++ with data, the data is stored as RWDBValues, so that the DBTools.h++ access libraries can standardize conversions from RWDBValue to a particular vendor's datatypes.
RWDBValue inherits from class RWCollectable. The virtual functions of the base class RWCollectable are redefined.
enum ValueType { NoType, Char, UnsignedChar, Tiny, // not used for data storage UnsignedTiny, // not used for data storage Short, UnsignedShort, Int, UnsignedInt, Long, UnsignedLong, Float, Double, Decimal, Date, DateTime, Duration, String, Blob, WString MBString, };
Every RWDBValue is tagged with a ValueType. In addition, RWDBColumn uses RWDBValue::ValueType to store schema information. In that context, Tiny and UnsignedTiny refer to one-byte integers. DBTools.h++ does not store data as Tiny or UnsignedTiny.
RWDBValueManip rwdbNull;
rwdbNull is used to represent a literal NULL value.
RWDBValueManip is a typedef:
typedef void (*RWDBValueManip)(RWDBValue&);
RWDBValue();
The default constructor creates a NULL value without type.
RWDBValue(const RWDBValue& value);
Copy constructor. RWDBValue obeys value semantics.
RWDBValue(char value); RWDBValue(unsigned char value); RWDBValue(short value); RWDBValue(unsigned short value); RWDBValue(int value); RWDBValue(unsigned int value); RWDBValue(long value); RWDBValue(unsigned long value); RWDBValue(float value); RWDBValue(double value); RWDBValue(const char* value); RWDBValue(const RWDecimalPortable& value); RWDBValue(const RWDBDateTime& value); RWDBValue(const RWDBDuration& value); RWDBValue(const RWCString& value); RWDBValue(const RWDBBlob& value); RWDBValue(const RWDate& date); RWDBValue(const wchar_t *value); RWDBValue(const RWWString& value); RWDBValue(const RWDBMBString& value);
Constructs an RWDBValue from the supplied value. Self is non-NULL and is tagged with the appropriate ValueType.
RWDBValue(RWDBValueManip manip);
Constructs an RWDBValue defined by the semantics of manip. In particular, rwdbNull can be used to construct a NULL value without type.
RWDBValue& operator=(const RWDBValue& value);
Assignment operator. RWDBValue obeys value semantics.
RWDBValue& operator=(char value); RWDBValue& operator=(unsigned char value); RWDBValue& operator=(short value); RWDBValue& operator=(unsigned short value); RWDBValue& operator=(int value); RWDBValue& operator=(unsigned int value); RWDBValue& operator=(long value); RWDBValue& operator=(unsigned long value); RWDBValue& operator=(float value); RWDBValue& operator=(double value); RWDBValue& operator=(const RWDecimalPortable& value); RWDBValue& operator=(const RWDBDateTime& value); RWDBValue& operator=(const RWDBDuration& value); RWDBValue& operator=(const RWCString& value); RWDBValue& operator=(const RWDBBlob& value); RWDBValue& operator=(const RWWString& value); RWDBValue& operator=(const RWDBMBString& value);
Assigns value's type and value to self.
RWDBValue& operator=(const RWDBValueManip manip);
Assigns a type and value defined by manip to self. In particular, rwdbNull can be assigned to an RWDBValue, changing it into a NULL value without type.
RWDBBlob asBlob() const;
Returns self as an RWDBBlob. If self cannot be converted according to canConvert(RWDBValue::Blob), returns an RWDBBlob with zero length.
char asChar() const;
Returns self as a char. If self cannot be converted according to canConvert(RWDBValue::Char), returns a char with a value of (char)0.
RWDate asDate() const;
Returns self as an RWDate. If self cannot be converted according to canConvert(RWDBValue::Date), returns an RWDate whose state is invalid.
RWDBDateTime asDateTime() const;
Returns self as an RWDBDateTime. If self cannot be converted according to canConvert(RWDBValue::DateTime), returns an RWDBDateTime whose state is invalid.
RWDecimalPortable asDecimal() const;
Returns self as an RWDecimalPortable. If self cannot be converted according to canConvert(RWDBValue::Decimal), returns an RWDecimalPortable with a value of 0.
double asDouble() const;
Returns self as a double. If self cannot be converted according to canConvert(RWDBValue::Double), returns a double with a value of 0.
RWDBDuration asDuration() const;
Returns self as an RWDBDuration. If self cannot be converted according to canConvert(RWDBValue::Duration), returns an RWDBDuration whose state is invalid.
float asFloat() const;
Returns self as a float. If self cannot be converted according to canConvert(RWDBValue::Float), returns a float with a value of 0.
int asInt() const;
Returns self as an int. If self cannot be converted according to canConvert(RWDBValue::Int), returns an int with a value of 0.
long asLong() const;
Returns self as a long. If self cannot be converted according to canConvert(RWDBValue::Long), returns a long with a value of 0.
RWDBMBString asMBString() const;
Returns self as an RWDBMBString. Any RWDBValue can be converted to an RWDBMBString.
short asShort() const;
Returns self as a short. If self cannot be converted according to canConvert(RWDBValue::Short), returns a short with a value of 0.
RWCString asString() const;
Returns self as an RWCString. Any RWDBValue can be converted to an RWCString. Uses default format specifications.
RWCString asString(const RWDBPhraseBook& phraseBook) const;
Returns self as an RWCString. Any RWDBValue can be converted to an RWCString. Uses format specifications from the supplied phraseBook.
unsigned char asUnsignedChar() const;
Returns self as an unsigned char. If self cannot be converted according to canConvert(RWDBValue::UnsignedChar), returns an unsigned char with a value of (unsigned char) 0.
unsigned int asUnsignedInt() const;
Returns self as an unsigned int. If self cannot be converted according to canConvert(RWDBValue::UnsignedInt), returns an unsigned int with a value of 0.
unsigned long asUnsignedLong() const;
Returns self as an unsigned long. If self cannot be converted according to canConvert(RWDBValue::UnsignedLong), returns an unsigned long with a value of 0.
unsigned short asUnsignedShort() const;
Returns self as an unsigned short. If self cannot be converted according to canConvert(RWDBValue::UnsignedShort), returns an unsigned short with a value of 0.
RWWString asWString() const;
Returns self as an RWWString. Any RWDBValue can be converted to an RWWString.
virtual RWspace binaryStoreSize() const;
Redefined from RWCollectable. Returns the number of bytes required to store self in an RWFile.
RWBoolean canConvert(ValueType type)const;
Returns TRUE if self can be converted to type by an RWDBValue::asType() method, otherwise returns FALSE. Returns TRUE when:
Table 21 shows the supported type conversions. Each row is a datatype to be converted, while each column is a conversion type. A 1 means can convert and a 0 means can't convert. For example, Table 21 shows that type Blob can be converted to itself and to String, WString, and MBString.
Type | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | |
a. |
NoType |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
b. |
Char |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
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0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
o. |
Duration |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
p. |
String |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
q. |
Blob |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
r. |
WString |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
s. |
MBString |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
Note: Loss of precision can result without warning if you try to push a string representation of a number into a value that can't hold it. If this is a concern, please use RWDecimalPortable, as in the following example:
RWDBValue aNumber("12345.6789"); Assert(aNumber.canConvert(RWDBValue::Char)); char numberThatIsTooSmall = aNumber.asChar(); // No way that // 12345.6789 can fit. assert(aNumber.canConvert(RWDBValue::Decimal)); RWDecimalPortable bigEnough = aNumber.asDecimal(); // This // is OK.
virtual int compareTo(const RWCollectable* cp) const;
Redefined from RWCollectable. Interprets cp as a pointer to an RWDBValue, dereferences it, and compares the result with self. If either self or *cp is NULL, the result is undefined. Otherwise, if self and *cp have the same type, the result is -1, 0, or 1, depending upon whether or not self is less than, equal to, or greater than *cp, according to the semantics of self's type. Otherwise self and *cp have different types, and the result is defined only as being nonzero.
virtual unsigned hash() const;
Redefined from RWCollectable. Returns a suitable value for hashing.
virtual RWClassID isA() const;
Redefined from RWCollectable. Returns __RWDBVALUE.
virtual RWBoolean isEqual(const RWCollectable* cp) const;
Redefined from RWCollectable. Returns TRUE if compareTo(cp) == 0, otherwise returns FALSE.
RWBoolean isNull() const;
Returns TRUE if self represents a NULL value, otherwise returns FALSE. Note that the results of arithmetic and logical operations on NULL values are undefined; checks for NULL must be made independently.
virtual void restoreGuts(const RWFile& file);
Redefined from RWCollectable. Replaces the value of self with a value read from file.
virtual void restoreGuts(const RWvistream& vis);
Redefined from RWCollectable. Replaces the value of self with a value read from vis.
virtual void saveGuts(const RWFile& file) const;
Redefined from RWCollectable. Writes self file.
virtual void saveGuts(const RWvostream& vos) const;
Redefined from RWCollectable. Writes self to vos.
ValueType type() const;
Returns the datatype of self.
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.