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
QSqlResult Class Referenceabstract

The QSqlResult class provides an abstract interface for accessing data from specific SQL databases. More...

#include <qsqlresult.h>

Inheritance diagram for QSqlResult:
Collaboration diagram for QSqlResult:

Public Member Functions

virtual ~QSqlResult ()
 Destroys the object and frees any allocated resources.
virtual QVariant handle () const
 Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVariant if there is no handle.

Protected Types

enum  BindingSyntax { PositionalBinding , NamedBinding }
 This enum type specifies the different syntaxes for specifying placeholders in prepared queries. More...
enum  VirtualHookOperation

Protected Member Functions

 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 exec ()
 Executes the query, returning true if successful; otherwise returns false.
virtual bool prepare (const QString &query)
 Prepares the given query for execution; the query will normally use placeholders so that it can be executed repeatedly.
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 QVariant data (int i)=0
 Returns the data for field index in the current row as a QVariant.
virtual bool isNull (int i)=0
 Returns true if the field at position index in the current row is null; otherwise returns false.
virtual bool reset (const QString &sqlquery)=0
 Sets the result to use the SQL statement query for subsequent data retrieval.
virtual bool fetch (int i)=0
 Positions the result to an arbitrary (zero-based) row index.
virtual bool fetchNext ()
 Positions the result to the next available record (row) in the result.
virtual bool fetchPrevious ()
 Positions the result to the previous record (row) in the result.
virtual bool fetchFirst ()=0
 Positions the result to the first record (row 0) in the result.
virtual bool fetchLast ()=0
 Positions the result to the last record (last row) in the result.
virtual int size ()=0
 Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELECT statement.
virtual int numRowsAffected ()=0
 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.
virtual QSqlRecord record () const
 Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
virtual QVariant lastInsertId () const
 Returns the object ID of the most recent inserted row if the database supports it.
virtual void virtual_hook (int id, void *data)
virtual bool execBatch (bool arrayBind=false)
virtual void detachFromResultSet ()
virtual void setNumericalPrecisionPolicy (QSql::NumericalPrecisionPolicy policy)
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy () const
void setPositionalBindingEnabled (bool enable)
bool isPositionalBindingEnabled () const
virtual bool nextResult ()
void resetBindCount ()
 Resets the number of bind parameters.

Protected Attributes

QSqlResultPrivated_ptr

Friends

class QSqlQuery
class QSqlTableModelPrivate

Detailed Description

The QSqlResult class provides an abstract interface for accessing data from specific SQL databases.

\inmodule QtSql

Normally, you would use QSqlQuery instead of QSqlResult, since QSqlQuery provides a generic wrapper for database-specific implementations of QSqlResult.

If you are implementing your own SQL driver (by subclassing QSqlDriver), you will need to provide your own QSqlResult subclass that implements all the pure virtual functions and other virtual functions that you need.

See also
QSqlDriver

Definition at line 22 of file qsqlresult.h.

Member Enumeration Documentation

◆ BindingSyntax

enum QSqlResult::BindingSyntax
protected

This enum type specifies the different syntaxes for specifying placeholders in prepared queries.

\value PositionalBinding Use the ODBC-style positional syntax, with "?" as placeholders. \value NamedBinding Use the Oracle-style syntax with named placeholders (e.g., ":id")

See also
bindingSyntax()
Enumerator
PositionalBinding 
NamedBinding 

Definition at line 33 of file qsqlresult.h.

◆ VirtualHookOperation

Definition at line 95 of file qsqlresult.h.

Constructor & Destructor Documentation

◆ ~QSqlResult()

QSqlResult::~QSqlResult ( )
virtual

Destroys the object and frees any allocated resources.

Definition at line 215 of file qsqlresult.cpp.

◆ QSqlResult() [1/2]

QSqlResult::QSqlResult ( const QSqlDriver * db)
explicitprotected

Creates a QSqlResult using database driver db.

The object is initialized to an inactive state.

See also
isActive(), driver()

Definition at line 193 of file qsqlresult.cpp.

◆ QSqlResult() [2/2]

QSqlResult::QSqlResult ( QSqlResultPrivate & dd)
protected

Definition at line 203 of file qsqlresult.cpp.

Member Function Documentation

◆ addBindValue()

void QSqlResult::addBindValue ( const QVariant & val,
QSql::ParamType paramType )
protected

Binds the value val of parameter type paramType to the next available position in the current record (row).

See also
bindValue()

Definition at line 728 of file qsqlresult.cpp.

◆ at()

int QSqlResult::at ( ) const
protected

Returns the current (zero-based) row position of the result.

May return the special values QSql::BeforeFirstRow or QSql::AfterLastRow.

See also
setAt(), isValid()

Definition at line 254 of file qsqlresult.cpp.

◆ bindingSyntax()

QSqlResult::BindingSyntax QSqlResult::bindingSyntax ( ) const
protected

Returns the binding syntax used by prepared queries.

Definition at line 827 of file qsqlresult.cpp.

◆ bindValue() [1/2]

void QSqlResult::bindValue ( const QString & placeholder,
const QVariant & val,
QSql::ParamType paramType )
protectedvirtual

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

Note
Binding an undefined placeholder will result in undefined behavior.
See also
QSqlQuery::bindValue()

Reimplemented in QSqlNullResult.

Definition at line 705 of file qsqlresult.cpp.

◆ bindValue() [2/2]

void QSqlResult::bindValue ( int index,
const QVariant & val,
QSql::ParamType paramType )
protectedvirtual

Binds the value val of parameter type paramType to position index in the current record (row).

See also
addBindValue()

Reimplemented in QSqlNullResult.

Definition at line 681 of file qsqlresult.cpp.

◆ bindValueType() [1/2]

QSql::ParamType QSqlResult::bindValueType ( const QString & placeholder) const
protected

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.

Definition at line 780 of file qsqlresult.cpp.

◆ bindValueType() [2/2]

QSql::ParamType QSqlResult::bindValueType ( int index) const
protected

Returns the parameter type for the value bound at position index.

See also
boundValue()

Definition at line 768 of file qsqlresult.cpp.

◆ boundValue() [1/2]

QVariant QSqlResult::boundValue ( const QString & placeholder) const
protected

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

See also
bindValueType()

Definition at line 756 of file qsqlresult.cpp.

◆ boundValue() [2/2]

QVariant QSqlResult::boundValue ( int index) const
protected

Returns the value bound at position index in the current record (row).

See also
bindValue(), boundValues()

Definition at line 742 of file qsqlresult.cpp.

◆ boundValueCount()

int QSqlResult::boundValueCount ( ) const
protected

Returns the number of bound values in the result.

See also
boundValues()

Definition at line 791 of file qsqlresult.cpp.

◆ boundValueName()

QString QSqlResult::boundValueName ( int index) const
protected

Returns the name of the bound value at position index in the current record (row).

See also
boundValue(), boundValueNames()

Definition at line 886 of file qsqlresult.cpp.

◆ boundValueNames()

QStringList QSqlResult::boundValueNames ( ) const
protected

Returns the names of all bound values.

See also
boundValue(), boundValueName()

Definition at line 871 of file qsqlresult.cpp.

◆ boundValues() [1/2]

QVariantList & QSqlResult::boundValues ( QT6_DECL_NEW_OVERLOAD )
protected

◆ boundValues() [2/2]

QVariantList QSqlResult::boundValues ( QT6_DECL_NEW_OVERLOAD ) const
protected

◆ clear()

void QSqlResult::clear ( )
protected

Clears the entire result set and releases any associated resources.

Definition at line 837 of file qsqlresult.cpp.

◆ data()

virtual QVariant QSqlResult::data ( int index)
protectedpure virtual

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.

Implemented in QDB2Result, QDB2Result, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSqlNullResult, XyzResult, and XyzResult.

◆ detachFromResultSet()

void QSqlResult::detachFromResultSet ( )
protectedvirtual

◆ driver()

const QSqlDriver * QSqlResult::driver ( ) const
protected

Returns the driver associated with the result.

This is the object that was passed to the constructor.

Definition at line 340 of file qsqlresult.cpp.

◆ exec()

bool QSqlResult::exec ( )
protectedvirtual

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

See also
prepare()

Reimplemented in QDB2Result, QDB2Result, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, and QSqlNullResult.

Definition at line 631 of file qsqlresult.cpp.

◆ execBatch()

bool QSqlResult::execBatch ( bool arrayBind = false)
protectedvirtual

Executes a prepared query in batch mode if the driver supports it, otherwise emulates a batch execution using bindValue() and exec(). QSqlDriver::hasFeature() can be used to find out whether a driver supports batch execution.

Batch execution can be faster for large amounts of data since it reduces network roundtrips.

For batch executions, bound values have to be provided as lists of variants (QVariantList).

Each list must contain values of the same type. All lists must contain equal amount of values (rows).

NULL values are passed in as typed QVariants, for example {QVariant(QMetaType::fromType<int>())} for an integer NULL value.

Example:

q.prepare("insert into test (i1, i2, s) values (?, ?, ?)");
col1 << 1 << 3;
col2 << 2 << 4;
col3 << "hello" << "world";
q.bindValue(0, col1);
q.bindValue(1, col2);
q.bindValue(2, col3);
if (!q.execBatch())
qDebug() << q.lastError();

Here, we insert two rows into a SQL table, with each row containing three values.

See also
exec(), QSqlDriver::hasFeature()

Reimplemented in QMimerSQLResult, QMimerSQLResult, QOCIResult, QSQLiteResult, and QSQLiteResult.

Definition at line 975 of file qsqlresult.cpp.

◆ executedQuery()

QString QSqlResult::executedQuery ( ) const
protected

Returns the query that was actually executed.

This may differ from the query that was passed, for example if bound values were used with a prepared query and the underlying database doesn't support prepared queries.

See also
exec(), setQuery()

Definition at line 851 of file qsqlresult.cpp.

◆ fetch()

virtual bool QSqlResult::fetch ( int index)
protectedpure virtual

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

Implemented in QDB2Result, QDB2Result, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSqlNullResult, XyzResult, and XyzResult.

◆ fetchFirst()

virtual bool QSqlResult::fetchFirst ( )
protectedpure virtual

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

Implemented in QDB2Result, QDB2Result, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSqlNullResult, XyzResult, and XyzResult.

◆ fetchLast()

virtual bool QSqlResult::fetchLast ( )
protectedpure virtual

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

Implemented in QDB2Result, QDB2Result, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSqlNullResult, XyzResult, and XyzResult.

◆ fetchNext()

bool QSqlResult::fetchNext ( )
protectedvirtual

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 in QDB2Result, QDB2Result, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, and QSqlCachedResult.

Definition at line 489 of file qsqlresult.cpp.

◆ fetchPrevious()

bool QSqlResult::fetchPrevious ( )
protectedvirtual

Positions the result to the previous 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 previous 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.

Reimplemented in QODBCResult, QODBCResult, and QSqlCachedResult.

Definition at line 505 of file qsqlresult.cpp.

◆ handle()

QVariant QSqlResult::handle ( ) const
virtual

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 in QDB2Result, QDB2Result, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, and QSQLiteResult.

Definition at line 1068 of file qsqlresult.cpp.

◆ hasOutValues()

bool QSqlResult::hasOutValues ( ) const
protected

Returns true if at least one of the query's bound values is a QSql::Out or a QSql::InOut; otherwise returns false.

See also
bindValueType()

Definition at line 898 of file qsqlresult.cpp.

◆ isActive()

bool QSqlResult::isActive ( ) const
protected

Returns true if the result has records to be retrieved; otherwise returns false.

Definition at line 287 of file qsqlresult.cpp.

◆ isForwardOnly()

bool QSqlResult::isForwardOnly ( ) const
protected

Returns true if you can only scroll forward through the result set; otherwise returns false.

See also
setForwardOnly()

Definition at line 516 of file qsqlresult.cpp.

◆ isNull()

virtual bool QSqlResult::isNull ( int i)
protectedpure virtual

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

Implemented in QDB2Result, QDB2Result, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSqlNullResult, XyzResult, and XyzResult.

◆ isPositionalBindingEnabled()

bool QSqlResult::isPositionalBindingEnabled ( ) const
protected

Definition at line 1026 of file qsqlresult.cpp.

◆ isSelect()

bool QSqlResult::isSelect ( ) const
protected

Returns true if the current result is from a SELECT statement; otherwise returns false.

See also
setSelect()

Definition at line 329 of file qsqlresult.cpp.

◆ isValid()

bool QSqlResult::isValid ( ) const
protected

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.

See also
at()

Definition at line 269 of file qsqlresult.cpp.

◆ lastError()

QSqlError QSqlResult::lastError ( ) const
protected

Returns the last error associated with the result.

Definition at line 381 of file qsqlresult.cpp.

◆ lastInsertId()

QVariant QSqlResult::lastInsertId ( ) const
protectedvirtual

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 in QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, and QSQLiteResult.

Definition at line 938 of file qsqlresult.cpp.

◆ lastQuery()

QString QSqlResult::lastQuery ( ) const
protected

Returns the current SQL query text, or an empty string if there isn't one.

See also
setQuery()

Definition at line 241 of file qsqlresult.cpp.

◆ nextResult()

bool QSqlResult::nextResult ( )
protectedvirtual

◆ numericalPrecisionPolicy()

QSql::NumericalPrecisionPolicy QSqlResult::numericalPrecisionPolicy ( ) const
protected

Definition at line 1010 of file qsqlresult.cpp.

◆ numRowsAffected()

virtual int QSqlResult::numRowsAffected ( )
protectedpure virtual

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

Implemented in QDB2Result, QDB2Result, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, QSqlNullResult, XyzResult, and XyzResult.

◆ prepare()

bool QSqlResult::prepare ( const QString & query)
protectedvirtual

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 in QDB2Result, QDB2Result, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, and QSqlNullResult.

Definition at line 587 of file qsqlresult.cpp.

◆ record()

QSqlRecord QSqlResult::record ( ) const
protectedvirtual

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 in QDB2Result, QDB2Result, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, XyzResult, and XyzResult.

Definition at line 919 of file qsqlresult.cpp.

◆ reset()

virtual bool QSqlResult::reset ( const QString & query)
protectedpure virtual

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

Implemented in QDB2Result, QDB2Result, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, QSqlNullResult, XyzResult, and XyzResult.

◆ resetBindCount()

void QSqlResult::resetBindCount ( )
protected

Resets the number of bind parameters.

Definition at line 860 of file qsqlresult.cpp.

◆ savePrepare()

bool QSqlResult::savePrepare ( const QString & query)
protectedvirtual

Prepares the given query, using the underlying database functionality where possible.

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

Note: This method should have been called "safePrepare()".

See also
prepare()

Reimplemented in QSqlNullResult.

Definition at line 561 of file qsqlresult.cpp.

◆ setActive()

void QSqlResult::setActive ( bool active)
protectedvirtual

This function is provided for derived classes to set the internal active state to active.

See also
isActive()

Reimplemented in QSqlNullResult.

Definition at line 354 of file qsqlresult.cpp.

◆ setAt()

void QSqlResult::setAt ( int index)
protectedvirtual

This function is provided for derived classes to set the internal (zero-based) row position to index.

See also
at()

Reimplemented in QSqlNullResult.

Definition at line 300 of file qsqlresult.cpp.

◆ setForwardOnly()

void QSqlResult::setForwardOnly ( bool forward)
protectedvirtual

Sets forward only mode to forward.

If forward is true, only fetchNext() is allowed for navigating the results. Forward only mode needs much less memory since results do not have to be cached. By default, this feature is disabled.

Setting forward only to false is a suggestion to the database engine, which has the final say on whether a result set is forward only or scrollable. isForwardOnly() will always return the correct status of the result set.

Note
Calling setForwardOnly after execution of the query will result in unexpected results at best, and crashes at worst.
To make sure the forward-only query completed successfully, the application should check lastError() for an error not only after executing the query, but also after navigating the query results.
Warning
PostgreSQL: While navigating the query results in forward-only mode, do not execute any other SQL command on the same database connection. This will cause the query results to be lost.
See also
isForwardOnly(), fetchNext(), QSqlQuery::setForwardOnly()

Reimplemented in QSqlNullResult.

Definition at line 546 of file qsqlresult.cpp.

◆ setLastError()

void QSqlResult::setLastError ( const QSqlError & error)
protectedvirtual

This function is provided for derived classes to set the last error to error.

See also
lastError()

Reimplemented in QSqlNullResult.

Definition at line 370 of file qsqlresult.cpp.

◆ setNumericalPrecisionPolicy()

void QSqlResult::setNumericalPrecisionPolicy ( QSql::NumericalPrecisionPolicy policy)
protectedvirtual

Reimplemented in QSqlCachedResult.

Definition at line 1002 of file qsqlresult.cpp.

◆ setPositionalBindingEnabled()

void QSqlResult::setPositionalBindingEnabled ( bool enable)
protected

Definition at line 1018 of file qsqlresult.cpp.

◆ setQuery()

void QSqlResult::setQuery ( const QString & query)
protectedvirtual

Sets the current query for the result to query.

You must call reset() to execute the query on the database.

See also
reset(), lastQuery()

Reimplemented in QSqlNullResult.

Definition at line 228 of file qsqlresult.cpp.

◆ setSelect()

void QSqlResult::setSelect ( bool select)
protectedvirtual

This function is provided for derived classes to indicate whether or not the current statement is a SQL SELECT statement.

The select parameter should be true if the statement is a SELECT statement; otherwise it should be false.

See also
isSelect()

Reimplemented in QSqlNullResult.

Definition at line 316 of file qsqlresult.cpp.

◆ size()

virtual int QSqlResult::size ( )
protectedpure virtual

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

Implemented in QDB2Result, QDB2Result, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, QSqlNullResult, XyzResult, and XyzResult.

◆ virtual_hook()

void QSqlResult::virtual_hook ( int id,
void * data )
protectedvirtual

◆ QSqlQuery

friend class QSqlQuery
friend

Definition at line 25 of file qsqlresult.h.

◆ QSqlTableModelPrivate

friend class QSqlTableModelPrivate
friend

Definition at line 26 of file qsqlresult.h.

Member Data Documentation

◆ d_ptr

QSqlResultPrivate* QSqlResult::d_ptr
protected

Definition at line 106 of file qsqlresult.h.


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