TreeFrogFramework 2.10
Loading...
Searching...
No Matches
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 (const QSqlDatabase &db)
 
TSqlQueryprepare (const QString &query)
 
bool load (const QString &filename)
 
bool loadPreparedQuery (const QString &filename)
 
TSqlQuerybind (const QString &placeholder, const QVariant &val)
 
TSqlQuerybind (int pos, const QVariant &val)
 
TSqlQueryaddBind (const QVariant &val)
 
QVariant boundValue (int pos) const
 
QVariantList boundValues () const
 
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
 
QVariant value (const QString &name) 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, const QMetaType &type, int databaseId=0)
 
static QString formatValue (const QVariant &val, const QMetaType &type, const QSqlDatabase &database)
 
static QString formatValue (const QVariant &val, const QMetaType &type, const QSqlDriver *driver)
 
static QString formatValue (const QVariant &val, const QSqlDriver *driver)
 
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() [1/2]

TSqlQuery::TSqlQuery ( int  databaseId = 0)

Constructs a TSqlQuery object using the database databaseId.

◆ TSqlQuery() [2/2]

TSqlQuery::TSqlQuery ( const QSqlDatabase &  db)

Member Function Documentation

◆ addBind()

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

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.

◆ bind() [1/2]

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

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

◆ bind() [2/2]

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

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

Field numbering starts at 0.

◆ boundValue()

QVariant TSqlQuery::boundValue ( int  pos) const

◆ boundValues()

QVariantList TSqlQuery::boundValues ( ) const

◆ clearCachedQueries()

void TSqlQuery::clearCachedQueries ( )
static

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

◆ escapeIdentifier() [1/2]

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.

◆ escapeIdentifier() [2/2]

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.

◆ exec() [1/2]

bool TSqlQuery::exec ( )

Executes a previously prepared SQL query.

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

◆ exec() [2/2]

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.

◆ formatValue() [1/5]

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

◆ formatValue() [2/5]

QString TSqlQuery::formatValue ( const QVariant &  val,
const QMetaType &  type,
const QSqlDriver *  driver 
)
static

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

◆ formatValue() [3/5]

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

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

◆ formatValue() [4/5]

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

◆ formatValue() [5/5]

QString TSqlQuery::formatValue ( const QVariant &  val,
const QSqlDriver *  driver 
)
static

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

◆ getNextValue()

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(*)'.

◆ load()

bool TSqlQuery::load ( const QString &  filename)

Loads a query from the given file filename.

◆ loadPreparedQuery()

bool TSqlQuery::loadPreparedQuery ( const QString &  filename)
inline

◆ next()

bool TSqlQuery::next ( )
inline

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.

◆ numRowsAffected()

int TSqlQuery::numRowsAffected ( ) const
inline

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.

◆ prepare()

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

Prepares the SQL query query for execution.

◆ queryDirPath()

QString TSqlQuery::queryDirPath ( ) const

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

◆ size()

int TSqlQuery::size ( ) const
inline

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().

◆ value() [1/2]

QVariant TSqlQuery::value ( const QString &  name) const
inline

Returns the value of the field called name in the current record.

If field name does not exist an invalid variant is returned.

◆ value() [2/2]

QVariant TSqlQuery::value ( int  index) const
inline

Returns the value of field index in the current record.


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