Wt: Wt::Dbo::query_result_traits< Result > Class Template Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
Wt::Dbo::query_result_traits< Result > Class Template Reference
Database Objects (Wt::Dbo)

Traits class for result types. More...

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

## Static Public Member Functions
static void | getFields (Session &session, std::vector< std::string > *aliases, std::vector< FieldInfo > &result)
| Obtains the list of fields in this result.
static Result | load (Session &session, SqlStatement &statement, int &column)
| Reads a result from an executed query.
static void | getValues (const Result &result, std::vector< cpp17::any > &values)
| Returns result values.
static void | setValue (Result &result, int &index, const cpp17::any &value)
| Sets a result value.
static Result | create ()
| Creates a new result.
static void | add (Session &session, Result &result)
| Adds a new result to the session.
static void | remove (Result &result)
| Removes a result from the session.
static long long | id (const Result &result)
| Returns a unique id for a result.
static Result | findById (Session &session, long long id)
| Find a result by id.

## Detailed Description

template<typename Result>
class Wt::Dbo::query_result_traits< Result >

Traits class for result types.

This traits class may be used to add support for using classes or structs as a result for a Session::query().

The library provides by default support for primitive types, using sql_value_traits, mapped objects held by ptr types, and std::tuple<> or any combination of these.

See also
  sql_value_traits, ptr

## Member Function Documentation

## ◆ add()

template<typename Result >

void Wt::Dbo::query_result_traits< Result >::add | ( | Session & | session,
|  | Result & | result )
| static

Adds a new result to the session.

Adds a (newly created) result to a session.

This method needs to be implemented only if you want to create new results from a QueryModel (which implements Wt's MVC item model).

## ◆ create()

template<typename Result >

Result Wt::Dbo::query_result_traits< Result >::create | ( |  | ) |
| static

Creates a new result.

Creates a new result. This should initialize a result so that its values can be set using setValue() or read using getValues().

The result should not yet be associated with a session.

This method needs to be implemented only if you want to create new results from a QueryModel (which implements Wt's MVC item model).

## ◆ findById()

template<typename Result >

Result Wt::Dbo::query_result_traits< Result >::findById | ( | Session & | session,
|  | long long | id )
| static

Find a result by id.

This needs to be inverse of id()

## ◆ getFields()

template<typename Result >

void Wt::Dbo::query_result_traits< Result >::getFields | ( | Session & | session,
|  | std::vector< std::string > * | aliases,
|  | std::vector< FieldInfo > & | result )
| static

Obtains the list of fields in this result.

This is used to build the select clause of an Sql query.

The given `aliases` may be used to qualify fields that correspond to entire tables (popping values from the front of this vector). An exception is thrown if not enough aliases were provided.

This method is needed when you want to use Result as the result of query.

## ◆ getValues()

template<typename Result >

void Wt::Dbo::query_result_traits< Result >::getValues | ( | const Result & | result,
|  | std::vector< cpp17::any > & | values )
| static

Returns result values.

This returns the individual field values in the given `result`.

This method needs to be implemented only if you want to display the result in a QueryModel (which implements Wt's MVC item model).

## ◆ id()

template<typename Result >

long long Wt::Dbo::query_result_traits< Result >::id | ( | const Result & | result | ) |
| static

Returns a unique id for a result.

This method needs to be implemented to return a unique id for a result which can later be used to find the result.

If not supported, return -1.

See also
  findbyId()

## ◆ load()

template<typename Result >

Result Wt::Dbo::query_result_traits< Result >::load | ( | Session & | session,
|  | SqlStatement & | statement,
|  | int & | column )
| static

Reads a result from an executed query.

This reads the value from the `statement`, starting at column `column`, and advancing the column pointer for as many columns as needed (and according to the number of fields returned by getFields()).

This method is needed when you want to use Result as the result of query.

## ◆ remove()

template<typename Result >

void Wt::Dbo::query_result_traits< Result >::remove | ( | Result & | result | ) |
| static

Removes a result from the session.

This method needs to be implemented only if you want to remove results from a QueryModel (which implements Wt's MVC item model).

## ◆ setValue()

template<typename Result >

void Wt::Dbo::query_result_traits< Result >::setValue | ( | Result & | result,
|  | int & | index,
|  | const cpp17::any & | value )
| static

Sets a result value.

Sets the value at `index`, where index indicates the field whose value needs to be updated.

When `index` is out-of-bounds, it should be decremented with as many fields as there are in this result type. Otherwise, index should be set to -1 after the value has been set.

This method needs to be implemented only if you want to modify the result from a QueryModel (which implements Wt's MVC item model).