Creates a SQL query. More...
#include <query.hpp>
Public Member Functions | |
query (session &s) | |
query (database &s) | |
query & | create (const prototype_node &node) |
query & | create (const std::string &name, object_atomizable *o) |
query & | drop (const prototype_node &node) |
query & | drop (const std::string &name) |
query & | select () |
query & | select (const prototype_node &node) |
query & | select (object_atomizable *o) |
query & | insert (object *o) |
query & | insert (object_atomizable *o, const std::string &name) |
query & | update (object *o) |
query & | update (const std::string &name, object_atomizable *o) |
query & | update (const std::string &table) |
query & | remove (const prototype_node &node) |
query & | where (const std::string &clause) |
query & | where (const condition &c) |
query & | and_ (const condition &c) |
query & | or_ (const condition &c) |
query & | order_by (const std::string &by) |
query & | limit (int l) |
query & | group_by (const std::string &field) |
query & | column (const std::string &name, data_type_t type) |
query & | from (const std::string &table) |
template<class T > | |
query & | set (const std::string &column, data_type_t type, const T &val) |
result * | execute () |
statement * | prepare () |
query & | reset () |
Detailed Description
Creates a SQL query.
The query class represents a SQL query for any database provided by the backend driver libraries.
With this class at hand you can create
- create
- drop
- select
- insert
- update
- delete
statements. These statements can be created manually by adding each part of the statement by hand or you can create them using object based class or instances.
The class uses a chain mechanism. Each method representing a part of a query returns the reference to itself. So you can concatenate your query parts by calling the methods in a chain (concatenated by dots).
Constructor & Destructor Documentation
oos::query::query | ( | session & | s | ) |
Create a new query for the given session.
- Parameters
-
s The session.
oos::query::query | ( | database & | s | ) |
Create a new query for the given database.
- Parameters
-
s The database.
Member Function Documentation
Adds an and clause condition to the where clause.
- Parameters
-
c The condition.
- Returns
- A reference to the query.
query& oos::query::column | ( | const std::string & | name, |
data_type_t | type | ||
) |
Adds a column to a select statement.
- Parameters
-
name The name of the column. type The datatype of the column,
- Returns
- A reference to the query.
query& oos::query::create | ( | const prototype_node & | node | ) |
Creates a create statement based on the given prototype node.
- Parameters
-
node The prototype node used for the create statement.
- Returns
- A reference to the query.
query& oos::query::create | ( | const std::string & | name, |
object_atomizable * | o | ||
) |
Creates a create statement based on a given name and a serializable class instance.
- Parameters
-
name The name of the table to create. o The serializable object providing the field information.
- Returns
- A reference to the query.
query& oos::query::drop | ( | const prototype_node & | node | ) |
Creates a drop statement based on the given prototype node.
- Parameters
-
node The prototype node used for the drop statement.
- Returns
- A reference to the query.
query& oos::query::drop | ( | const std::string & | name | ) |
Creates a drop statement based on the given table name.
- Parameters
-
name The name of the table.
- Returns
- A reference to the query.
result* oos::query::execute | ( | ) |
Executes the current query and returns a new result object.
- Returns
- The result object.
query& oos::query::from | ( | const std::string & | table | ) |
Appends the given table name to the select query. Must only be called for a select statement and after the queried columns are appended.
- Parameters
-
table The name of the table.
- Returns
- A reference to the query.
query& oos::query::group_by | ( | const std::string & | field | ) |
Adds a group by clause to a select statement.
- Parameters
-
field The group by clause.
- Returns
- A reference to the query.
Creates an insert statement based on the given object.
- Parameters
-
o The object used for the insert statement.
- Returns
- A reference to the query.
query& oos::query::insert | ( | object_atomizable * | o, |
const std::string & | name | ||
) |
Creates an insert statement based on the given serializable object and. the name of the table
- Parameters
-
o The serializable object used for the insert statement. name The name of the table.
- Returns
- A reference to the query.
query& oos::query::limit | ( | int | l | ) |
Adds a limit clause to a select statement.
- Parameters
-
l The limit clause.
- Returns
- A reference to the query.
Adds an or clause condition to the where clause.
- Parameters
-
c The condition.
- Returns
- A reference to the query.
query& oos::query::order_by | ( | const std::string & | by | ) |
Adds an order by clause to a select statement.
- Parameters
-
by The order by clause.
- Returns
- A reference to the query.
statement* oos::query::prepare | ( | ) |
Creates and returns a prepared statement based on the current query.
- Returns
- The new prepared statement.
query& oos::query::remove | ( | const prototype_node & | node | ) |
Creates a delete statement based on the given prototype node.
- Parameters
-
node The prototype node used for the delete statement.
- Returns
- A reference to the query.
query& oos::query::reset | ( | ) |
Resets the query.
- Returns
- A reference to the query.
query& oos::query::select | ( | ) |
Creates a select statement without any selection. All columns must be added manually via the column method.
- Returns
- A reference to the query.
query& oos::query::select | ( | const prototype_node & | node | ) |
Creates a select statement based on the given prototype node.
- Parameters
-
node The prototype node used for the select statement.
- Returns
- A reference to the query.
query& oos::query::select | ( | object_atomizable * | o | ) |
Creates a select statement based on the given serializable object.
- Parameters
-
o The serializable object used for the select statement.
- Returns
- A reference to the query.
|
inline |
This method must only be called for an update statement. Sets for the given column the data type and a value.
- Template Parameters
-
T The value type.
- Parameters
-
column The column name. type The data type. val The value to set.
- Returns
- A reference to the query.
Creates an update statement based on the given object.
- Parameters
-
o The object used for the update statement.
- Returns
- A reference to the query.
query& oos::query::update | ( | const std::string & | name, |
object_atomizable * | o | ||
) |
Creates an update statement based on the given serializable object and. the name of the table
- Parameters
-
name The name of the table. o The serializable object used for the update statement.
- Returns
- A reference to the query.
query& oos::query::update | ( | const std::string & | table | ) |
Creates an update statement without any settings. All columns must be added manually via the set method. Just the name of the table is given.
- Parameters
-
table The name of the table.
- Returns
- A reference to the query.
query& oos::query::where | ( | const std::string & | clause | ) |
Adds a where clause string to the select or update statement. For any other query an exception is thrown.
- Parameters
-
clause The where clause.
- Returns
- A reference to the query.
Adds a where clause condition to the select or update statement. For any other query an exception is thrown.
- Parameters
-
c The condition.
- Returns
- A reference to the query.
The documentation for this class was generated from the following file:
- database/query.hpp