xvr2::SQL::Field Class Reference

#include <Field.h>

Inheritance diagram for xvr2::SQL::Field:

Inheritance graph
[legend]

List of all members.


Detailed Description

Multitype container for SQL single data.

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 StringtoText () 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 DatetoDate ()
 This method will convert and return the data as a Date pointer.
const TimetoTime ()
 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 BytetoByte ()
 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 StringgetFieldName () 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

Driverdrv

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
DatetmpDate
TimetmpTime
TimestamptmpTimestamp
BytetmpByte
bool * tmpBool
Int16tmpInt16
Int32tmpInt32
Int64tmpInt64
float * tmpFloat
double * tmpDouble
String colname

Friends

std::ostream & operator<< (std::ostream &stream, const Object &s)

Member Enumeration Documentation

This enumeration holds all SQL compatible datatypes, this compatible datatypes must also coincide with C/C++ and/or xvr2lib's previously defined datatypes.

Enumerator:
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.

Definition at line 75 of file Field.h.


Constructor & Destructor Documentation

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.


Member Function Documentation

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

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& xvr2::SQL::Field::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* 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]


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  stream,
const Object s 
) [friend, inherited]


Member Data Documentation

void* xvr2::SQL::Field::dataPtr [private]

Definition at line 38 of file Field.h.

Definition at line 39 of file Field.h.

Definition at line 40 of file Field.h.

Definition at line 42 of file Field.h.

Definition at line 43 of file Field.h.

Definition at line 44 of file Field.h.

Definition at line 45 of file Field.h.

Definition at line 46 of file Field.h.

char* xvr2::SQL::Field::tmpStrBIT [private]

Definition at line 47 of file Field.h.

Definition at line 48 of file Field.h.

Definition at line 50 of file Field.h.

Definition at line 59 of file Field.h.

Definition at line 60 of file Field.h.

Definition at line 61 of file Field.h.

Definition at line 62 of file Field.h.

bool* xvr2::SQL::Field::tmpBool [private]

Definition at line 63 of file Field.h.

Definition at line 64 of file Field.h.

Definition at line 65 of file Field.h.

Definition at line 66 of file Field.h.

float* xvr2::SQL::Field::tmpFloat [private]

Definition at line 67 of file Field.h.

double* xvr2::SQL::Field::tmpDouble [private]

Definition at line 68 of file Field.h.

Definition at line 69 of file Field.h.

Definition at line 71 of file Field.h.

std::string xvr2::Object::__cls_name [protected, inherited]

Definition at line 30 of file Object.h.


The documentation for this class was generated from the following file:

Generated on Fri Jun 20 22:56:06 2008 for X-VR2 SDK by  doxygen 1.5.5