oos::query Class Reference

Creates a SQL query. More...

#include <query.hpp>

Public Member Functions

 query (session &s)
 
 query (database &s)
 
querycreate (const prototype_node &node)
 
querycreate (const std::string &name, object_atomizable *o)
 
querydrop (const prototype_node &node)
 
querydrop (const std::string &name)
 
queryselect ()
 
queryselect (const prototype_node &node)
 
queryselect (object_atomizable *o)
 
queryinsert (object *o)
 
queryinsert (object_atomizable *o, const std::string &name)
 
queryupdate (object *o)
 
queryupdate (const std::string &name, object_atomizable *o)
 
queryupdate (const std::string &table)
 
queryremove (const prototype_node &node)
 
querywhere (const std::string &clause)
 
querywhere (const condition &c)
 
queryand_ (const condition &c)
 
queryor_ (const condition &c)
 
queryorder_by (const std::string &by)
 
querylimit (int l)
 
querygroup_by (const std::string &field)
 
querycolumn (const std::string &name, data_type_t type)
 
queryfrom (const std::string &table)
 
template<class T >
queryset (const std::string &column, data_type_t type, const T &val)
 
result * execute ()
 
statement * prepare ()
 
queryreset ()
 

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
sThe session.
oos::query::query ( database &  s)

Create a new query for the given database.

Parameters
sThe database.

Member Function Documentation

query& oos::query::and_ ( const condition c)

Adds an and clause condition to the where clause.

Parameters
cThe 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
nameThe name of the column.
typeThe 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
nodeThe 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
nameThe name of the table to create.
oThe 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
nodeThe 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
nameThe 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
tableThe 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
fieldThe group by clause.
Returns
A reference to the query.
query& oos::query::insert ( object o)

Creates an insert statement based on the given object.

Parameters
oThe 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
oThe serializable object used for the insert statement.
nameThe 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
lThe limit clause.
Returns
A reference to the query.
query& oos::query::or_ ( const condition c)

Adds an or clause condition to the where clause.

Parameters
cThe 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
byThe 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
nodeThe 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
nodeThe 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
oThe serializable object used for the select statement.
Returns
A reference to the query.
template<class T >
query& oos::query::set ( const std::string &  column,
data_type_t  type,
const T &  val 
)
inline

This method must only be called for an update statement. Sets for the given column the data type and a value.

Template Parameters
TThe value type.
Parameters
columnThe column name.
typeThe data type.
valThe value to set.
Returns
A reference to the query.
query& oos::query::update ( object o)

Creates an update statement based on the given object.

Parameters
oThe 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
nameThe name of the table.
oThe 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
tableThe 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
clauseThe where clause.
Returns
A reference to the query.
query& oos::query::where ( const condition c)

Adds a where clause condition to the select or update statement. For any other query an exception is thrown.

Parameters
cThe condition.
Returns
A reference to the query.

The documentation for this class was generated from the following file:
  • database/query.hpp