Wt: Wt::Dbo::AbstractQuery Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Wt::Dbo::AbstractQuery Class Reference
Database Objects (Wt::Dbo)

An abstract dynamic database query. More...

`#include <Wt/Dbo/Query.h>`

Inheritance diagram for Wt::Dbo::AbstractQuery:
[legend]

## Public Member Functions
template<typename T >
AbstractQuery & | bind (const T &value)
| Binds a value to the next positional marker.
void | reset ()
| Resets bound values.
AbstractQuery & | join (const std::string &other)
| Adds a join.
AbstractQuery & | leftJoin (const std::string &other)
| Adds a left join.
AbstractQuery & | rightJoin (const std::string &other)
| Adds a right join.
AbstractQuery & | where (const std::string &condition)
| Adds a query condition.
AbstractQuery & | orWhere (const std::string &condition)
| Adds a query condition.
AbstractQuery & | orderBy (const std::string &fieldName)
| Sets the result order.
AbstractQuery & | groupBy (const std::string &fields)
| Sets the grouping field(s).
AbstractQuery & | having (const std::string &fields)
| Sets the grouping filter(s).
AbstractQuery & | offset (int count)
| Sets a result offset.
int | offset () const
| Returns an offset set for this query.
AbstractQuery & | limit (int count)
| Sets a result limit.
int | limit () const
| Returns a limit set for this query.

## Detailed Description

An abstract dynamic database query.

See also
  Query

## Member Function Documentation

## ◆ bind()

template<typename T >

AbstractQuery & Wt::Dbo::AbstractQuery::bind | ( | const T & | value | ) |

Binds a value to the next positional marker.

This binds the `value` to the next positional marker in the query condition.

## ◆ groupBy()

AbstractQuery & Wt::Dbo::AbstractQuery::groupBy | ( | const std::string & | fields | ) |

Sets the grouping field(s).

This is a convenience method for creating a SQL query, and sets a group by field expression for the current query.

Groups results based on unique values of the indicated field(s), which is a comma separated list of fields. Only fields on which you group and aggregate functions can be selected by a query.

A field that refers to a database object that is selected by the query is expanded to all the corresponding fields of that database object (as in the select statement).

## ◆ having()

AbstractQuery & Wt::Dbo::AbstractQuery::having | ( | const std::string & | fields | ) |

Sets the grouping filter(s).

It's like where(), but for aggregate fields.

For example you can't go:

select department.name, count(employees) from department where count(employees) > 5 group by count(employees);

Because you can't have aggregate fields in a where clause, but you can go:

select department.name, count(employees) from department group by count(employees) having count(employees) > 5;

This will of course return all the departments with more than 5 employees (and their employee count).

Note
  You must have a group by clause, in order to have a 'having' clause

## ◆ join()

AbstractQuery & Wt::Dbo::AbstractQuery::join | ( | const std::string & | other | ) |

Adds a join.

This is a convenience method for creating a SQL query, and concatenates a new join to the current query.

The join should be a valid SQL join expression, e.g. "customer c on o.customer_id = c.id"

Note
  This method is not available when using a DirectBinding binding strategy.

## ◆ leftJoin()

AbstractQuery & Wt::Dbo::AbstractQuery::leftJoin | ( | const std::string & | other | ) |

Adds a left join.

This is a convenience method for creating a SQL query, and concatenates a new left join to the current query.

The join should be a valid SQL join expression, e.g. "customer c on o.customer_id = c.id"

Note
  This method is not available when using a DirectBinding binding strategy.

## ◆ limit() [1/2]

int Wt::Dbo::AbstractQuery::limit | ( |  | ) | const

Returns a limit set for this query.

See also
  limit(int)

## ◆ limit() [2/2]

AbstractQuery & Wt::Dbo::AbstractQuery::limit | ( | int | count | ) |

Sets a result limit.

Sets a result limit. This has the effect that the next resultList() call will return up to `count` results. Use -1 to indicate no limit.

This provides the (non standard) limit part of an SQL query.

See also
  offset()

## ◆ offset() [1/2]

int Wt::Dbo::AbstractQuery::offset | ( |  | ) | const

Returns an offset set for this query.

See also
  offset(int)

## ◆ offset() [2/2]

AbstractQuery & Wt::Dbo::AbstractQuery::offset | ( | int | count | ) |

Sets a result offset.

Sets a result offset. This has the effect that the next resultList() call will skip as many results as the offset indicates. Use -1 to indicate no offset.

This provides the (non standard) offset part of an SQL query.

See also
  limit()

## ◆ orderBy()

AbstractQuery & Wt::Dbo::AbstractQuery::orderBy | ( | const std::string & | fieldName | ) |

Sets the result order.

This is a convenience method for creating a SQL query, and sets an order by field expression for the current query.

Orders the results based on the given field name (or multiple names, comma-separated).

## ◆ orWhere()

AbstractQuery & Wt::Dbo::AbstractQuery::orWhere | ( | const std::string & | condition | ) |

Adds a query condition.

This is a convenience method for creating a SQL query, and concatenates a new where condition expression to the current query.

The condition must be a valid SQL condition expression.

Multiple conditions may be provided by successive calls to orWhere(), and are concatenated together using 'or'. Previous conditions will be surrounded by brackets and the new condition will be concatenated using 'or'. For example:

query.where("column_a = ?").bind("A")
.where("column_b = ?").bind("B")
.orWhere("column_c = ?").bind("C");

results in: "where ((column_a = 'A') and (column_b = 'B')) or column_c = 'C'"

As with any part of the SQL query, a condition may contain positional markers '?' to which values may be bound using bind().

## ◆ reset()

void Wt::Dbo::AbstractQuery::reset | ( |  | ) |

Resets bound values.

This undoes all previous calls to bind().

## ◆ rightJoin()

AbstractQuery & Wt::Dbo::AbstractQuery::rightJoin | ( | const std::string & | other | ) |

Adds a right join.

This is a convenience method for creating a SQL query, and concatenates a new right join to the current query.

The join should be a valid SQL join expression, e.g. "customer c on o.customer_id = c.id"

Note
  This method is not available when using a DirectBinding binding strategy.

## ◆ where()

AbstractQuery & Wt::Dbo::AbstractQuery::where | ( | const std::string & | condition | ) |

Adds a query condition.

This is a convenience method for creating a SQL query, and concatenates a new where condition expression to the current query.

The condition must be a valid SQL condition expression.

Multiple conditions may be provided by successive calls to where(), which must each be fulfilled, and are concatenated together using 'and'.

As with any part of the SQL query, a condition may contain positional markers '?' to which values may be bound using bind().