tntdb 1.4
|
This class represents an 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 () |
Set all host variables to NULL. | |
Statement & | setNull (const std::string &col) |
Set the host variable with the given name to NULL. | |
Statement & | setBool (const std::string &col, bool data) |
Set the host variable with the given name to a boolean value. | |
Statement & | setShort (const std::string &col, short data) |
Set the host variable with the given name to a short value. | |
Statement & | setInt (const std::string &col, int data) |
Set the host variable with the given name to an int value. | |
Statement & | setLong (const std::string &col, long data) |
Set the host variable with the given name to a long value. | |
Statement & | setUnsignedShort (const std::string &col, unsigned short data) |
Set the host variable with the given name to an unsigned short value. | |
Statement & | setUnsigned (const std::string &col, unsigned data) |
Set the host variable with the given name to an unsigned value. | |
Statement & | setUnsignedLong (const std::string &col, unsigned long data) |
Set the host variable with the given name to an unsigned long value. | |
Statement & | setInt32 (const std::string &col, int32_t data) |
Set the host variable with the given name to a int32_t value. | |
Statement & | setUnsigned32 (const std::string &col, uint32_t data) |
Set the host variable with the given name to a uint32_t value. | |
Statement & | setInt64 (const std::string &col, int64_t data) |
Set the host variable with the given name to a int64_t value. | |
Statement & | setUnsigned64 (const std::string &col, uint64_t data) |
Set the host variable with the given name to a uint64_t value. | |
Statement & | setDecimal (const std::string &col, const Decimal &data) |
Set the host variable with the given name to a Decimal. | |
Statement & | setFloat (const std::string &col, float data) |
Set the host variable with the given name to a float value. | |
Statement & | setDouble (const std::string &col, double data) |
Set the host variable with the given name to a double value. | |
Statement & | setChar (const std::string &col, char data) |
Set the host variable with the given name to a char value. | |
Statement & | setString (const std::string &col, const std::string &data) |
Set the host variable with the given name to a string value. | |
Statement & | setString (const std::string &col, const char *data) |
Set the host variable with the given name to a string value or null. | |
Statement & | setUString (const std::string &col, const cxxtools::String &data) |
Set the host variable with the given name to a unicode string value. | |
Statement & | setBlob (const std::string &col, const Blob &data) |
Set the host variable with the given name to a blob value. | |
Statement & | setDate (const std::string &col, const Date &data) |
Set the host variable with the given name to a date value. | |
Statement & | setTime (const std::string &col, const Time &data) |
Set the host variable with the given name to a time value. | |
Statement & | setDatetime (const std::string &col, const Datetime &data) |
Set the host variable with the given name to a datetime value. | |
template<typename T > | |
Statement & | set (const std::string &col, const T &data) |
Set the host variable with the given name to the passed value. | |
template<typename Iterator > | |
Statement & | set (const std::string &col, Iterator it1, Iterator it2) |
Set multiple numbered parameters to the values specified by the iterator range. | |
template<typename Object > | |
Statement & | set (const Object &obj) |
template<typename T > | |
Statement & | setIf (const std::string &col, bool notNull, const T &data) |
Set the host variable with the given name to the passed value or null. | |
const_iterator | begin (unsigned fetchsize=100) const |
Create a database cursor and fetch the first row of the query result. | |
const_iterator | end () const |
Get an end iterator. | |
bool | operator! () const |
Check whether this object is associated with a real statement (true if not) | |
void | maxNumDelay (size_type n) |
Sets a buffer for delayed execution of statements. | |
size_type | numDelayed () const |
Returns the number of the currently pending statements. | |
size_type | flush () |
Executes all currently pending statements. | |
size_type | execute () |
Statement execution methods. | |
template<typename Object > | |
size_type | execute (const Object &obj) |
Statement execution methods. | |
Result | select () |
Execute the query and return the result. | |
Row | selectRow () |
Execute the query and return the first row of the result. | |
Value | selectValue () |
Execute the query and return the first value from the first row of the result. | |
const IStatement * | getImpl () const |
IStatement * | getImpl () |
This class represents an SQL statement.
A statement can have parameters, which are referenced by name, called host variables. They are prefixed with a colon followed by a name. A name starts with a letter followed by alphanumeric characters or underscores. Host variables are not searched in strings (between apostrophes, quotation marks or backticks). A backslash prevents the interpretation of a special meaning of the following character.
const_iterator tntdb::Statement::begin | ( | unsigned | fetchsize = 100 | ) | const |
Create a database cursor and fetch the first row of the query result.
|
inline |
Set all host variables to NULL.
|
inline |
Get an end iterator.
This iterator works like the iterator got from the end() method of STL containers like std::vector and std::list. It doesn't reference the last element in a list but an imaginary element after the last one, and should be used as follows:
size_type tntdb::Statement::execute | ( | ) |
Statement execution methods.
Execute the query without returning the result
The query should not return results. This method is normally used with INSERT, UPDATE or DELETE statements.
Statement execution methods.
Execute the query without returning the result
The query should not return results. This method is normally used with INSERT, UPDATE or DELETE statements.
size_type tntdb::Statement::flush | ( | ) |
Executes all currently pending statements.
Returns number of affected rows.
|
inline |
Get the actual implementation object
|
inline |
Get the actual implementation object
void tntdb::Statement::maxNumDelay | ( | size_type | n | ) |
Sets a buffer for delayed execution of statements.
When the number if greater than 0 and the connection is in a transaction, the execute method may delay the actual execution until the buffer is full or flush is called.
The default is 0.
size_type tntdb::Statement::numDelayed | ( | ) | const |
Returns the number of the currently pending statements.
|
inline |
Check whether this object is associated with a real statement (true if not)
Result tntdb::Statement::select | ( | ) |
Execute the query and return the result.
The query normally is a SELECT statement.
Row tntdb::Statement::selectRow | ( | ) |
Execute the query and return the first row of the result.
If the result is empty, a NotFound exception is thrown. Additional rows are ignored.
Value tntdb::Statement::selectValue | ( | ) |
Execute the query and return the first value from the first row of the result.
If the result is empty, a NotFound exception is thrown. Additional values are ignored.
Statement & tntdb::Statement::set | ( | const std::string & | col, |
const T & | data | ||
) |
Set the host variable with the given name to the passed value.
The method uses the operator<< with a l-value of the type 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.
Statement & tntdb::Statement::set | ( | const std::string & | col, |
Iterator | it1, | ||
Iterator | it2 | ||
) |
Set multiple numbered parameters to the values specified by the iterator range.
The method expects, that the statement has columns with the specified column name appended by a number range starting from 0. This list can be generated for example with tntdb::SqlBuilder.
Example:
Set the host variable with the given name to a blob value.
Set the host variable with the given name to a boolean value.
Set the host variable with the given name to a char value.
Set the host variable with the given name to a date value.
Set the host variable with the given name to a datetime value.
Set the host variable with the given name to a Decimal.
Set the host variable with the given name to a double value.
Set the host variable with the given name to a float value.
|
inline |
Set the host variable with the given name to the passed value or null.
The method sets the host variable to the given value if the 2nd argument is true. Otherwise the host variable is set to null.
Set the host variable with the given name to an int value.
Set the host variable with the given name to a int32_t value.
Set the host variable with the given name to a int64_t value.
Set the host variable with the given name to a long value.
Set the host variable with the given name to NULL.
Set the host variable with the given name to a short value.
Set the host variable with the given name to a string value or null.
|
inline |
Set the host variable with the given name to a string value.
Set the host variable with the given name to a time value.
Set the host variable with the given name to an unsigned value.
Set the host variable with the given name to a uint32_t value.
Set the host variable with the given name to a uint64_t value.
|
inline |
Set the host variable with the given name to an unsigned long value.
|
inline |
Set the host variable with the given name to an unsigned short value.
|
inline |
Set the host variable with the given name to a unicode string value.