Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QMYSQLResult Class Reference
Inheritance diagram for QMYSQLResult:
Collaboration diagram for QMYSQLResult:

Public Member Functions

 QMYSQLResult (const QMYSQLDriver *db)
 ~QMYSQLResult ()
QVariant handle () const override
 Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVariant if there is no handle.
 QMYSQLResult (const QMYSQLDriver *db)
 ~QMYSQLResult ()
QVariant handle () const override
 Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVariant if there is no handle.
Public Member Functions inherited from QSqlResult
virtual ~QSqlResult ()
 Destroys the object and frees any allocated resources.

Protected Member Functions

void cleanup ()
bool fetch (int i) override
 Positions the result to an arbitrary (zero-based) row index.
bool fetchNext () override
 Positions the result to the next available record (row) in the result.
bool fetchLast () override
 Positions the result to the last record (last row) in the result.
bool fetchFirst () override
 Positions the result to the first record (row 0) in the result.
QVariant data (int field) override
 Returns the data for field index in the current row as a QVariant.
bool isNull (int field) override
 Returns true if the field at position index in the current row is null; otherwise returns false.
bool reset (const QString &query) override
 Sets the result to use the SQL statement query for subsequent data retrieval.
int size () override
 Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELECT statement.
int numRowsAffected () override
 Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or if the query is a SELECT statement.
QVariant lastInsertId () const override
 Returns the object ID of the most recent inserted row if the database supports it.
QSqlRecord record () const override
 Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
void virtual_hook (int id, void *data) override
bool nextResult () override
void detachFromResultSet () override
bool prepare (const QString &stmt) override
 Prepares the given query for execution; the query will normally use placeholders so that it can be executed repeatedly.
bool exec () override
 Executes the query, returning true if successful; otherwise returns false.
void cleanup ()
bool fetch (int i) override
 Positions the result to an arbitrary (zero-based) row index.
bool fetchNext () override
 Positions the result to the next available record (row) in the result.
bool fetchLast () override
 Positions the result to the last record (last row) in the result.
bool fetchFirst () override
 Positions the result to the first record (row 0) in the result.
QVariant data (int field) override
 Returns the data for field index in the current row as a QVariant.
bool isNull (int field) override
 Returns true if the field at position index in the current row is null; otherwise returns false.
bool reset (const QString &query) override
 Sets the result to use the SQL statement query for subsequent data retrieval.
int size () override
 Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELECT statement.
int numRowsAffected () override
 Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or if the query is a SELECT statement.
QVariant lastInsertId () const override
 Returns the object ID of the most recent inserted row if the database supports it.
QSqlRecord record () const override
 Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
void virtual_hook (int id, void *data) override
bool nextResult () override
void detachFromResultSet () override
bool prepare (const QString &stmt) override
 Prepares the given query for execution; the query will normally use placeholders so that it can be executed repeatedly.
bool exec () override
 Executes the query, returning true if successful; otherwise returns false.
Protected Member Functions inherited from QSqlResult
 QSqlResult (const QSqlDriver *db)
 Creates a QSqlResult using database driver db.
 QSqlResult (QSqlResultPrivate &dd)
int at () const
 Returns the current (zero-based) row position of the result.
QString lastQuery () const
 Returns the current SQL query text, or an empty string if there isn't one.
QSqlError lastError () const
 Returns the last error associated with the result.
bool isValid () const
 Returns true if the result is positioned on a valid record (that is, the result is not positioned before the first or after the last record); otherwise returns false.
bool isActive () const
 Returns true if the result has records to be retrieved; otherwise returns false.
bool isSelect () const
 Returns true if the current result is from a SELECT statement; otherwise returns false.
bool isForwardOnly () const
 Returns true if you can only scroll forward through the result set; otherwise returns false.
const QSqlDriverdriver () const
 Returns the driver associated with the result.
virtual void setAt (int at)
 This function is provided for derived classes to set the internal (zero-based) row position to index.
virtual void setActive (bool a)
 This function is provided for derived classes to set the internal active state to active.
virtual void setLastError (const QSqlError &e)
 This function is provided for derived classes to set the last error to error.
virtual void setQuery (const QString &query)
 Sets the current query for the result to query.
virtual void setSelect (bool s)
 This function is provided for derived classes to indicate whether or not the current statement is a SQL SELECT statement.
virtual void setForwardOnly (bool forward)
 Sets forward only mode to forward.
virtual bool savePrepare (const QString &sqlquery)
 Prepares the given query, using the underlying database functionality where possible.
virtual void bindValue (int pos, const QVariant &val, QSql::ParamType type)
 Binds the value val of parameter type paramType to position index in the current record (row).
virtual void bindValue (const QString &placeholder, const QVariant &val, QSql::ParamType type)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Binds the value val of parameter type paramType to the placeholder name in the current record (row).
void addBindValue (const QVariant &val, QSql::ParamType type)
 Binds the value val of parameter type paramType to the next available position in the current record (row).
QVariant boundValue (const QString &placeholder) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the value bound by the given placeholder name in the current record (row).
QVariant boundValue (int pos) const
 Returns the value bound at position index in the current record (row).
QSql::ParamType bindValueType (const QString &placeholder) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the parameter type for the value bound with the given placeholder name.
QSql::ParamType bindValueType (int pos) const
 Returns the parameter type for the value bound at position index.
int boundValueCount () const
 Returns the number of bound values in the result.
QVariantListboundValues (QT6_DECL_NEW_OVERLOAD)
QVariantList boundValues (QT6_DECL_NEW_OVERLOAD) const
QString executedQuery () const
 Returns the query that was actually executed.
QStringList boundValueNames () const
 Returns the names of all bound values.
QString boundValueName (int pos) const
 Returns the name of the bound value at position index in the current record (row).
void clear ()
 Clears the entire result set and releases any associated resources.
bool hasOutValues () const
 Returns true if at least one of the query's bound values is a QSql::Out or a QSql::InOut; otherwise returns false.
BindingSyntax bindingSyntax () const
 Returns the binding syntax used by prepared queries.
virtual bool fetchPrevious ()
 Positions the result to the previous record (row) in the result.
virtual bool execBatch (bool arrayBind=false)
virtual void setNumericalPrecisionPolicy (QSql::NumericalPrecisionPolicy policy)
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy () const
void setPositionalBindingEnabled (bool enable)
bool isPositionalBindingEnabled () const
void resetBindCount ()
 Resets the number of bind parameters.

Friends

class QMYSQLDriver

Additional Inherited Members

Protected Types inherited from QSqlResult
enum  BindingSyntax { PositionalBinding , NamedBinding }
 This enum type specifies the different syntaxes for specifying placeholders in prepared queries. More...
enum  VirtualHookOperation
Protected Attributes inherited from QSqlResult
QSqlResultPrivated_ptr

Detailed Description

Definition at line 146 of file qsql_mysql.cpp.

Constructor & Destructor Documentation

◆ QMYSQLResult() [1/2]

QMYSQLResult::QMYSQLResult ( const QMYSQLDriver * db)
explicit

Definition at line 397 of file qsql_mysql.cpp.

References QMYSQLResult().

Referenced by QMYSQLResult().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~QMYSQLResult() [1/2]

QMYSQLResult::~QMYSQLResult ( )

Definition at line 402 of file qsql_mysql.cpp.

References cleanup().

Here is the call graph for this function:

◆ QMYSQLResult() [2/2]

QMYSQLResult::QMYSQLResult ( const QMYSQLDriver * db)
explicit

◆ ~QMYSQLResult() [2/2]

QMYSQLResult::~QMYSQLResult ( )

Member Function Documentation

◆ cleanup() [1/2]

void QMYSQLResult::cleanup ( )
protected

Definition at line 416 of file qsql_mysql.cpp.

Referenced by ~QMYSQLResult(), prepare(), and reset().

Here is the caller graph for this function:

◆ cleanup() [2/2]

void QMYSQLResult::cleanup ( )
protected

◆ data() [1/2]

QVariant QMYSQLResult::data ( int index)
overrideprotectedvirtual

Returns the data for field index in the current row as a QVariant.

This function is only called if the result is in an active state and is positioned on a valid record and index is non-negative. Derived classes must reimplement this function and return the value of field index, or QVariant() if it cannot be determined.

Implements QSqlResult.

Definition at line 564 of file qsql_mysql.cpp.

References QMYSQLResultPrivate::QMyField::bufLength, QT_MYSQL_TIME::day, QT_MYSQL_TIME::hour, QT_MYSQL_TIME::minute, QT_MYSQL_TIME::month, QMYSQLResultPrivate::QMyField::outField, QT_MYSQL_TIME::second, QT_MYSQL_TIME::second_part, and QT_MYSQL_TIME::year.

◆ data() [2/2]

QVariant QMYSQLResult::data ( int index)
overrideprotectedvirtual

Returns the data for field index in the current row as a QVariant.

This function is only called if the result is in an active state and is positioned on a valid record and index is non-negative. Derived classes must reimplement this function and return the value of field index, or QVariant() if it cannot be determined.

Implements QSqlResult.

◆ detachFromResultSet() [1/2]

void QMYSQLResult::detachFromResultSet ( )
overrideprotectedvirtual

Reimplemented from QSqlResult.

Definition at line 752 of file qsql_mysql.cpp.

◆ detachFromResultSet() [2/2]

void QMYSQLResult::detachFromResultSet ( )
overrideprotectedvirtual

Reimplemented from QSqlResult.

◆ exec() [1/2]

bool QMYSQLResult::exec ( )
overrideprotectedvirtual

Executes the query, returning true if successful; otherwise returns false.

See also
prepare()

Reimplemented from QSqlResult.

Definition at line 898 of file qsql_mysql.cpp.

◆ exec() [2/2]

bool QMYSQLResult::exec ( )
overrideprotectedvirtual

Executes the query, returning true if successful; otherwise returns false.

See also
prepare()

Reimplemented from QSqlResult.

◆ fetch() [1/2]

bool QMYSQLResult::fetch ( int index)
overrideprotectedvirtual

Positions the result to an arbitrary (zero-based) row index.

This function is only called if the result is in an active state. Derived classes must reimplement this function and position the result to the row index, and call setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

See also
isActive(), fetchFirst(), fetchLast(), fetchNext(), fetchPrevious()

Implements QSqlResult.

Definition at line 462 of file qsql_mysql.cpp.

References fetchNext().

Referenced by fetchFirst(), and fetchLast().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch() [2/2]

bool QMYSQLResult::fetch ( int index)
overrideprotectedvirtual

Positions the result to an arbitrary (zero-based) row index.

This function is only called if the result is in an active state. Derived classes must reimplement this function and position the result to the row index, and call setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

See also
isActive(), fetchFirst(), fetchLast(), fetchNext(), fetchPrevious()

Implements QSqlResult.

◆ fetchFirst() [1/2]

bool QMYSQLResult::fetchFirst ( )
overrideprotectedvirtual

Positions the result to the first record (row 0) in the result.

This function is only called if the result is in an active state. Derived classes must reimplement this function and position the result to the first record, and call setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

See also
fetch(), fetchLast()

Implements QSqlResult.

Definition at line 540 of file qsql_mysql.cpp.

References fetch().

Here is the call graph for this function:

◆ fetchFirst() [2/2]

bool QMYSQLResult::fetchFirst ( )
overrideprotectedvirtual

Positions the result to the first record (row 0) in the result.

This function is only called if the result is in an active state. Derived classes must reimplement this function and position the result to the first record, and call setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

See also
fetch(), fetchLast()

Implements QSqlResult.

◆ fetchLast() [1/2]

bool QMYSQLResult::fetchLast ( )
overrideprotectedvirtual

Positions the result to the last record (last row) in the result.

This function is only called if the result is in an active state. Derived classes must reimplement this function and position the result to the last record, and call setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

See also
fetch(), fetchFirst()

Implements QSqlResult.

Definition at line 521 of file qsql_mysql.cpp.

References fetch(), and fetchNext().

Here is the call graph for this function:

◆ fetchLast() [2/2]

bool QMYSQLResult::fetchLast ( )
overrideprotectedvirtual

Positions the result to the last record (last row) in the result.

This function is only called if the result is in an active state. Derived classes must reimplement this function and position the result to the last record, and call setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

See also
fetch(), fetchFirst()

Implements QSqlResult.

◆ fetchNext() [1/2]

bool QMYSQLResult::fetchNext ( )
overrideprotectedvirtual

Positions the result to the next available record (row) in the result.

This function is only called if the result is in an active state. The default implementation calls fetch() with the next index. Derived classes can reimplement this function and position the result to the next record in some other way, and call setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

See also
fetch(), fetchPrevious()

Reimplemented from QSqlResult.

Definition at line 499 of file qsql_mysql.cpp.

Referenced by fetch(), and fetchLast().

Here is the caller graph for this function:

◆ fetchNext() [2/2]

bool QMYSQLResult::fetchNext ( )
overrideprotectedvirtual

Positions the result to the next available record (row) in the result.

This function is only called if the result is in an active state. The default implementation calls fetch() with the next index. Derived classes can reimplement this function and position the result to the next record in some other way, and call setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

See also
fetch(), fetchPrevious()

Reimplemented from QSqlResult.

◆ handle() [1/2]

QVariant QMYSQLResult::handle ( ) const
overridevirtual

Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVariant if there is no handle.

Warning
Use this with uttermost care and only if you know what you're doing.
The handle returned here can become a stale pointer if the result is modified (for example, if you clear it).
The handle can be NULL if the result was not executed yet.
PostgreSQL: in forward-only mode, the handle of QSqlResult can change after calling fetch(), fetchFirst(), fetchLast(), fetchNext(), fetchPrevious(), nextResult().

The handle returned here is database-dependent, you should query the type name of the variant before accessing it.

This example retrieves the handle for a sqlite result:

QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db);
QVariant v = query.result()->handle();
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3_stmt*") == 0) {
// v.data() returns a pointer to the handle
sqlite3_stmt *handle = *static_cast<sqlite3_stmt **>(v.data());
if (handle) {
// ...
}
}

This snippet returns the handle for PostgreSQL or MySQL:

if (qstrcmp(v.typeName(), "PGresult*") == 0) {
PGresult *handle = *static_cast<PGresult **>(v.data());
if (handle) {
// ...
}
}
if (qstrcmp(v.typeName(), "MYSQL_STMT*") == 0) {
MYSQL_STMT *handle = *static_cast<MYSQL_STMT **>(v.data());
if (handle) {
// ...
}
}
See also
QSqlDriver::handle()

Reimplemented from QSqlResult.

Definition at line 407 of file qsql_mysql.cpp.

◆ handle() [2/2]

QVariant QMYSQLResult::handle ( ) const
overridevirtual

Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVariant if there is no handle.

Warning
Use this with uttermost care and only if you know what you're doing.
The handle returned here can become a stale pointer if the result is modified (for example, if you clear it).
The handle can be NULL if the result was not executed yet.
PostgreSQL: in forward-only mode, the handle of QSqlResult can change after calling fetch(), fetchFirst(), fetchLast(), fetchNext(), fetchPrevious(), nextResult().

The handle returned here is database-dependent, you should query the type name of the variant before accessing it.

This example retrieves the handle for a sqlite result:

QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db);
QVariant v = query.result()->handle();
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3_stmt*") == 0) {
// v.data() returns a pointer to the handle
sqlite3_stmt *handle = *static_cast<sqlite3_stmt **>(v.data());
if (handle) {
// ...
}
}

This snippet returns the handle for PostgreSQL or MySQL:

if (qstrcmp(v.typeName(), "PGresult*") == 0) {
PGresult *handle = *static_cast<PGresult **>(v.data());
if (handle) {
// ...
}
}
if (qstrcmp(v.typeName(), "MYSQL_STMT*") == 0) {
MYSQL_STMT *handle = *static_cast<MYSQL_STMT **>(v.data());
if (handle) {
// ...
}
}
See also
QSqlDriver::handle()

Reimplemented from QSqlResult.

◆ isNull() [1/2]

bool QMYSQLResult::isNull ( int i)
overrideprotectedvirtual

Returns true if the field at position index in the current row is null; otherwise returns false.

Implements QSqlResult.

Definition at line 684 of file qsql_mysql.cpp.

◆ isNull() [2/2]

bool QMYSQLResult::isNull ( int i)
overrideprotectedvirtual

Returns true if the field at position index in the current row is null; otherwise returns false.

Implements QSqlResult.

◆ lastInsertId() [1/2]

QVariant QMYSQLResult::lastInsertId ( ) const
overrideprotectedvirtual

Returns the object ID of the most recent inserted row if the database supports it.

An invalid QVariant will be returned if the query did not insert any value or if the database does not report the id back. If more than one row was touched by the insert, the behavior is undefined.

Note that for Oracle databases the row's ROWID will be returned, while for MySQL databases the row's auto-increment field will be returned.

See also
QSqlDriver::hasFeature()

Reimplemented from QSqlResult.

Definition at line 761 of file qsql_mysql.cpp.

◆ lastInsertId() [2/2]

QVariant QMYSQLResult::lastInsertId ( ) const
overrideprotectedvirtual

Returns the object ID of the most recent inserted row if the database supports it.

An invalid QVariant will be returned if the query did not insert any value or if the database does not report the id back. If more than one row was touched by the insert, the behavior is undefined.

Note that for Oracle databases the row's ROWID will be returned, while for MySQL databases the row's auto-increment field will be returned.

See also
QSqlDriver::hasFeature()

Reimplemented from QSqlResult.

◆ nextResult() [1/2]

bool QMYSQLResult::nextResult ( )
overrideprotectedvirtual

Reimplemented from QSqlResult.

Definition at line 801 of file qsql_mysql.cpp.

◆ nextResult() [2/2]

bool QMYSQLResult::nextResult ( )
overrideprotectedvirtual

Reimplemented from QSqlResult.

◆ numRowsAffected() [1/2]

int QMYSQLResult::numRowsAffected ( )
overrideprotectedvirtual

Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or if the query is a SELECT statement.

See also
size()

Implements QSqlResult.

Definition at line 746 of file qsql_mysql.cpp.

◆ numRowsAffected() [2/2]

int QMYSQLResult::numRowsAffected ( )
overrideprotectedvirtual

Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or if the query is a SELECT statement.

See also
size()

Implements QSqlResult.

◆ prepare() [1/2]

bool QMYSQLResult::prepare ( const QString & query)
overrideprotectedvirtual

Prepares the given query for execution; the query will normally use placeholders so that it can be executed repeatedly.

Returns true if the query is prepared successfully; otherwise returns false.

See also
exec()

Reimplemented from QSqlResult.

Definition at line 857 of file qsql_mysql.cpp.

References cleanup().

Here is the call graph for this function:

◆ prepare() [2/2]

bool QMYSQLResult::prepare ( const QString & query)
overrideprotectedvirtual

Prepares the given query for execution; the query will normally use placeholders so that it can be executed repeatedly.

Returns true if the query is prepared successfully; otherwise returns false.

See also
exec()

Reimplemented from QSqlResult.

◆ record() [1/2]

QSqlRecord QMYSQLResult::record ( ) const
overrideprotectedvirtual

Returns the current record if the query is active; otherwise returns an empty QSqlRecord.

The default implementation always returns an empty QSqlRecord.

See also
isActive()

Reimplemented from QSqlResult.

Definition at line 779 of file qsql_mysql.cpp.

◆ record() [2/2]

QSqlRecord QMYSQLResult::record ( ) const
overrideprotectedvirtual

Returns the current record if the query is active; otherwise returns an empty QSqlRecord.

The default implementation always returns an empty QSqlRecord.

See also
isActive()

Reimplemented from QSqlResult.

◆ reset() [1/2]

bool QMYSQLResult::reset ( const QString & query)
overrideprotectedvirtual

Sets the result to use the SQL statement query for subsequent data retrieval.

Derived classes must reimplement this function and apply the query to the database. This function is only called after the result is set to an inactive state and is positioned before the first record of the new result. Derived classes should return true if the query was successful and ready to be used, or false otherwise.

See also
setQuery()

Implements QSqlResult.

Definition at line 695 of file qsql_mysql.cpp.

References cleanup().

Here is the call graph for this function:

◆ reset() [2/2]

bool QMYSQLResult::reset ( const QString & query)
overrideprotectedvirtual

Sets the result to use the SQL statement query for subsequent data retrieval.

Derived classes must reimplement this function and apply the query to the database. This function is only called after the result is set to an inactive state and is positioned before the first record of the new result. Derived classes should return true if the query was successful and ready to be used, or false otherwise.

See also
setQuery()

Implements QSqlResult.

◆ size() [1/2]

int QMYSQLResult::size ( )
overrideprotectedvirtual

Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELECT statement.

See also
numRowsAffected()

Implements QSqlResult.

Definition at line 734 of file qsql_mysql.cpp.

◆ size() [2/2]

int QMYSQLResult::size ( )
overrideprotectedvirtual

Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELECT statement.

See also
numRowsAffected()

Implements QSqlResult.

◆ virtual_hook() [1/2]

void QMYSQLResult::virtual_hook ( int id,
void * data )
overrideprotectedvirtual

Reimplemented from QSqlResult.

Definition at line 852 of file qsql_mysql.cpp.

◆ virtual_hook() [2/2]

void QMYSQLResult::virtual_hook ( int id,
void * data )
overrideprotectedvirtual

Reimplemented from QSqlResult.

◆ QMYSQLDriver

QMYSQLDriver
friend

Definition at line 149 of file qsql_mysql.cpp.


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