Wexus2 0.20
|
#include <ActiveRecord.h>
Public Member Functions | |
virtual QVariant | getIDAsVariant (void) |
implementation | |
ActiveClass * | activeClass (void) const |
void | clear (void) |
void | test (Context::Errors *outerrors=0) const |
bool | fromForm (const QVariant &v=QVariant()) |
QString | toString (void) const |
void | setFilterColumn (int colindex) |
void | order (const ActiveExpr &orderByExpr) |
void | all (void) |
void | where (const ActiveExpr &whereExpr) |
void | find (const QVariant &keyVal) |
bool | exists (const QVariant &keyVal) |
bool | first (const ActiveExpr &whereExpr=ActiveExpr()) |
bool | last (const ActiveExpr &whereExpr=ActiveExpr()) |
void | create (const QVariant &v=QVariant()) |
void | save (void) |
void | destroy (void) |
void | destroy (const QVariant &keyVal) |
void | destroyAll (const ActiveExpr &whereExpr=ActiveExpr()) |
int | count (const ActiveExpr &whereExpr=ActiveExpr()) |
bool | next (void) |
Static Public Member Functions | |
static QSqlDatabase & | database (void) |
static void | check (const QSqlQuery &qy) |
static void | check (bool b, const QString &exceptionMsg="ActiveRecord::check(bool) failed") |
Protected Member Functions | |
ActiveRecord (ActiveClass *klass) | |
ctor, protected. this class is meanted to be inherited from. | |
ActiveExpr | filterExpr (const ActiveExpr &e) |
void | resetQuery (void) |
void | setQuery (std::shared_ptr< QSqlQuery > qry) |
void | internalWhere (const ActiveExpr &whereExpr, int limit) |
The base class for all Wexus-generated user records. This is a type of ORM.
ActiveClass* wexus::ActiveRecord::activeClass | ( | void | ) | const [inline] |
Returns the active class for this record. Should never be null.
void wexus::ActiveRecord::all | ( | void | ) |
Returns all the records.
void wexus::ActiveRecord::clear | ( | void | ) |
Resets the fields to default values... usually -1 for ints and empty strings.
Skips the filter column, if set.
int wexus::ActiveRecord::count | ( | const ActiveExpr & | whereExpr = ActiveExpr() | ) |
Returns the number of rows that match the given where query, or all the rows if no query is upplied.
void wexus::ActiveRecord::create | ( | const QVariant & | v = QVariant() | ) |
Inserts the current values into the database. If a specific id is desired, it must be passed here. Otherwise, one will be auto generated.
void wexus::ActiveRecord::destroy | ( | void | ) |
Removes the current record from the DB. Does nothing on failure.
void wexus::ActiveRecord::destroy | ( | const QVariant & | keyVal | ) |
Removes the record with the given primary key from the DB. Does nothing on failure.
void wexus::ActiveRecord::destroyAll | ( | const ActiveExpr & | whereExpr = ActiveExpr() | ) |
Deletes all the records that match the given query. A null query (the default), deletes all the rows. Does nothing on failure.
bool wexus::ActiveRecord::exists | ( | const QVariant & | keyVal | ) |
ActiveExpr wexus::ActiveRecord::filterExpr | ( | const ActiveExpr & | e | ) | [protected] |
Appends the column filter criteria (if any) to the given filter and returns that.
void wexus::ActiveRecord::find | ( | const QVariant & | keyVal | ) |
Finds the record that that has the given value as its primary key. Throws an exception on not-found.
bool wexus::ActiveRecord::first | ( | const ActiveExpr & | whereExpr = ActiveExpr() | ) |
Finds the loads the first record that matches the given whereExpr expression. This calls next() for, and returns true if that succeeded.
bool wexus::ActiveRecord::fromForm | ( | const QVariant & | v = QVariant() | ) |
Calls clear() first.
Extracts the fields from the given form map and calls test().
If is v is invalid (the default), then params[activeClass()->table()] will be assumed (this works with the Form(ActiveRecord&) class.
Returns true if atleast one field was extracted and errors is empty (after calling test())
bool wexus::ActiveRecord::last | ( | const ActiveExpr & | whereExpr = ActiveExpr() | ) |
Finds the loads the last record matches the given whereExpr expression. This calls next() for, and returns true if that succeeded.
bool wexus::ActiveRecord::next | ( | void | ) |
After running a query function, this will move the current row to the first row in the result set. Subsequent calls will move the current row to the next one. true is returns if the current row is valid.
void wexus::ActiveRecord::order | ( | const ActiveExpr & | orderByExpr | ) |
Sets the default ordering. If not called, the default is no ordering at all.
void wexus::ActiveRecord::save | ( | void | ) |
Saves the current values back into the database. You must not have changed the primary key value :)
The current query is unaffected, so you can continue iteration (with next()), for example.
void wexus::ActiveRecord::setFilterColumn | ( | int | colindex | ) |
Sets the filter column to use in all where clauses. By default this is -1, for none.
void wexus::ActiveRecord::test | ( | Context::Errors * | outerrors = 0 | ) | const |
Validates the fields in the current record against any defined validation checks.
outerrors should be Context::errors.
QString wexus::ActiveRecord::toString | ( | void | ) | const |
Returns a printable string reprensentation of the fields in this record.
void wexus::ActiveRecord::where | ( | const ActiveExpr & | whereExpr | ) |
Returns all the records that match the given whereExpr expression.