tntdb 1.4
tntdb::Statement Class Reference

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)
 
Statementclear ()
 Set all host variables to NULL.
 
StatementsetNull (const std::string &col)
 Set the host variable with the given name to NULL.
 
StatementsetBool (const std::string &col, bool data)
 Set the host variable with the given name to a boolean value.
 
StatementsetShort (const std::string &col, short data)
 Set the host variable with the given name to a short value.
 
StatementsetInt (const std::string &col, int data)
 Set the host variable with the given name to an int value.
 
StatementsetLong (const std::string &col, long data)
 Set the host variable with the given name to a long value.
 
StatementsetUnsignedShort (const std::string &col, unsigned short data)
 Set the host variable with the given name to an unsigned short value.
 
StatementsetUnsigned (const std::string &col, unsigned data)
 Set the host variable with the given name to an unsigned value.
 
StatementsetUnsignedLong (const std::string &col, unsigned long data)
 Set the host variable with the given name to an unsigned long value.
 
StatementsetInt32 (const std::string &col, int32_t data)
 Set the host variable with the given name to a int32_t value.
 
StatementsetUnsigned32 (const std::string &col, uint32_t data)
 Set the host variable with the given name to a uint32_t value.
 
StatementsetInt64 (const std::string &col, int64_t data)
 Set the host variable with the given name to a int64_t value.
 
StatementsetUnsigned64 (const std::string &col, uint64_t data)
 Set the host variable with the given name to a uint64_t value.
 
StatementsetDecimal (const std::string &col, const Decimal &data)
 Set the host variable with the given name to a Decimal.
 
StatementsetFloat (const std::string &col, float data)
 Set the host variable with the given name to a float value.
 
StatementsetDouble (const std::string &col, double data)
 Set the host variable with the given name to a double value.
 
StatementsetChar (const std::string &col, char data)
 Set the host variable with the given name to a char value.
 
StatementsetString (const std::string &col, const std::string &data)
 Set the host variable with the given name to a string value.
 
StatementsetString (const std::string &col, const char *data)
 Set the host variable with the given name to a string value or null.
 
StatementsetUString (const std::string &col, const cxxtools::String &data)
 Set the host variable with the given name to a unicode string value.
 
StatementsetBlob (const std::string &col, const Blob &data)
 Set the host variable with the given name to a blob value.
 
StatementsetDate (const std::string &col, const Date &data)
 Set the host variable with the given name to a date value.
 
StatementsetTime (const std::string &col, const Time &data)
 Set the host variable with the given name to a time value.
 
StatementsetDatetime (const std::string &col, const Datetime &data)
 Set the host variable with the given name to a datetime value.
 
template<typename T >
Statementset (const std::string &col, const T &data)
 Set the host variable with the given name to the passed value.
 
template<typename Iterator >
Statementset (const std::string &col, Iterator it1, Iterator it2)
 Set multiple numbered parameters to the values specified by the iterator range.
 
template<typename Object >
Statementset (const Object &obj)
 
template<typename T >
StatementsetIf (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 ()
 

Detailed Description

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.

Member Function Documentation

◆ begin()

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

Create a database cursor and fetch the first row of the query result.

◆ clear()

Statement & tntdb::Statement::clear ( )
inline

Set all host variables to NULL.

◆ end()

Statement::const_iterator tntdb::Statement::end ( ) const
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:

for(tntdb::Statement::const_iterator it = stmtObj.begin(); it != stmtObj.end(); ++it)
{
// Loop body accessing individual result rows through *it
}
This class represents a database-cursor.
Definition statement_iterator.h:46

◆ execute() [1/2]

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.

◆ execute() [2/2]

template<typename Object >
size_type tntdb::Statement::execute ( const Object & obj)
inline

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.

◆ flush()

size_type tntdb::Statement::flush ( )

Executes all currently pending statements.

Returns number of affected rows.

◆ getImpl() [1/2]

IStatement * tntdb::Statement::getImpl ( )
inline

Get the actual implementation object

◆ getImpl() [2/2]

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

Get the actual implementation object

◆ maxNumDelay()

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.

◆ numDelayed()

size_type tntdb::Statement::numDelayed ( ) const

Returns the number of the currently pending statements.

◆ operator!()

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

Check whether this object is associated with a real statement (true if not)

◆ select()

Result tntdb::Statement::select ( )

Execute the query and return the result.

The query normally is a SELECT statement.

◆ selectRow()

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.

◆ selectValue()

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.

◆ set() [1/2]

template<typename T >
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.

◆ set() [2/2]

template<typename Iterator >
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:

std::vector<int> values;
values.push_back(5);
values.push_back(12);
tntdb::Statement stmt = conn.prepare("select a, b, c from tab1 where v in (" + tntdb::Statement::paramlist("v", values.size()) + ")");
stmt.set("v", values.begin(), values.end());
// or short version:
stmt.set("v", values);
// now stmt is ready for iteration
This class represents an SQL statement.
Definition statement.h:73
Statement & set(const std::string &col, const T &data)
Set the host variable with the given name to the passed value.
Definition statement.h:492

◆ setBlob()

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

Set the host variable with the given name to a blob value.

◆ setBool()

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

Set the host variable with the given name to a boolean value.

◆ setChar()

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

Set the host variable with the given name to a char value.

◆ setDate()

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

Set the host variable with the given name to a date value.

◆ setDatetime()

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

Set the host variable with the given name to a datetime value.

◆ setDecimal()

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

Set the host variable with the given name to a Decimal.

◆ setDouble()

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

Set the host variable with the given name to a double value.

◆ setFloat()

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

Set the host variable 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 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.

◆ setInt()

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

Set the host variable with the given name to an int value.

◆ setInt32()

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

Set the host variable with the given name to a int32_t value.

◆ setInt64()

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

Set the host variable with the given name to a int64_t value.

◆ setLong()

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

Set the host variable with the given name to a long value.

◆ setNull()

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

Set the host variable with the given name to NULL.

◆ setShort()

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

Set the host variable with the given name to a short value.

◆ setString() [1/2]

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

Set the host variable with the given name to a string value or null.

◆ setString() [2/2]

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

Set the host variable with the given name to a string value.

◆ setTime()

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

Set the host variable with the given name to a time value.

◆ setUnsigned()

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

Set the host variable with the given name to an unsigned value.

◆ setUnsigned32()

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

Set the host variable with the given name to a uint32_t value.

◆ setUnsigned64()

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

Set the host variable with the given name to a uint64_t value.

◆ setUnsignedLong()

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

Set the host variable with the given name to an unsigned long value.

◆ setUnsignedShort()

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

Set the host variable with the given name to an unsigned short value.

◆ setUString()

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

Set the host variable with the given name to a unicode string value.


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