Qx v0.7
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::SqlDqlQuery Class Reference

The SqlDqlQuery class represents SQL queries that fit into the data query language sub-language. More...

#include <qx/sql/qx-sqlquery.h>

Inheritance diagram for Qx::SqlDqlQuery:
[legend]

Public Member Functions

 SqlDqlQuery ()
 
 SqlDqlQuery (SqlDatabase &db)
 
template<QxSql::sql_containing Container>
SqlError appendExecute (Container &result)
 
template<sql_stringable First>
auto & ESCAPE (First &&fs)
 
template<QxSql::sql_containing Container>
SqlError execute (Container &result)
 
template<typename T>
SqlError execute (SqlResult< T > &result)
 
template<typename T>
SqlError execute (T &result)
 
auto & EXISTS (const SqlQuery &q)
 
template<sql_stringable First>
auto & GROUP_BY (First &&fs)
 
template<sql_stringable First>
auto & HAVING (First &&fs)
 
template<sql_stringable First>
auto & ILIKE (First &&fs)
 
template<sql_stringable First>
auto & JOIN (First &&fs)
 
template<sql_stringable First>
auto & LIKE (First &&fs)
 
template<sql_stringable First>
auto & LIMIT (First &&fs)
 
auto & NOT ()
 
template<sql_stringable First>
auto & NOT (First &&fs)
 
template<sql_stringable First>
auto & OFFSET (First &&fs)
 
template<sql_stringable First, sql_stringable ... Rest>
auto & ORDER_BY (First &&fs, Rest &&... s)
 
template<sql_stringable First>
auto & SIMILAR_TO (First &&fs)
 
- Public Member Functions inherited from Qx::AbstractSqlQuery< SqlDqlQuery >
auto & AS (First &&fs)
 
auto & BETWEEN (First &&fs)
 
auto & CASE ()
 
auto & DISTINCT ()
 
auto & ELSE (First &&fs)
 
auto & END ()
 
SqlDqlQueryFROM ()
 
auto & FROM (First &&fs, Rest &&... s)
 
SqlDqlQueryIN (const R &range)
 
auto & IN (const SqlQuery &q)
 
auto & IN (First &&fs, Rest &&... s)
 
auto & IS ()
 
auto & IS (First &&fs)
 
auto & ON (First &&fs)
 
SqlDqlQuerySELECT ()
 
SqlDqlQuerySELECT (First &&fsel, Rest &&... sel)
 
SqlDqlQuerySELECT_DISTINCT ()
 
SqlDqlQuerySELECT_DISTINCT (First &&fsel, Rest &&... sel)
 
auto & THEN (First &&fs)
 
SqlDqlQueryverbatim (const QString &sql, bool space=true)
 
auto & WHEN ()
 
auto & WHEN (First &&fs)
 
auto & WHERE ()
 
auto & WHERE (First &&fs)
 
- Public Member Functions inherited from Qx::SqlQuery
void bindValue (const QString &placeholder, const QVariant &val)
 
SqlDatabasedatabase ()
 
const SqlDatabasedatabase () const
 
bool hasDatabase () const
 
QString string () const
 

Detailed Description

A query can be created separately, but is most often created directly using one of the methods of SqlDatabase.

Constructor & Destructor Documentation

◆ SqlDqlQuery() [1/2]

Qx::SqlDqlQuery::SqlDqlQuery ( )

Creates a DQL query without an associated database.

A query without an associated database cannot be execute, but can be used as a sub-query.

◆ SqlDqlQuery() [2/2]

Qx::SqlDqlQuery::SqlDqlQuery ( SqlDatabase & db)

Creates a DQL query associated with database db.

Note
The database must stay valid for the lifetime of the query.

Member Function Documentation

◆ appendExecute()

template<QxSql::sql_containing Container>
SqlError Qx::SqlDqlQuery::appendExecute ( Container & result)
inline

Same as execute(Container&), except that the result buffer is not cleared and so the results are appended to the existing container, instead of replacing them.

See also
execute(Container&).

◆ ESCAPE()

template<sql_stringable First>
auto & Qx::SqlDqlQuery::ESCAPE ( First && fs)

Adds a ESCAPE clause to the query using fs and returns a reference to the query.

◆ execute() [1/3]

template<QxSql::sql_containing Container>
SqlError Qx::SqlDqlQuery::execute ( Container & result)
inline

Executes the query, placing the result into the container result. Each element of the result container corresponds to a row from the SQL result. If the original result has fields that are not present in the utilized struct, they will simply be omitted.

Note
This method is very convenient, but iterates all returned rows immediately in order to create the result container. If you expect the query to return a large number of rows, it is more efficient to use execute(SqlResult<T>& result).

A valid error is returned if there was an issue executing the query.

See also
appendExecute().

◆ execute() [2/3]

template<typename T>
SqlError Qx::SqlDqlQuery::execute ( SqlResult< T > & result)
inline

Executes the query, placing the result into result. If the original result has fields that are not present in the utilized struct, they will simply be omitted.

Note
This method is more efficient than execute(Container& result) as the returned rows can be iterated as needed using SqlResult instead of all at once.

A valid error is returned if there was an issue executing the query.

◆ execute() [3/3]

template<typename T>
SqlError Qx::SqlDqlQuery::execute ( T & result)
inline

Executes the query, placing the result into result. If the original result contains more than one row, only the first row is returned, and if empty, then result is set to a default constructed value.

A valid error is returned if there was an issue executing the query.

◆ EXISTS()

auto & Qx::SqlDqlQuery::EXISTS ( const SqlQuery & q)

Adds a EXISTS clause to the query using q as a sub-query and returns a reference to the query.

◆ GROUP_BY()

template<sql_stringable First>
auto & Qx::SqlDqlQuery::GROUP_BY ( First && fs)

Adds a GROUP BY clause to the query using fs and returns a reference to the query.

◆ HAVING()

template<sql_stringable First>
auto & Qx::SqlDqlQuery::HAVING ( First && fs)

Adds a HAVING clause to the query using fs and returns a reference to the query.

◆ ILIKE()

template<sql_stringable First>
auto & Qx::SqlDqlQuery::ILIKE ( First && fs)

Adds a ILIKE clause to the query using fs and returns a reference to the query.

◆ JOIN()

template<sql_stringable First>
auto & Qx::SqlDqlQuery::JOIN ( First && fs)

Adds a JOIN clause to the query using fs and returns a reference to the query.

◆ LIKE()

template<sql_stringable First>
auto & Qx::SqlDqlQuery::LIKE ( First && fs)

Adds a LIKE clause to the query using fs and returns a reference to the query.

◆ LIMIT()

template<sql_stringable First>
auto & Qx::SqlDqlQuery::LIMIT ( First && fs)

Adds a LIMIT clause to the query using fs and returns a reference to the query.

◆ NOT() [1/2]

auto & Qx::SqlDqlQuery::NOT ( )

Adds a NOT clause to the query and returns a reference to the query.

◆ NOT() [2/2]

template<sql_stringable First>
auto & Qx::SqlDqlQuery::NOT ( First && fs)

Adds a NOT clause to the query using fs and returns a reference to the query.

◆ OFFSET()

template<sql_stringable First>
auto & Qx::SqlDqlQuery::OFFSET ( First && fs)

Adds a OFFSET clause to the query using fs and returns a reference to the query.

◆ ORDER_BY()

template<sql_stringable First, sql_stringable ... Rest>
auto & Qx::SqlDqlQuery::ORDER_BY ( First && fs,
Rest &&... s )

Adds a ORDER BY clause to the query using fs through s and returns a reference to the query.

◆ SIMILAR_TO()

template<sql_stringable First>
auto & Qx::SqlDqlQuery::SIMILAR_TO ( First && fs)

Adds a SIMILAR TO clause to the query using fs and returns a reference to the query.


The documentation for this class was generated from the following files: