WORM 0.2
A C++ DAL/ORM code generation framework
|
The WSqlField class represents a field in a record. More...
#include <wsqlfield.h>
Public Member Functions | |
WSqlField () | |
WSqlField (const std::string &fieldName, const std::string &columnName=std::string()) | |
WSqlField & | operator= (const WSqlField &other) |
bool | operator== (const WSqlField &other) const |
bool | operator!= (const WSqlField &other) const |
~WSqlField () | |
void | setData (std::string s) |
Functions for setting the value of the data. | |
void | setData (short sh) |
void | setData (int i) |
void | setData (long l) |
void | setData (float f) |
void | setData (double d) |
template<typename T > | |
T | data () |
const WSqlDatum & | rawDatum () |
void | clear () |
void | setName (const std::string &fname) |
void | setColumnName (const std::string &cname) |
void | setIsDirty (bool b) |
void | setPrecision (int i) |
const bool | isDirty () const |
const std::string & | name () const |
Returns the name of the field in the record. | |
const std::string & | columnName () const |
Returns the name of the column as defined in the database.. | |
const int | precision () const |
The WSqlField class represents a field in a record.
WSqlField represents the data contained a single field of a record in a result set returned from a query. Each field contains the value stored as a WSqlDatum and the name of the field associated is a string. Note that the name of the field corresponds to either the column name as defined in the database or the alias defined in the query. The column name defined in the database is available using columnName(). Drivers should initialize both of these when constructing a field for a result set; users should initialize at least name and preferable columnName if using the field for an insert or update.
WSqlFields are used to populate a WSqlRecord in a WSqlResult. See below for an example.
The data value is converted on demand to supported types (currently native C++ types and std::string) and can be retrieved using the function data(). Alternately, the full WSqlDatum can be retrieved using rawData(). For example:
//assume a record is available .. WSqlField fldName = record.field(string("user_name")); string name = fldName.data<string>(); //or int idnumber = record.field(string("user_id")).data<int>(); //or WSqlDatum datum = field.rawData(); //do something with the datum ..
Other methods provide more infomation about the field. columnName() returns the name of the column as defined in the database table (or view), isDirty() returns true if the field has been modified - note that this must be set by the user.
The value of the data can be set using setData() which provides several overloads to all setting the data with the supported types. Note that the types are coverted to string and stored in the WSqlDatum.
Definition at line 29 of file wsqlfield.h.
WSql::WSqlField::WSqlField | ( | ) |
WSql::WSqlField::WSqlField | ( | const std::string & | fieldName, |
const std::string & | columnName = std::string() |
||
) |
Constructs an empty WSqlField with the name set to fieldName and the column name set to columnName. If columnName is not supplied it is assumed to be the same as fieldName and set accordingly.
Definition at line 92 of file wsqlfield.cpp.
WSql::WSqlField::~WSqlField | ( | ) |
Destroys the object and frees any allocated resources.
Definition at line 141 of file wsqlfield.cpp.
void WSql::WSqlField::clear | ( | ) |
Clears the value of the field and resets the precision to the default If the field is read-only, nothing happens.
Definition at line 177 of file wsqlfield.cpp.
std::string WSql::WSqlField::columnName | ( | ) | const [inline] |
Returns the name of the column as defined in the database..
Note that this is the name as it is in the actual database and not necessarily the name of the field returned which may be an alias defined in the query.
Definition at line 65 of file wsqlfield.h.
template< typename T > T WSql::WSqlField::data | ( | ) | [inline] |
Returns the field's type as defined in the database.
Returns the value of the data in various formats. Valid return values are native C++ types (eg. int, long, float, double, etc.) or std::string. Example:
WSqlField field; // ... set field with some value double d = 1223.34; field.setData(d); double dd = field.data<double>(); //dd contains 1223.34 int i = field.data<int>(); //i contains 1223 string s = field.data<string>(); //s contains "1223.34"
Definition at line 50 of file wsqlfield.h.
const bool WSql::WSqlField::isDirty | ( | ) | const [inline] |
Definition at line 63 of file wsqlfield.h.
std::string WSql::WSqlField::name | ( | ) | const [inline] |
Returns the name of the field in the record.
Note that this may be different from the actual name of the column defined in the database if an alias was defined in the query.
Definition at line 64 of file wsqlfield.h.
bool WSql::WSqlField::operator!= | ( | const WSqlField & | other | ) | const [inline] |
Returns true if the field is unequal to other; otherwise returns false.
Definition at line 40 of file wsqlfield.h.
Sets the field equal to other.
Definition at line 106 of file wsqlfield.cpp.
bool WSql::WSqlField::operator== | ( | const WSqlField & | other | ) | const |
Returns true if the field is equal to other; otherwise returns false.
Definition at line 126 of file wsqlfield.cpp.
const int WSql::WSqlField::precision | ( | ) | const [inline] |
Definition at line 66 of file wsqlfield.h.
const WSqlDatum& WSql::WSqlField::rawDatum | ( | ) | [inline] |
Definition at line 55 of file wsqlfield.h.
void WSql::WSqlField::setColumnName | ( | const std::string & | name | ) | [inline] |
Sets the column name of the field to name. Note that this does not (yet) effect the actual column name in the database.
Definition at line 59 of file wsqlfield.h.
void WSql::WSqlField::setData | ( | int | i | ) | [inline] |
Definition at line 45 of file wsqlfield.h.
void WSql::WSqlField::setData | ( | double | d | ) | [inline] |
Definition at line 48 of file wsqlfield.h.
void WSql::WSqlField::setData | ( | float | f | ) | [inline] |
Definition at line 47 of file wsqlfield.h.
void WSql::WSqlField::setData | ( | long | l | ) | [inline] |
Definition at line 46 of file wsqlfield.h.
void WSql::WSqlField::setData | ( | std::string | value | ) | [inline] |
Functions for setting the value of the data.
These functions set the value of the field to value. If the field is read-only (isReadOnly() returns true), nothing happens. The data type of value must be either a native C++ type (eg. int, long, double, etc ) or a std::string. The value is converted (if numeric) and stored as a string. The default floating point precision for setting the value is 2 - greater precision can be had by using setPrecision() before setting the value.
Definition at line 43 of file wsqlfield.h.
void WSql::WSqlField::setData | ( | short | sh | ) | [inline] |
Definition at line 44 of file wsqlfield.h.
void WSql::WSqlField::setIsDirty | ( | bool | b | ) | [inline] |
Definition at line 60 of file wsqlfield.h.
void WSql::WSqlField::setName | ( | const std::string & | name | ) | [inline] |
Sets the name of the field to name. This will correspond to the column name or be the alias defined in the query.
Definition at line 58 of file wsqlfield.h.
void WSql::WSqlField::setPrecision | ( | int | precision | ) | [inline] |
Sets the field's precision. This only affects numeric fields.
Definition at line 61 of file wsqlfield.h.