Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

clawsoft::SQLField Class Reference

#include <SQLField.h>

Inheritance diagram for clawsoft::SQLField:

Inheritance graph
[legend]
Collaboration diagram for clawsoft::SQLField:

Collaboration graph
[legend]

Detailed Description

Multitype container for SQL single data.

The purpose of SQLField 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.

STATUS: IN PROGRESS


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 clawlib's previously defined datatypes. More...


Public Methods

 SQLField (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.

 SQLField (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.

 ~SQLField ()
 This destructor will release any used buffeasr and reset all internal stored data.

Sint16 toTinyInt ()
 This will convert the data stored on this object to an Sint16 which is a signed integer of 16 bits (2 bytes) length.

Uint16 toUTinyInt ()
 Is the same as toTinyInt but instead of returning a signed quantity this method returns an unsigned one.

Sint32 toInteger ()
 Returns the data as a 32 bit (4 bytes) signed integer.

Uint32 toUInteger ()
 Is the same as toInteger but instead of returning a signed quantity this method returns an unsigned one.

Sint64 toBigInt ()
 Returns the data as a 64 bit (8 bytes) signed integer.

Uint64 toUBigInt ()
 Is the same as clawsoft::SQLResultSet::toBigInt but instead of returning a signed quantity this method returns an unsigned one.

float toFloat ()
 Returns the data as a 32 bit (4 bytes) floating number conforming to the IEEE 754 standard.

double toDouble ()
 Returns the data as a 64 bit (8 bytes) floating number conforming to the IEEE 754 standard.

const char * toChar ()
 Returns the data as a null-terminated string of char, len is the length of the string.

const StringtoString ()
 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 ()
 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.

const TimestamptoTimestamp ()
 This method will convert and return the data as a Timestamp pointer.

bool toBit ()
 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 Uint32 size ()
 Returns the size in bytes of the currently stored object.

const Uint32 dataSize ()
 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 ()
 This will the name for this field as configured during the table creation.

const char * getClassName ()
 Returns the name of the current class.


Protected Methods

void setClassName (const char *n)
 Call this method when you need to set the name of the class you're creating, typically in it's constructor, remember that you must set the classname for every class you create, that way you can have more information while debugging.


Member Enumeration Documentation

enum clawsoft::SQLField::SQLtypes
 

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

Enumeration values:
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 clawlib'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.


Constructor & Destructor Documentation

clawsoft::SQLField::SQLField 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.

clawsoft::SQLField::SQLField 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

clawsoft::SQLField::~SQLField  
 

This destructor will release any used buffeasr and reset all internal stored data.


Member Function Documentation

const Uint32 clawsoft::SQLField::dataSize  
 

Returns the size in bytes of the currently stored object.

const char * clawsoft::Object::getClassName   [inherited]
 

Returns the name of the current class.

const int clawsoft::SQLField::getDatatype  
 

Returns a constant like SQLtypes describing the datatype currently stored.

const String & clawsoft::SQLField::getFieldName  
 

This will the name for this field as configured during the table creation.

void clawsoft::Object::setClassName const char *    n [protected, inherited]
 

Call this method when you need to set the name of the class you're creating, typically in it's constructor, remember that you must set the classname for every class you create, that way you can have more information while debugging.

void clawsoft::SQLField::setFieldName const String   nam
 

This will set the column name to nam.

const Uint32 clawsoft::SQLField::size  
 

Returns the size in bytes of the currently stored object.

Sint64 clawsoft::SQLField::toBigInt  
 

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.

bool clawsoft::SQLField::toBit  
 

This method will return 0 or 1, a boolean value according to the stored data pointer.

const void* clawsoft::SQLField::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 Byte * clawsoft::SQLField::toByte  
 

With this method ou will get the first byte of the stored data pointer.

const char * clawsoft::SQLField::toChar  
 

Returns the data as a null-terminated string of char, len is the length of the string.

const Date * clawsoft::SQLField::toDate  
 

This method will convert and return the data as a Date pointer.

double clawsoft::SQLField::toDouble  
 

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.

float clawsoft::SQLField::toFloat  
 

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.

Sint32 clawsoft::SQLField::toInteger  
 

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.

const String * clawsoft::SQLField::toString  
 

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 * clawsoft::SQLField::toText  
 

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 Time * clawsoft::SQLField::toTime  
 

This method will convert and return the data as a Time pointer.

const Timestamp * clawsoft::SQLField::toTimestamp  
 

This method will convert and return the data as a Timestamp pointer.

Sint16 clawsoft::SQLField::toTinyInt  
 

This will convert the data stored on this object to an Sint16 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 SQLField is storing a 32 char VARCHAR, as an Sint16 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

Uint64 clawsoft::SQLField::toUBigInt  
 

Is the same as clawsoft::SQLResultSet::toBigInt but instead of returning a signed quantity this method returns an unsigned one.

Uint32 clawsoft::SQLField::toUInteger  
 

Is the same as toInteger but instead of returning a signed quantity this method returns an unsigned one.

Uint16 clawsoft::SQLField::toUTinyInt  
 

Is the same as toTinyInt but instead of returning a signed quantity this method returns an unsigned one.


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

Authors:

Juan V. Guerrero
Jannette C. Mejia
Juan C. Guevara

Powered by:

SourceForgeLogo