TreeFrogFramework  1.18
Public Member Functions | Static Public Member Functions | List of all members
TSqlQuery Class Reference

#include <tsqlquery.h>

Inheritance diagram for TSqlQuery:
Inheritance graph
[legend]
Collaboration diagram for TSqlQuery:
Collaboration graph
[legend]

Public Member Functions

 TSqlQuery (int databaseId=0)
 
 TSqlQuery (QSqlDatabase db)
 
TSqlQueryprepare (const QString &query)
 
bool load (const QString &filename)
 
TSqlQuerybind (const QString &placeholder, const QVariant &val)
 
TSqlQuerybind (int pos, const QVariant &val)
 
TSqlQueryaddBind (const QVariant &val)
 
QVariant getNextValue ()
 
QString queryDirPath () const
 
bool exec (const QString &query)
 
bool exec ()
 
int numRowsAffected () const
 
int size () const
 
bool next ()
 
QVariant value (int index) const
 

Static Public Member Functions

static void clearCachedQueries ()
 
static QString escapeIdentifier (const QString &identifier, QSqlDriver::IdentifierType type=QSqlDriver::FieldName, int databaseId=0)
 
static QString escapeIdentifier (const QString &identifier, QSqlDriver::IdentifierType type, const QSqlDriver *driver)
 
static QString formatValue (const QVariant &val, QVariant::Type type=QVariant::Invalid, int databaseId=0)
 
static QString formatValue (const QVariant &val, QVariant::Type type, const QSqlDatabase &database)
 
static QString formatValue (const QVariant &val, const QSqlDatabase &database)
 

Detailed Description

The TSqlQuery class provides a means of executing and manipulating SQL statements.

Constructor & Destructor Documentation

TSqlQuery::TSqlQuery ( int  databaseId = 0)

Constructs a TSqlQuery object using the database databaseId.

TSqlQuery::TSqlQuery ( QSqlDatabase  db)

Member Function Documentation

TSqlQuery & TSqlQuery::addBind ( const QVariant &  val)
inline

Adds the value val to the list of values when using positional value binding and returns the query object.

The order of the addBind() calls determines which placeholder a value will be bound to in the prepared query.

TSqlQuery & TSqlQuery::bind ( const QString &  placeholder,
const QVariant &  val 
)
inline

Set the placeholder placeholder to be bound to value val in the prepared statement.

TSqlQuery & TSqlQuery::bind ( int  pos,
const QVariant &  val 
)
inline

Set the placeholder in position pos to be bound to value val in the prepared statement.

Field numbering starts at 0.

void TSqlQuery::clearCachedQueries ( )
static

Clears currently cached SQL queries that are loaded by the load() function.

QString TSqlQuery::escapeIdentifier ( const QString &  identifier,
QSqlDriver::IdentifierType  type = QSqlDriver::FieldName,
int  databaseId = 0 
)
static

Returns the identifier escaped according to the rules of the database databaseId.

The identifier can either be a table name or field name, dependent on type.

QString TSqlQuery::escapeIdentifier ( const QString &  identifier,
QSqlDriver::IdentifierType  type,
const QSqlDriver *  driver 
)
static

Returns the identifier escaped according to the rules of the driver driver.

The identifier can either be a table name or field name, dependent on type.

bool TSqlQuery::exec ( const QString &  query)

Executes the SQL in query.

Returns true and sets the query state to active if the query was successful; otherwise returns false.

bool TSqlQuery::exec ( )

Executes a previously prepared SQL query.

Returns true if the query executed successfully; otherwise returns false.

QString TSqlQuery::formatValue ( const QVariant &  val,
QVariant::Type  type = QVariant::Invalid,
int  databaseId = 0 
)
static

Returns a string representation of the value val for the database databaseId.

QString TSqlQuery::formatValue ( const QVariant &  val,
QVariant::Type  type,
const QSqlDatabase &  database 
)
static

Returns a string representation of the value val for the database database.

QString TSqlQuery::formatValue ( const QVariant &  val,
const QSqlDatabase &  database 
)
static

Returns a string representation of the value val for the database database.

QVariant TSqlQuery::getNextValue ( )
inline

Returns the value of first field in the next object and advances the internal iterator by one position.

It can be used for a query returning at least one result, such as 'SELECT COUNT(*)'.

bool TSqlQuery::load ( const QString &  filename)

Loads a query from the given file filename.

bool TSqlQuery::next ( )

Retrieves the next record in the result, if available, and positions the query on the retrieved record.

Note that the result must be in the active state and isSelect() must return true before calling this function or it will do nothing and return false.

int TSqlQuery::numRowsAffected ( ) const

Returns the number of rows affected by the result's SQL statement, or -1 if it cannot be determined.

Note that for SELECT statements, the value is undefined; use size() instead. If the query is not active, -1 is returned.

TSqlQuery & TSqlQuery::prepare ( const QString &  query)
inline

Prepares the SQL query query for execution.

QString TSqlQuery::queryDirPath ( ) const

Returns the directory path for SQL query files, which is indicated by the value for application setting SqlQueriesStoredDirectory.

int TSqlQuery::size ( ) const

Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or if the database does not support reporting information about query sizes.

Note that for non-SELECT statements (isSelect() returns false), size() will return -1. If the query is not active (isActive() returns false), -1 is returned. To determine the number of rows affected by a non-SELECT statement, use numRowsAffected().

QVariant TSqlQuery::value ( int  index) const

Returns the value of field index in the current record.


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