Wexus2 0.20
wexus::ActiveRecord Class Reference

#include <ActiveRecord.h>

Inheritance diagram for wexus::ActiveRecord:

List of all members.

Public Member Functions

virtual QVariant getIDAsVariant (void)
 implementation
ActiveClassactiveClass (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)

Detailed Description

The base class for all Wexus-generated user records. This is a type of ORM.

Author:
Aleksander Demko

Member Function Documentation

ActiveClass* wexus::ActiveRecord::activeClass ( void  ) const [inline]

Returns the active class for this record. Should never be null.

Author:
Aleksander Demko
void wexus::ActiveRecord::all ( void  )

Returns all the records.

Author:
Aleksander Demko
void wexus::ActiveRecord::clear ( void  )

Resets the fields to default values... usually -1 for ints and empty strings.

Skips the filter column, if set.

Author:
Aleksander Demko
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.

Author:
Aleksander Demko
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.

Author:
Aleksander Demko
void wexus::ActiveRecord::destroy ( void  )

Removes the current record from the DB. Does nothing on failure.

Author:
Aleksander Demko
void wexus::ActiveRecord::destroy ( const QVariant &  keyVal)

Removes the record with the given primary key from the DB. Does nothing on failure.

Author:
Aleksander Demko
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.

Author:
Aleksander Demko
bool wexus::ActiveRecord::exists ( const QVariant &  keyVal)

Same as find(), except returns false on failure. find() raises an exception.

Author:
Aleksander Demko
ActiveExpr wexus::ActiveRecord::filterExpr ( const ActiveExpr e) [protected]

Appends the column filter criteria (if any) to the given filter and returns that.

Author:
Aleksander Demko
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.

Author:
Aleksander Demko
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.

Author:
Aleksander Demko
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())

Author:
Aleksander Demko
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.

Author:
Aleksander Demko
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.

Author:
Aleksander Demko
void wexus::ActiveRecord::order ( const ActiveExpr orderByExpr)

Sets the default ordering. If not called, the default is no ordering at all.

Author:
Aleksander Demko
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.

Author:
Aleksander Demko
void wexus::ActiveRecord::setFilterColumn ( int  colindex)

Sets the filter column to use in all where clauses. By default this is -1, for none.

Author:
Aleksander Demko
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.

Author:
Aleksander Demko
QString wexus::ActiveRecord::toString ( void  ) const

Returns a printable string reprensentation of the fields in this record.

Author:
Aleksander Demko
void wexus::ActiveRecord::where ( const ActiveExpr whereExpr)

Returns all the records that match the given whereExpr expression.

Author:
Aleksander Demko

The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Enumerations Enumerator