tntdb::Statement Class Reference

This class represents a sql-statement. More...

`#include <statement.h>`

## Classes

class | const_iterator
| This class represents a database-cursor. More...

## Public Types

typedef IStatement::size_type | size_type

## Public Member Functions

| Statement (IStatement *stmt_=0)
Statement & | clear ()
| Sets all hostvariables to NULL. More...
Statement & | setNull (const std::string &col)
| Sets the hostvariable with the given name to NULL. More...
Statement & | setBool (const std::string &col, bool data)
| Sets the hostvariable with the given name to a boolean value. More...
Statement & | setShort (const std::string &col, short data)
| Sets the hostvariable with the given name to a short value. More...
Statement & | setInt (const std::string &col, int data)
| Sets the hostvariable with the given name to a int value. More...
Statement & | setLong (const std::string &col, long data)
| Sets the hostvariable with the given name to a int value. More...
Statement & | setUnsignedShort (const std::string &col, unsigned short data)
| Sets the hostvariable with the given name to a unsigned short value. More...
Statement & | setUnsigned (const std::string &col, unsigned data)
| Sets the hostvariable with the given name to a unsigned value. More...
Statement & | setUnsignedLong (const std::string &col, unsigned long data)
| Sets the hostvariable with the given name to a unsigned long value. More...
Statement & | setInt32 (const std::string &col, int32_t data)
| Sets the hostvariable with the given name to a int32_t value. More...
Statement & | setUnsigned32 (const std::string &col, uint32_t data)
| Sets the hostvariable with the given name to a uint32_t value. More...
Statement & | setInt64 (const std::string &col, int64_t data)
| Sets the hostvariable with the given name to a int64_t value. More...
Statement & | setUnsigned64 (const std::string &col, uint64_t data)
| Sets the hostvariable with the given name to a uint64_t value. More...
Statement & | setDecimal (const std::string &col, const Decimal &data)
| Sets the hostvariable with the given name to a Decimal. More...
Statement & | setFloat (const std::string &col, float data)
| Sets the hostvariable with the given name to a float value. More...
Statement & | setDouble (const std::string &col, double data)
| Sets the hostvariable with the given name to a double value. More...
Statement & | setChar (const std::string &col, char data)
| Sets the hostvariable with the given name to a char value. More...
Statement & | setString (const std::string &col, const std::string &data)
| Sets the hostvariable with the given name to a string value. More...
Statement & | setString (const std::string &col, const char *data)
| Sets the hostvariable with the given name to a string value or null, if passing null-pointer. More...
Statement & | setUString (const std::string &col, const cxxtools::String &data)
| Sets the hostvariable with the given name to a unicode string value. More...
Statement & | setBlob (const std::string &col, const Blob &data)
| Sets the hostvariable with the given name to a blob value. More...
Statement & | setDate (const std::string &col, const Date &data)
| Sets the hostvariable with the given name to a date value. More...
Statement & | setTime (const std::string &col, const Time &data)
| Sets the hostvariable with the given name to a time value. More...
Statement & | setDatetime (const std::string &col, const Datetime &data)
| Sets the hostvariable with the given name to a datetime value. More...
template<typename Iterator >
Statement & | set (const std::string &col, Iterator it1, Iterator it2)
template<typename T >
Statement & | setIf (const std::string &col, bool notNull, const T &data)
| Set the hostvariable with the given name to the passed value or null. More...
size_type | execute ()
| statement-execution-methods More...
Result | select ()
| Executes a query, which returns a resultset, with the current parameters. More...
Row | selectRow ()
| Executes a query, which returns a row, with the current parameters. More...
Value | selectValue ()
| Executes a query, which returns a single value, with the current parameters. More...
const_iterator | begin (unsigned fetchsize=100) const
| This methods creates a cursor and fetches the first row. More...
const_iterator | end () const
| A empty iterator is returned. More...
bool | operator! () const
| Returns true, if this class is not connected to a actual statement. More...
const IStatement * | getImpl () const
| Returns the actual implementation-class. More...
IStatement * | getImpl ()
template<typename T >
Statement & | set (const std::string &col, const T &data)
| Set the hostvariable with the given name to the passed value. More...

## Detailed Description

This class represents a sql-statement.

A statement can have parameters, which are referenced by name, called hostvariables. They are prefixed with a colon followed by a name. A name starts with a letter followed by alphanumeric characters or underscore. Hostvariables are not searched in strings (between apostrophes, quotation marks or backticks). The backslash prevents the interpretation of a special meaning of the following character.

## Member Function Documentation

## begin()

const_iterator tntdb::Statement::begin | ( | unsigned | fetchsize = `100` | ) | const

This methods creates a cursor and fetches the first row.

## clear()

Statement& tntdb::Statement::clear | ( |  | ) |

inline

Sets all hostvariables to NULL.

## end()

Statement::const_iterator tntdb::Statement::end | ( |  | ) | const

inline

A empty iterator is returned.

Every const_iterator, which reaches the end is equal with this.

## execute()

size_type tntdb::Statement::execute | ( |  | ) |

statement-execution-methods

Executes a query with the current parameters. The query should not return results. This method is normally used with INSERT-, UPDATE- or DELETE-statements.

## getImpl()

const IStatement* tntdb::Statement::getImpl | ( |  | ) | const

inline

Returns the actual implementation-class.

## operator!()

bool tntdb::Statement::operator! | ( |  | ) | const

inline

Returns true, if this class is not connected to a actual statement.

## select()

Result tntdb::Statement::select | ( |  | ) |

Executes a query, which returns a resultset, with the current parameters.

The query is normally a SELECT-statement.

## selectRow()

Row tntdb::Statement::selectRow | ( |  | ) |

Executes a query, which returns a row, with the current parameters.

If the query return no rows, a exception of type tntdb::NotFound is thrown. When the query returns more than one row, additional rows are discarded.

## selectValue()

Value tntdb::Statement::selectValue | ( |  | ) |

Executes a query, which returns a single value, with the current parameters.

If the query return no rows, a exception of type tntdb::NotFound is thrown. Only the first value of the first row is returned.

## set()

template<typename T >

Statement & tntdb::Statement::set | ( | const std::string & | col,
|  | const T & | data
| ) |  |

Set the hostvariable with the given name to the passed value.

The method uses the operator<< with a l-value of tntdb::Hostvar& and r-value of a const reference to the actual type to read the value. The operator is defined for standard types and may be defined for user defined types.

## setBlob()

Statement& tntdb::Statement::setBlob | ( | const std::string & | col,
|  | const Blob & | data
| ) |  |

inline

Sets the hostvariable with the given name to a blob value.

## setBool()

Statement& tntdb::Statement::setBool | ( | const std::string & | col,
|  | bool | data
| ) |  |

inline

Sets the hostvariable with the given name to a boolean value.

## setChar()

Statement& tntdb::Statement::setChar | ( | const std::string & | col,
|  | char | data
| ) |  |

inline

Sets the hostvariable with the given name to a char value.

## setDate()

Statement& tntdb::Statement::setDate | ( | const std::string & | col,
|  | const Date & | data
| ) |  |

inline

Sets the hostvariable with the given name to a date value.

## setDatetime()

Statement& tntdb::Statement::setDatetime | ( | const std::string & | col,
|  | const Datetime & | data
| ) |  |

inline

Sets the hostvariable with the given name to a datetime value.

## setDecimal()

Statement& tntdb::Statement::setDecimal | ( | const std::string & | col,
|  | const Decimal & | data
| ) |  |

inline

Sets the hostvariable with the given name to a Decimal.

## setDouble()

Statement& tntdb::Statement::setDouble | ( | const std::string & | col,
|  | double | data
| ) |  |

inline

Sets the hostvariable with the given name to a double value.

## setFloat()

Statement& tntdb::Statement::setFloat | ( | const std::string & | col,
|  | float | data
| ) |  |

inline

Sets the hostvariable with the given name to a float value.

## setIf()

template<typename T >

Statement& tntdb::Statement::setIf | ( | const std::string & | col,
|  | bool | notNull,
|  | const T & | data
| ) |  |

inline

Set the hostvariable with the given name to the passed value or null.

The method sets the hostvariable to the given value if the 2nd argument is true. Otherwise the hostvariable is set to null.

## setInt()

Statement& tntdb::Statement::setInt | ( | const std::string & | col,
|  | int | data
| ) |  |

inline

Sets the hostvariable with the given name to a int value.

## setInt32()

Statement& tntdb::Statement::setInt32 | ( | const std::string & | col,
|  | int32_t | data
| ) |  |

inline

Sets the hostvariable with the given name to a int32_t value.

## setInt64()

Statement& tntdb::Statement::setInt64 | ( | const std::string & | col,
|  | int64_t | data
| ) |  |

inline

Sets the hostvariable with the given name to a int64_t value.

## setLong()

Statement& tntdb::Statement::setLong | ( | const std::string & | col,
|  | long | data
| ) |  |

inline

Sets the hostvariable with the given name to a int value.

## setNull()

Statement& tntdb::Statement::setNull | ( | const std::string & | col | ) |

inline

Sets the hostvariable with the given name to NULL.

## setShort()

Statement& tntdb::Statement::setShort | ( | const std::string & | col,
|  | short | data
| ) |  |

inline

Sets the hostvariable with the given name to a short value.

## setString() [1/2]

Statement& tntdb::Statement::setString | ( | const std::string & | col,
|  | const std::string & | data
| ) |  |

inline

Sets the hostvariable with the given name to a string value.

## setString() [2/2]

Statement& tntdb::Statement::setString | ( | const std::string & | col,
|  | const char * | data
| ) |  |

inline

Sets the hostvariable with the given name to a string value or null, if passing null-pointer.

## setTime()

Statement& tntdb::Statement::setTime | ( | const std::string & | col,
|  | const Time & | data
| ) |  |

inline

Sets the hostvariable with the given name to a time value.

## setUnsigned()

Statement& tntdb::Statement::setUnsigned | ( | const std::string & | col,
|  | unsigned | data
| ) |  |

inline

Sets the hostvariable with the given name to a unsigned value.

## setUnsigned32()

Statement& tntdb::Statement::setUnsigned32 | ( | const std::string & | col,
|  | uint32_t | data
| ) |  |

inline

Sets the hostvariable with the given name to a uint32_t value.

## setUnsigned64()

Statement& tntdb::Statement::setUnsigned64 | ( | const std::string & | col,
|  | uint64_t | data
| ) |  |

inline

Sets the hostvariable with the given name to a uint64_t value.

## setUnsignedLong()

Statement& tntdb::Statement::setUnsignedLong | ( | const std::string & | col,
|  | unsigned long | data
| ) |  |

inline

Sets the hostvariable with the given name to a unsigned long value.

## setUnsignedShort()

Statement& tntdb::Statement::setUnsignedShort | ( | const std::string & | col,
|  | unsigned short | data
| ) |  |

inline

Sets the hostvariable with the given name to a unsigned short value.

## setUString()

Statement& tntdb::Statement::setUString | ( | const std::string & | col,
|  | const cxxtools::String & | data
| ) |  |

inline

Sets the hostvariable with the given name to a unicode string value.

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

- tntdb/bits/statement.h