tntdb::Statement Class Reference

This class represents an SQL statement. More...

#include <tntdb/bits/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 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)
size_type execute ()
 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 IStatementgetImpl () const
IStatementgetImpl ()

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 Typedef Documentation

Constructor & Destructor Documentation

tntdb::Statement::Statement ( IStatement stmt = 0)
inline

Member Function Documentation

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

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

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

Set all host variables to NULL.

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
}
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.

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

Get the actual implementation object

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

Get the actual implementation object

bool tntdb::Statement::operator! ( ) const
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.

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.

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
Statement& tntdb::Statement::setBlob ( const std::string &  col,
const Blob data 
)
inline

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

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

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

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.

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.

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

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

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

Set the host variable with the given name to NULL.

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

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

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.

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.

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

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

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

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

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.

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.

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.

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.

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: