Wt: Wt::Dbo::SqlStatement Class Reference

Wt 4.10.4

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

Abstract base class for a prepared SQL statement. More...

`#include <SqlStatement.h>`

## Public Member Functions
virtual | ~SqlStatement ()
| Destructor.
bool | use ()
| Uses the statement.
void | done ()
| Finish statement use.
virtual void | reset ()=0
| Resets the statement.
virtual void | bind (int column, const std::string &value)=0
| Binds a value to a column.
virtual void | bind (int column, short value)=0
| Binds a value to a column.
virtual void | bind (int column, int value)=0
| Binds a value to a column.
virtual void | bind (int column, long long value)=0
| Binds a value to a column.
virtual void | bind (int column, float value)=0
| Binds a value to a column.
virtual void | bind (int column, double value)=0
| Binds a value to a column.
virtual void | bind (int column, const std::chrono::system_clock::time_point &value, SqlDateTimeType type)=0
| Binds a value to a column.
virtual void | bind (int column, const std::chrono::duration< int, std::milli > &value)=0
| Binds a value to a column.
virtual void | bind (int column, const std::vector< unsigned char > &value)=0
| Binds a value to a column.
virtual void | bindNull (int column)=0
| Binds `null` to a column.
virtual void | execute ()=0
| Executes the statement.
virtual long long | insertedId ()=0
| Returns the id if the statement was an SQL `insert`.
virtual int | affectedRowCount ()=0
| Returns the affected number of rows.
virtual bool | nextRow ()=0
| Fetches the next result row.
virtual int | columnCount () const =0
| Returns the number of columns in the result.
virtual bool | getResult (int column, std::string *value, int size)=0
| Fetches a result value.
virtual bool | getResult (int column, short *value)=0
| Fetches a result value.
virtual bool | getResult (int column, int *value)=0
| Fetches a result value.
virtual bool | getResult (int column, long long *value)=0
| Fetches a result value.
virtual bool | getResult (int column, float *value)=0
| Fetches a result value.
virtual bool | getResult (int column, double *value)=0
| Fetches a result value.
virtual bool | getResult (int column, std::chrono::system_clock::time_point *value, SqlDateTimeType type)=0
| Fetches a result value.
virtual bool | getResult (int column, std::chrono::duration< int, std::milli > *value)=0
| Fetches a result value.
virtual bool | getResult (int column, std::vector< unsigned char > *value, int size)=0
| Fetches a result value.
virtual std::string | sql () const =0
| Returns the prepared SQL string.

## Detailed Description

Abstract base class for a prepared SQL statement.

The statement may be used multiple times, but cannot be used concurrently. It also cannot be copied.

This class is part of Wt::Dbo's backend API, and should not be used directly. Its interface must be reimplemented for each backend corresponding to a supported database.

See also
  SqlConnection

## Member Function Documentation

## ◆ affectedRowCount()

virtual int Wt::Dbo::SqlStatement::affectedRowCount | ( |  | ) |
| pure virtual

Returns the affected number of rows.

This is only useful for an SQL `update` or `delete` statement.

## ◆ columnCount()

virtual int Wt::Dbo::SqlStatement::columnCount | ( |  | ) | const
| pure virtual

Returns the number of columns in the result.

Note
  The column count may only be available after the query was executed.

## ◆ done()

void Wt::Dbo::SqlStatement::done | ( |  | ) |

Finish statement use.

Marks the statement as no longer used and resets the statement.

See also
  use()

## ◆ getResult() [1/9]

virtual bool Wt::Dbo::SqlStatement::getResult | ( | int | column,
|  | double * | value )
| pure virtual

Fetches a result value.

Returns `true` when the value was not `null`.

## ◆ getResult() [2/9]

virtual bool Wt::Dbo::SqlStatement::getResult | ( | int | column,
|  | float * | value )
| pure virtual

Fetches a result value.

Returns `true` when the value was not `null`.

## ◆ getResult() [3/9]

virtual bool Wt::Dbo::SqlStatement::getResult | ( | int | column,
|  | int * | value )
| pure virtual

Fetches a result value.

Returns `true` when the value was not `null`.

## ◆ getResult() [4/9]

virtual bool Wt::Dbo::SqlStatement::getResult | ( | int | column,
|  | long long * | value )
| pure virtual

Fetches a result value.

Returns `true` when the value was not `null`.

## ◆ getResult() [5/9]

virtual bool Wt::Dbo::SqlStatement::getResult | ( | int | column,
|  | short * | value )
| pure virtual

Fetches a result value.

Returns `true` when the value was not `null`.

## ◆ getResult() [6/9]

virtual bool Wt::Dbo::SqlStatement::getResult | ( | int | column,
|  | std::chrono::duration< int, std::milli > * | value )
| pure virtual

Fetches a result value.

Returns `true` when the value was not `null`.

## ◆ getResult() [7/9]

virtual bool Wt::Dbo::SqlStatement::getResult | ( | int | column,
|  | std::chrono::system_clock::time_point * | value,
|  | SqlDateTimeType | type )
| pure virtual

Fetches a result value.

Returns `true` when the value was not `null`.

## ◆ getResult() [8/9]

virtual bool Wt::Dbo::SqlStatement::getResult | ( | int | column,
|  | std::string * | value,
|  | int | size )
| pure virtual

Fetches a result value.

Returns `true` when the value was not `null`. The size is the expected size of sql string type and can be used to dimension buffers but the return string may be bigger.

## ◆ getResult() [9/9]

virtual bool Wt::Dbo::SqlStatement::getResult | ( | int | column,
|  | std::vector< unsigned char > * | value,
|  | int | size )
| pure virtual

Fetches a result value.

Returns `true` when the value was not `null`.

## ◆ nextRow()

virtual bool Wt::Dbo::SqlStatement::nextRow | ( |  | ) |
| pure virtual

Fetches the next result row.

Returns `true` if there was one more row to be fetched.

## ◆ use()

bool Wt::Dbo::SqlStatement::use | ( |  | ) |

Uses the statement.

Marks the statement as in-use. If the statement is already in use, return false. In that case, we will later provision that a statement can be cloned and that a list of equivalent statement is kept in the statement cache of a connectin.