WORM 0.2
A C++ DAL/ORM code generation framework
|
The WSqlRecord class represents a database record. More...
#include <wsqlrecord.h>
Public Member Functions | |
WSqlRecord () | |
WSqlRecord (const WSqlRecord &other) | |
WSqlRecord & | operator= (const WSqlRecord &other) |
~WSqlRecord () | |
bool | operator== (const WSqlRecord &other) const |
bool | operator!= (const WSqlRecord &other) const |
std::string | operator[] (const std::string fieldname) const |
Operator to return the data in field fieldname This operator allows for easy access to field data - for example: | |
std::string | operator[] (const char *fieldname) const |
void | append (WSqlField field) |
WSqlField | at (int pos) const |
WSqlField | field (int pos) const |
WSqlField | field (const std::string &colname) const |
std::string | data (int pos) const |
std::string | data (const std::string &colname) const |
bool | isNull (int i) const |
bool | isNull (const std::string &name) const |
int | indexOf (const std::string &name) const |
bool | isValid () const |
bool | empty () |
int | size () const |
int | count () const |
const std::vector< WSqlField > & | fields () const |
void | setNull (int i) |
void | setNull (const std::string &name) |
void | clear () |
The WSqlRecord class represents a database record.
The WSqlRecord class represents a database record (AKA a "row") returned from a SELECT query as a vector of WSqlFields. WSqlRecord supports adding and removing fields as well as setting and retrieving field names, data values and some metadata.
The data values of a record's fields can be set by name or position with setData(). To find the position of a field by name use indexOf(), and to find the name of a field at a particular position use at().name() Use field() to retrieve a WSqlField object for a field by name or position. To get a vector of all WSqlFields use fields().
There are some convenience operators for getting the data from fields as well - operator[] supports fetching the data from a field by its name:
std::string fieldname = "user_name";
std::string username = record[fieldname];
This can also be used with plain const char* strings:
std::string username = record["user_name"];
A record can have fields added with append() or insert(), replaced with replace(), and removed with remove(). All the fields can be removed with clear(). The number of fields is given by count().
WSqlRecord is used to populate a WSqlResult set.
Definition at line 30 of file wsqlrecord.h.
WSql::WSqlRecord::WSqlRecord | ( | ) |
Definition at line 63 of file wsqlrecord.cpp.
WSql::WSqlRecord::WSqlRecord | ( | const WSqlRecord & | other | ) |
Definition at line 68 of file wsqlrecord.cpp.
WSql::WSqlRecord::~WSqlRecord | ( | ) |
Definition at line 73 of file wsqlrecord.cpp.
void WSql::WSqlRecord::append | ( | WSqlField | field | ) | [inline] |
Definition at line 43 of file wsqlrecord.h.
WSqlField WSql::WSqlRecord::at | ( | int | pos | ) | const |
Definition at line 145 of file wsqlrecord.cpp.
void WSql::WSqlRecord::clear | ( | ) |
Definition at line 177 of file wsqlrecord.cpp.
int WSql::WSqlRecord::count | ( | ) | const [inline] |
Definition at line 56 of file wsqlrecord.h.
std::string WSql::WSqlRecord::data | ( | int | pos | ) | const |
Returns the value of the field located at position index in the record. If index is out of bounds, an invalid WSqlDatum is returned.
Definition at line 113 of file wsqlrecord.cpp.
std::string WSql::WSqlRecord::data | ( | const std::string & | colname | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the value of the field called name in the record. If field name does not exist an invalid WSqlDatum is returned.
Definition at line 126 of file wsqlrecord.cpp.
bool WSql::WSqlRecord::empty | ( | ) | [inline] |
Definition at line 54 of file wsqlrecord.h.
WSqlField WSql::WSqlRecord::field | ( | const std::string & | colname | ) | const |
Definition at line 153 of file wsqlrecord.cpp.
WSqlField WSql::WSqlRecord::field | ( | int | pos | ) | const |
Definition at line 140 of file wsqlrecord.cpp.
const std::vector<WSqlField>& WSql::WSqlRecord::fields | ( | ) | const [inline] |
Definition at line 60 of file wsqlrecord.h.
int WSql::WSqlRecord::indexOf | ( | const std::string & | name | ) | const |
Definition at line 158 of file wsqlrecord.cpp.
bool WSql::WSqlRecord::isNull | ( | const std::string & | name | ) | const |
Definition at line 131 of file wsqlrecord.cpp.
bool WSql::WSqlRecord::isNull | ( | int | i | ) | const |
Definition at line 135 of file wsqlrecord.cpp.
bool WSql::WSqlRecord::isValid | ( | ) | const [inline] |
Definition at line 53 of file wsqlrecord.h.
bool WSql::WSqlRecord::operator!= | ( | const WSqlRecord & | other | ) | const [inline] |
Definition at line 39 of file wsqlrecord.h.
WSqlRecord & WSql::WSqlRecord::operator= | ( | const WSqlRecord & | other | ) |
Definition at line 78 of file wsqlrecord.cpp.
bool WSql::WSqlRecord::operator== | ( | const WSqlRecord & | other | ) | const |
Definition at line 84 of file wsqlrecord.cpp.
std::string WSql::WSqlRecord::operator[] | ( | const std::string | fieldname | ) | const [inline] |
Operator to return the data in field fieldname This operator allows for easy access to field data - for example:
std::string username = record[std::string("user_name")];
Definition at line 40 of file wsqlrecord.h.
std::string WSql::WSqlRecord::operator[] | ( | const char * | fieldname | ) | const [inline] |
Definition at line 41 of file wsqlrecord.h.
void WSql::WSqlRecord::setNull | ( | const std::string & | name | ) |
Definition at line 89 of file wsqlrecord.cpp.
void WSql::WSqlRecord::setNull | ( | int | i | ) |
Definition at line 93 of file wsqlrecord.cpp.
int WSql::WSqlRecord::size | ( | ) | const [inline] |
Definition at line 55 of file wsqlrecord.h.