#include <Field.h>
The purpose of Field is to provide a multitype container, because we need to translate the data that is coming from the ResultSet on a select statement we need to provide a way to ensure a safe translation of the data provided.
Definition at line 36 of file Field.h.
Public Types | |
enum | SQLtypes { TINYINT = 1, INTEGER = 2, BIGINT = 3, FLOAT = 4, DOUBLE = 5, CHAR = 6, VARCHAR = 7, STRING = 8, BLOB = 9, TEXT = 10, DATE = 11, TIME = 12, TIMESTAMP = 13, BIT = 14, BYTE = 15 } |
This enumeration holds all SQL compatible datatypes, this compatible datatypes must also coincide with C/C++ and/or xvr2lib's previously defined datatypes. More... | |
Public Member Functions | |
Field () | |
Default constructor. | |
Field (const void *data, const UInt32 size) | |
This will instatiate an SQLResultSet attempting to guess the datatype based on the size in bytes, data is pointer to the buffer containing the the value returned in the current cell from the selected row in the ResultSet. | |
Field (const int type, const void *data, const UInt32 size) | |
This constructor will instatiate a new object of this class followed by an specified type, data pointer and a given pointer size. | |
void | init (const int type, const void *data, const UInt32 size) |
This constructor will instatiate a new object of this class followed by an specified type, data pointer and a given pointer size. | |
~Field () | |
This destructor will release any used buffeasr and reset all internal stored data. | |
Int16 | toTinyInt () const |
This will convert the data stored on this object to an Int16 which is a signed integer of 16 bits (2 bytes) length. | |
UInt16 | toUTinyInt () const |
Is the same as toTinyInt but instead of returning a signed quantity this method returns an unsigned one. | |
Int32 | toInteger () const |
Returns the data as a 32 bit (4 bytes) signed integer. | |
UInt32 | toUInteger () const |
Is the same as toInteger but instead of returning a signed quantity this method returns an unsigned one. | |
Int64 | toBigInt () const |
Returns the data as a 64 bit (8 bytes) signed integer. | |
UInt64 | toUBigInt () const |
Is the same as xvr2::ResultSet::toBigInt but instead of returning a signed quantity this method returns an unsigned one. | |
float | toFloat () const |
Returns the data as a 32 bit (4 bytes) floating number conforming to the IEEE 754 standard. | |
double | toDouble () const |
Returns the data as a 64 bit (8 bytes) floating number conforming to the IEEE 754 standard. | |
char * | toChar () const |
Returns the data as a null-terminated string of char, len is the length of the string. | |
std::string | toString () const |
Returns the data as a String if the data is numeric then it will be translated also if it is a Date, Time Byte, Bit or Timestamp. | |
const String & | toText () const |
Returns the data as a String if the data is numeric then it will be translated also if it is a Date, Time Byte, Bit or Timestamp. | |
const void * | toBLOB () |
This will return a void data pointer, please take special care with BLOBs and try not to pass their addressing limits, please use allways the size(); method in order know the size of the current BLOB. | |
const Date * | toDate () |
This method will convert and return the data as a Date pointer. | |
const Time * | toTime () |
This method will convert and return the data as a Time pointer. | |
Timestamp | toTimestamp () |
This method will convert and return the data as a Timestamp pointer. | |
Timestamp | toTimestamp () const |
bool | toBit () const |
This method will return 0 or 1, a boolean value according to the stored data pointer. | |
bool | toBool () const |
This method will return 0 or 1, a boolean value according to the stored data pointer. | |
const Byte * | toByte () |
With this method ou will get the first byte of the stored data pointer. | |
const int | getDatatype () |
Returns a constant like SQLtypes describing the datatype currently stored. | |
const int | getDatatype () const |
Returns a constant like SQLtypes describing the datatype currently stored. | |
const UInt32 | size () |
Returns the size in bytes of the currently stored object. | |
const UInt32 | size () const |
Returns the size in bytes of the currently stored object. | |
const UInt32 | dataSize () |
Returns the size in bytes of the currently stored object. | |
const UInt32 | dataSize () const |
Returns the size in bytes of the currently stored object. | |
void | setFieldName (const String &nam) |
This will set the column name to nam. | |
const String & | getFieldName () const |
This will be the name for this field as configured during the table creation. | |
bool | isNull () const |
virtual const char * | getClassName () |
Returns the name of the current class. | |
virtual std::string | toString () |
Static Public Member Functions | |
static void | debugmsg (Object *obj, const char *msg, int linenumber=__LINE__, const char *srcfile=__FILE__) |
Will print a debug message to the screen. | |
static void | debugmsgln (Object *obj, const char *msg, int linenumber=__LINE__, const char *srcfile=__FILE__) |
Public Attributes | |
Driver * | drv |
Protected Attributes | |
std::string | __cls_name |
Private Attributes | |
void * | dataPtr |
UInt32 | dataLen |
int | dataType |
char * | tmpStrTINYINT |
char * | tmpStrINTEGER |
char * | tmpStrBIGINT |
char * | tmpStrFLOAT |
char * | tmpStrDOUBLE |
char * | tmpStrBIT |
char * | tmpStrBYTE |
String | tmpString |
Date * | tmpDate |
Time * | tmpTime |
Timestamp * | tmpTimestamp |
Byte * | tmpByte |
bool * | tmpBool |
Int16 * | tmpInt16 |
Int32 * | tmpInt32 |
Int64 * | tmpInt64 |
float * | tmpFloat |
double * | tmpDouble |
String | colname |
Friends | |
std::ostream & | operator<< (std::ostream &stream, const Object &s) |
This enumeration holds all SQL compatible datatypes, this compatible datatypes must also coincide with C/C++ and/or xvr2lib's previously defined datatypes.
TINYINT | Represents 2 byte integer, the same as Int16. |
INTEGER | This is a 4 byte integer, the same as Int32. |
BIGINT | An 8 byte integer, this is a 64 bit number, the same as Int64. |
FLOAT | The same as a C float datatype. |
DOUBLE | The same as a C double. |
CHAR | An array of 1 byte characters, the same as the C char datatype. |
VARCHAR | A variable null-terminated array of CHARs, the same as a C char[]. |
STRING | The same as a varchar, but this is compatible with the xvr2lib's String class. |
BLOB | This is a variable number of binary data, it could be text an image or anything else, be carefull with this datatype since you could cause a segmentation fault if try to read or write past the end of the allocated space for the object stored in, it is the C equivalent of a void pointer. |
TEXT |
This is the same thing as a BLOB, but instead of being a binary arrangement of data now it is an understandable arrangement of characters.
It is equivalent to a String. |
DATE | This represents a date object and is also equivalent to the Date class datatype. |
TIME | This represents a time object and is also equivalent to the Time class datatype. |
TIMESTAMP | This represents a timestamp it is the same as the Timestamp class. |
BIT | This reprents a boolean datatype such as true or false only, for us the is the equivalent to the C++ bool datatype. |
BYTE | This represents a binary 8 bit datatype. |
xvr2::SQL::Field::Field | ( | ) |
Default constructor.
xvr2::SQL::Field::Field | ( | const void * | data, | |
const UInt32 | size | |||
) |
This will instatiate an SQLResultSet attempting to guess the datatype based on the size in bytes, data is pointer to the buffer containing the the value returned in the current cell from the selected row in the ResultSet.
xvr2::SQL::Field::Field | ( | const int | type, | |
const void * | data, | |||
const UInt32 | size | |||
) |
This constructor will instatiate a new object of this class followed by an specified type, data pointer and a given pointer size.
type must be one of the above SQLtypes
xvr2::SQL::Field::~Field | ( | ) |
This destructor will release any used buffeasr and reset all internal stored data.
void xvr2::SQL::Field::init | ( | const int | type, | |
const void * | data, | |||
const UInt32 | size | |||
) |
This constructor will instatiate a new object of this class followed by an specified type, data pointer and a given pointer size.
type must be one of the above SQLtypes
Int16 xvr2::SQL::Field::toTinyInt | ( | ) | const |
This will convert the data stored on this object to an Int16 which is a signed integer of 16 bits (2 bytes) length.
Be aware that if you try to convert the incorrect data you may be having an overflow of your current storage space, as an example imagine that the Field is storing a 32 char VARCHAR, as an Int16 your limits are set between -32768 and 32767 so even if the VARCHAR is composed of numeric values you wont have enough space to store the result translation, in this case the BufferTooSmallException is thrown, be carefull with this and try allways to convert the correct datatype. A NumberException is thrown only if the source datatype is of the type VARCHAR, TEXT or STRING and one or more of its characters is NOT a digit
UInt16 xvr2::SQL::Field::toUTinyInt | ( | ) | const |
Is the same as toTinyInt but instead of returning a signed quantity this method returns an unsigned one.
Int32 xvr2::SQL::Field::toInteger | ( | ) | const |
Returns the data as a 32 bit (4 bytes) signed integer.
If the data on this cell is coming from a TEXT or VARCHAR column type then be prepared to receive the NumberException exception if there is a non numeric character contained in there. Also the BufferTooSmallException may be thrown if the number of digits is bigger than 10.
UInt32 xvr2::SQL::Field::toUInteger | ( | ) | const |
Is the same as toInteger but instead of returning a signed quantity this method returns an unsigned one.
Int64 xvr2::SQL::Field::toBigInt | ( | ) | const |
Returns the data as a 64 bit (8 bytes) signed integer.
If the data on this cell is coming from a TEXT or VARCHAR column type then be prepared to receive the NumberException exception if there is a non numeric character contained in there. Also the BufferTooSmallException may be thrown if the number of digits is bigger than 20.
UInt64 xvr2::SQL::Field::toUBigInt | ( | ) | const |
Is the same as xvr2::ResultSet::toBigInt but instead of returning a signed quantity this method returns an unsigned one.
float xvr2::SQL::Field::toFloat | ( | ) | const |
Returns the data as a 32 bit (4 bytes) floating number conforming to the IEEE 754 standard.
If the data on this cell is coming from a TEXT or VARCHAR column type then be prepared to receive the NumberException exception if there is a non numeric character different from + - or E. Also the BufferTooSmallException may be thrown if the number of digits is bigger than 10 plus 3 for the exponent and 2 more for signs.
double xvr2::SQL::Field::toDouble | ( | ) | const |
Returns the data as a 64 bit (8 bytes) floating number conforming to the IEEE 754 standard.
If the data on this cell is coming from a TEXT or VARCHAR column type then be prepared to receive the NumberException exception if there is a non numeric character different from + - or E. Also the BufferTooSmallException may be thrown if the number of digits is bigger than 20 plus 3 for the exponent and 2 more for signs.
char* xvr2::SQL::Field::toChar | ( | ) | const |
Returns the data as a null-terminated string of char, len is the length of the string.
std::string xvr2::SQL::Field::toString | ( | ) | const |
const String& xvr2::SQL::Field::toText | ( | ) | const |
const void* xvr2::SQL::Field::toBLOB | ( | ) |
This will return a void data pointer, please take special care with BLOBs and try not to pass their addressing limits, please use allways the size(); method in order know the size of the current BLOB.
const Date* xvr2::SQL::Field::toDate | ( | ) |
This method will convert and return the data as a Date pointer.
const Time* xvr2::SQL::Field::toTime | ( | ) |
This method will convert and return the data as a Time pointer.
Timestamp xvr2::SQL::Field::toTimestamp | ( | ) |
This method will convert and return the data as a Timestamp pointer.
Timestamp xvr2::SQL::Field::toTimestamp | ( | ) | const |
bool xvr2::SQL::Field::toBit | ( | ) | const |
This method will return 0 or 1, a boolean value according to the stored data pointer.
bool xvr2::SQL::Field::toBool | ( | ) | const |
This method will return 0 or 1, a boolean value according to the stored data pointer.
const Byte* xvr2::SQL::Field::toByte | ( | ) |
With this method ou will get the first byte of the stored data pointer.
const int xvr2::SQL::Field::getDatatype | ( | ) |
Returns a constant like SQLtypes describing the datatype currently stored.
const int xvr2::SQL::Field::getDatatype | ( | ) | const |
Returns a constant like SQLtypes describing the datatype currently stored.
const UInt32 xvr2::SQL::Field::size | ( | ) |
Returns the size in bytes of the currently stored object.
const UInt32 xvr2::SQL::Field::size | ( | ) | const |
Returns the size in bytes of the currently stored object.
const UInt32 xvr2::SQL::Field::dataSize | ( | ) |
Returns the size in bytes of the currently stored object.
const UInt32 xvr2::SQL::Field::dataSize | ( | ) | const |
Returns the size in bytes of the currently stored object.
void xvr2::SQL::Field::setFieldName | ( | const String & | nam | ) |
This will set the column name to nam.
const String& xvr2::SQL::Field::getFieldName | ( | ) | const |
This will be the name for this field as configured during the table creation.
bool xvr2::SQL::Field::isNull | ( | ) | const |
virtual const char* xvr2::Object::getClassName | ( | ) | [virtual, inherited] |
Returns the name of the current class.
static void xvr2::Object::debugmsg | ( | Object * | obj, | |
const char * | msg, | |||
int | linenumber = __LINE__ , |
|||
const char * | srcfile = __FILE__ | |||
) | [static, inherited] |
Will print a debug message to the screen.
static void xvr2::Object::debugmsgln | ( | Object * | obj, | |
const char * | msg, | |||
int | linenumber = __LINE__ , |
|||
const char * | srcfile = __FILE__ | |||
) | [static, inherited] |
virtual std::string xvr2::Object::toString | ( | ) | [virtual, inherited] |
std::ostream& operator<< | ( | std::ostream & | stream, | |
const Object & | s | |||
) | [friend, inherited] |
void* xvr2::SQL::Field::dataPtr [private] |
UInt32 xvr2::SQL::Field::dataLen [private] |
int xvr2::SQL::Field::dataType [private] |
char* xvr2::SQL::Field::tmpStrTINYINT [private] |
char* xvr2::SQL::Field::tmpStrINTEGER [private] |
char* xvr2::SQL::Field::tmpStrBIGINT [private] |
char* xvr2::SQL::Field::tmpStrFLOAT [private] |
char* xvr2::SQL::Field::tmpStrDOUBLE [private] |
char* xvr2::SQL::Field::tmpStrBIT [private] |
char* xvr2::SQL::Field::tmpStrBYTE [private] |
String xvr2::SQL::Field::tmpString [private] |
Date* xvr2::SQL::Field::tmpDate [private] |
Time* xvr2::SQL::Field::tmpTime [private] |
Timestamp* xvr2::SQL::Field::tmpTimestamp [private] |
Byte* xvr2::SQL::Field::tmpByte [private] |
bool* xvr2::SQL::Field::tmpBool [private] |
Int16* xvr2::SQL::Field::tmpInt16 [private] |
Int32* xvr2::SQL::Field::tmpInt32 [private] |
Int64* xvr2::SQL::Field::tmpInt64 [private] |
float* xvr2::SQL::Field::tmpFloat [private] |
double* xvr2::SQL::Field::tmpDouble [private] |
String xvr2::SQL::Field::colname [private] |
std::string xvr2::Object::__cls_name [protected, inherited] |