WORM 0.2
A C++ DAL/ORM code generation framework
Public Member Functions

WSql::WSqlField Class Reference

The WSqlField class represents a field in a record. More...

#include <wsqlfield.h>

List of all members.

Public Member Functions

 WSqlField ()
 WSqlField (const std::string &fieldName, const std::string &columnName=std::string())
WSqlFieldoperator= (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 >
data ()
const WSqlDatumrawDatum ()
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

Detailed Description

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.

Note:
Inserts and updates using WSqlField are not yet supported (10/2011) .

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.

See also:
data() name() columnName() setData()
WSqlRecord WSqlDatum WSqlDataType

Definition at line 29 of file wsqlfield.h.


Constructor & Destructor Documentation

WSql::WSqlField::WSqlField ( )

Constructs an empty WSqlField

See also:
setName()

Definition at line 79 of file wsqlfield.cpp.

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.

See also:
setName() setDataType()

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.


Member Function Documentation

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.

See also:
setData()

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.

See also:
name() setColumnName()

Definition at line 65 of file wsqlfield.h.

template<typename T >
template< typename T > T WSql::WSqlField::data ( ) [inline]

Returns the field's type as defined in the database.

Todo:
decide if WSqlField needs/supports this (and other metadata) - also readOnly and so on ..
See also:
setDataType()

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"
See also:
setData() WSqlDatum

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.

See also:
columnName() setColumnName()

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.

WSqlField & WSql::WSqlField::operator= ( const WSqlField other)

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.

See also:
columnName()

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.

Todo:
implement that last sentence . set precision is tbd. To set the value to NULL, use clear().
See also:
data() setPrecision() isReadOnly()

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.

See also:
name()

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.

See also:
getPrecision()

Definition at line 61 of file wsqlfield.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines