WORM 0.2
A C++ DAL/ORM code generation framework
|
The WSqlColumn class represents a column in SQL database tables. More...
#include <wsqlcolumn.h>
Public Member Functions | |
WSqlColumn () | |
WSqlColumn (const WSqlColumn &other) | |
virtual | ~WSqlColumn () |
virtual WSqlColumn & | operator= (const WSqlColumn &other) |
virtual bool | operator== (const WSqlColumn &other) const |
bool | operator!= (const WSqlColumn &other) const |
template<typename T > | |
void | setDefaultValue (const T t) |
template<typename T > | |
T | defaultValue () |
void | setVariableName (const std::string &name) |
Manually set the variableName to name. | |
void | setColumnName (const std::string &name) |
Set the column name to be name. | |
void | setMaxLength (int length) |
void | setPrecision (int precision) |
void | setDataType (WSqlDataType::Type type) |
void | setIsAutoIncremented (bool b) |
void | setCanBeNull (bool b) |
void | setIsPrimaryKey (bool b) |
void | setIsUnsigned (bool b) |
const std::string & | columnName () const |
const std::string & | variableName () const |
std::string | typeDeclaration () const |
Returns a C++ type declaration This method returns a string suitable for a type declaration of a variable in C++ code. | |
const int | maxLength () const |
const int | precision () const |
const WSqlDataType::Type | type () const |
bool | isAutoIncremented () const |
bool | canBeNull () const |
bool | isPrimaryKey () const |
bool | isUnsigned () const |
bool | typeIsSupported () const |
Returns true if the datatype of the column is supported by the ORM generator. |
The WSqlColumn class represents a column in SQL database tables.
WSqlColumn represents the characteristics of a single column in a database table, collection or view, including the column and variable name and the type of datum or value stored in the column at a single row, including the default defined in the database if possible which may be retrieved using defaultValue() - this is stored as a string.
A WSqlColumn object provides meta-data about the database column, for example: columnName(), dataType(), maxLength(), precision(), defaultValue(), and isReadOnly().
NOTE: This class is part of the metadata component - it is not used for queries, results, etc. As yet seting values here has no effect on the database
Definition at line 31 of file wsqlcolumn.h.
WSql::WSqlColumn::WSqlColumn | ( | ) |
Constructs an empty WSqlColumn
Definition at line 55 of file wsqlcolumn.cpp.
WSql::WSqlColumn::WSqlColumn | ( | const WSqlColumn & | other | ) |
Definition at line 68 of file wsqlcolumn.cpp.
WSql::WSqlColumn::~WSqlColumn | ( | ) | [virtual] |
Definition at line 83 of file wsqlcolumn.cpp.
bool WSql::WSqlColumn::canBeNull | ( | ) | const |
Returns true if this is not a required column and can be null; otherwise returns false. In other words, "NOT NULL" has not been set for this column.Note that if the column is AUTOINCREMENT this returns true as autoincrement columns should not have values assigned.
Definition at line 233 of file wsqlcolumn.cpp.
const std::string & WSql::WSqlColumn::columnName | ( | ) | const |
Returns the name of the column as defined in the database
Definition at line 201 of file wsqlcolumn.cpp.
T WSql::WSqlColumn::defaultValue | ( | ) | [inline] |
Definition at line 46 of file wsqlcolumn.h.
bool WSql::WSqlColumn::isAutoIncremented | ( | ) | const [inline] |
Definition at line 67 of file wsqlcolumn.h.
bool WSql::WSqlColumn::isPrimaryKey | ( | ) | const [inline] |
Definition at line 69 of file wsqlcolumn.h.
bool WSql::WSqlColumn::isUnsigned | ( | ) | const [inline] |
Definition at line 70 of file wsqlcolumn.h.
const int WSql::WSqlColumn::maxLength | ( | ) | const |
Returns the column's maximum length, ie. the number of characters (eg. VARCHAR(255)) as defined in the database. If there is no maximum it returns -1.
Definition at line 245 of file wsqlcolumn.cpp.
bool WSql::WSqlColumn::operator!= | ( | const WSqlColumn & | other | ) | const [inline] |
Returns true if this column is not identical to other; otherwise returns false.
Definition at line 40 of file wsqlcolumn.h.
WSqlColumn & WSql::WSqlColumn::operator= | ( | const WSqlColumn & | other | ) | [virtual] |
Sets this column equal to other.
Definition at line 90 of file wsqlcolumn.cpp.
bool WSql::WSqlColumn::operator== | ( | const WSqlColumn & | other | ) | const [virtual] |
Returns true if this column is identical to other; otherwise returns false.
Definition at line 114 of file wsqlcolumn.cpp.
const int WSql::WSqlColumn::precision | ( | ) | const |
Returns the column's precision; this is only meaningful for numeric types. Note that the default is 2 which supports monetary format.
Definition at line 255 of file wsqlcolumn.cpp.
void WSql::WSqlColumn::setCanBeNull | ( | bool | b | ) | [inline] |
Definition at line 57 of file wsqlcolumn.h.
void WSql::WSqlColumn::setColumnName | ( | const std::string & | name | ) |
Set the column name to be name.
This sets the column name to name. This refers to the name of the column as defined in the database, eg. "first_name". Additionally this method will set the _variableName as a transformed version of the column name. Eg. "first_name" will be set as a variable name of "firstName"
Definition at line 172 of file wsqlcolumn.cpp.
void WSql::WSqlColumn::setDataType | ( | WSqlDataType::Type | type | ) |
Sets the data type for the column.
Definition at line 155 of file wsqlcolumn.cpp.
void WSql::WSqlColumn::setDefaultValue | ( | const T | t | ) | [inline] |
Definition at line 42 of file wsqlcolumn.h.
void WSql::WSqlColumn::setIsAutoIncremented | ( | bool | b | ) | [inline] |
Definition at line 56 of file wsqlcolumn.h.
void WSql::WSqlColumn::setIsPrimaryKey | ( | bool | b | ) | [inline] |
Definition at line 58 of file wsqlcolumn.h.
void WSql::WSqlColumn::setIsUnsigned | ( | bool | b | ) | [inline] |
Definition at line 59 of file wsqlcolumn.h.
void WSql::WSqlColumn::setMaxLength | ( | int | length | ) | [inline] |
Definition at line 53 of file wsqlcolumn.h.
void WSql::WSqlColumn::setPrecision | ( | int | precision | ) |
Sets the column's floating point precision. This only affects numeric columns.
Note also that this does not (yet) change the actual definition in the database.
Definition at line 137 of file wsqlcolumn.cpp.
void WSql::WSqlColumn::setVariableName | ( | const std::string & | name | ) |
Manually set the variableName to name.
This sets the variable name to name. This is the name of the class variable corresponding to the column name. So, for instance "first_name" will be a variable firstName with ORM generated gettor firstName() and settor setFirstName(string).
Note that manually setting the variable name is not normally used - it is done automatically by setColumnName(). This is provided to override the default behavior in cases like a view or alias where the column name may be different from the field name.
Definition at line 192 of file wsqlcolumn.cpp.
const WSqlDataType::Type WSql::WSqlColumn::type | ( | ) | const |
Returns the column's type as stored in the database. Note that numerical values are also stored as string to prevent precision loss (and since that is how they are frequently received from the database) - and to facilitate easy conversion.
Definition at line 221 of file wsqlcolumn.cpp.
std::string WSql::WSqlColumn::typeDeclaration | ( | ) | const |
Returns a C++ type declaration This method returns a string suitable for a type declaration of a variable in C++ code.
Definition at line 262 of file wsqlcolumn.cpp.
bool WSql::WSqlColumn::typeIsSupported | ( | ) | const |
Returns true if the datatype of the column is supported by the ORM generator.
Definition at line 309 of file wsqlcolumn.cpp.
const std::string & WSql::WSqlColumn::variableName | ( | ) | const |
Returns the name of the class variable that corresponds to the column.
Definition at line 209 of file wsqlcolumn.cpp.