Qt 6.x
The Qt SDK
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
 
virtual bool nextResult ()
 
void resetBindCount ()
 Resets the number of bind parameters.
 

Protected Attributes

QSqlResultPrivated_ptr
 

Friends

class QSqlQuery
 
class QSqlTableModelPrivate
 
class ::tst_QSqlQuery
 

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 24 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 37 of file qsqlresult.h.

◆ VirtualHookOperation

Definition at line 99 of file qsqlresult.h.

Constructor & Destructor Documentation

◆ ~QSqlResult()

QSqlResult::~QSqlResult ( )
virtual

Destroys the object and frees any allocated resources.

Definition at line 204 of file qsqlresult.cpp.

References d.

◆ 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 182 of file qsqlresult.cpp.

References d, d_ptr, db, and setNumericalPrecisionPolicy().

+ Here is the call graph for this function:

◆ QSqlResult() [2/2]

QSqlResult::QSqlResult ( QSqlResultPrivate dd)
protected

Definition at line 192 of file qsqlresult.cpp.

References d, and setNumericalPrecisionPolicy().

+ Here is the call graph for this function:

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 717 of file qsqlresult.cpp.

References bindValue(), d, and PositionalBinding.

Referenced by QSqlQuery::addBindValue().

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

◆ at()

◆ bindingSyntax()

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

Returns the binding syntax used by prepared queries.

Definition at line 816 of file qsqlresult.cpp.

References d.

◆ 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 694 of file qsqlresult.cpp.

References d, QSql::In, and NamedBinding.

◆ 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 670 of file qsqlresult.cpp.

References QList< T >::append(), QListSpecialMethodsBase< T >::contains(), d, QSql::In, and PositionalBinding.

Referenced by addBindValue(), QSqlQuery::bindValue(), QSqlQuery::bindValue(), QOCIResultPrivate::bindValues(), QMimerSQLResult::exec(), QSQLiteResult::execBatch(), and execBatch().

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

◆ 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 769 of file qsqlresult.cpp.

References d, and QSql::In.

Referenced by QDB2Result::exec(), QMimerSQLResult::exec(), QODBCResult::exec(), and QMimerSQLResult::execBatch().

+ Here is the caller graph for this function:

◆ 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 757 of file qsqlresult.cpp.

References d, and QSql::In.

◆ 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 745 of file qsqlresult.cpp.

References d, and QList< T >::value().

Referenced by QSqlQuery::boundValue(), and QSqlQuery::boundValue().

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

◆ 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 731 of file qsqlresult.cpp.

References d.

◆ boundValueCount()

int QSqlResult::boundValueCount ( ) const
protected

Returns the number of bound values in the result.

See also
boundValues()

Definition at line 780 of file qsqlresult.cpp.

References d.

Referenced by QOCIResult::exec().

+ Here is the caller graph for this function:

◆ 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 875 of file qsqlresult.cpp.

References d.

Referenced by QSqlQuery::boundValueName().

+ Here is the caller graph for this function:

◆ boundValueNames()

QStringList QSqlResult::boundValueNames ( ) const
protected

Returns the names of all bound values.

See also
boundValue(), boundValueName()

Definition at line 860 of file qsqlresult.cpp.

References d, and ret.

Referenced by QSqlQuery::boundValueNames().

+ Here is the caller graph for this function:

◆ boundValues() [1/2]

QVariantList & QSqlResult::boundValues ( QT6_DECL_NEW_OVERLOAD  )
protected

Referenced by QSqlQuery::boundValues(), QDB2Result::exec(), QIBaseResult::exec(), QMimerSQLResult::exec(), QMYSQLResult::exec(), QOCIResult::exec(), QODBCResult::exec(), QPSQLResult::exec(), QSQLiteResult::exec(), QMimerSQLResult::execBatch(), and QOCIResult::execBatch().

+ Here is the caller graph for this function:

◆ 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 826 of file qsqlresult.cpp.

References d.

Referenced by QSqlQuery::exec().

+ Here is the caller graph for this function:

◆ data()

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, QMYSQLResult, QODBCResult, QMimerSQLResult, QPSQLResult, QSqlCachedResult, XyzResult, and QSqlNullResult.

Referenced by QSqlQuery::value().

+ Here is the caller graph for this function:

◆ detachFromResultSet()

void QSqlResult::detachFromResultSet ( )
protectedvirtual

Reimplemented in QDB2Result, QMYSQLResult, QODBCResult, QSQLiteResult, and QSqlCachedResult.

Definition at line 987 of file qsqlresult.cpp.

Referenced by QSqlQuery::finish().

+ Here is the caller graph for this function:

◆ driver()

◆ exec()

bool QSqlResult::exec ( )
protectedvirtual

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

See also
prepare()

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

Definition at line 620 of file qsqlresult.cpp.

References d, driver(), QSqlDriver::formatValue(), i, QSqlResultPrivate::isVariantNull(), lastQuery(), QVariant::metaType(), NamedBinding, QString::replace(), ret, setQuery(), and var.

Referenced by QSqlQuery::exec(), QMimerSQLResult::exec(), QMYSQLResult::exec(), QPSQLResult::exec(), and execBatch().

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

◆ execBatch()

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

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();
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition qsqlquery.h:23
#define qDebug
[1]
Definition qlogging.h:160
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259

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

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

Reimplemented in QSQLiteResult, QMimerSQLResult, and QOCIResult.

Definition at line 966 of file qsqlresult.cpp.

References bindValue(), d, exec(), i, QSql::In, j, and Q_UNUSED.

Referenced by QSqlQuery::execBatch().

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

◆ 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 840 of file qsqlresult.cpp.

References d.

Referenced by QSqlQuery::executedQuery().

+ Here is the caller graph for this function:

◆ fetch()

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, QMimerSQLResult, QMYSQLResult, QODBCResult, QPSQLResult, QSqlCachedResult, XyzResult, and QSqlNullResult.

Referenced by fetchNext(), fetchPrevious(), and QSqlQuery::seek().

+ Here is the caller graph for this function:

◆ fetchFirst()

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, QMimerSQLResult, QMYSQLResult, QODBCResult, QPSQLResult, XyzResult, QSqlCachedResult, and QSqlNullResult.

Referenced by QSqlQuery::first(), and QSqlQuery::next().

+ Here is the caller graph for this function:

◆ fetchLast()

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, QMimerSQLResult, QMYSQLResult, QODBCResult, QPSQLResult, XyzResult, QSqlCachedResult, and QSqlNullResult.

Referenced by QSqlQuery::last(), QSqlQuery::previous(), and QSqlQuery::seek().

+ Here is the caller graph for this function:

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

Definition at line 478 of file qsqlresult.cpp.

References at(), and fetch().

Referenced by QSqlQuery::next(), and QSqlQuery::seek().

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

◆ 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, and QSqlCachedResult.

Definition at line 494 of file qsqlresult.cpp.

References at(), and fetch().

Referenced by QSqlQuery::previous(), and QSqlQuery::seek().

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

◆ 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) {
// ...
}
}
The QSqlDatabase class handles a connection to a database.
static QSqlDatabase database(const QString &connectionName=QLatin1StringView(defaultConnection), bool open=true)
\threadsafe
\inmodule QtCore
Definition qvariant.h:64
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
GLsizei const GLfloat * v
[13]
GLuint64 GLenum void * handle
GLenum query
QMimeDatabase db
[0]
void * sqlite3_stmt

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) {
// ...
}
}
struct pg_result PGresult
Definition qsql_psql_p.h:27
See also
QSqlDriver::handle()

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

Definition at line 1042 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 887 of file qsqlresult.cpp.

References d, QSql::In, and it.

Referenced by QDB2Result::exec(), QOCIResult::exec(), and QODBCResult::exec().

+ Here is the caller graph for this function:

◆ isActive()

◆ isForwardOnly()

◆ isNull()

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

Referenced by QSqlQuery::isNull().

+ Here is the caller graph for this function:

◆ 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 318 of file qsqlresult.cpp.

References d.

Referenced by QMYSQLResult::data(), QIBaseResult::exec(), QMYSQLResult::exec(), QODBCResult::exec(), QMimerSQLResult::fetch(), QMimerSQLResult::fetchFirst(), QMimerSQLResult::fetchLast(), QMimerSQLResult::fetchNext(), QSqlQuery::isSelect(), QMYSQLResult::nextResult(), QIBaseResult::prepare(), QMimerSQLResult::record(), QMYSQLResult::record(), QOCIResult::record(), QODBCResult::record(), QPSQLResult::record(), QSQLiteResult::record(), QMYSQLResult::reset(), QIBaseResult::size(), QMimerSQLResult::size(), and QMYSQLResult::size().

+ Here is the caller graph for this function:

◆ 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 258 of file qsqlresult.cpp.

References QSql::AfterLastRow, QSql::BeforeFirstRow, and d.

Referenced by QSQLiteResult::exec(), QSqlQuery::isNull(), and QSqlQuery::isValid().

+ Here is the caller graph for this function:

◆ lastError()

QSqlError QSqlResult::lastError ( ) const
protected

Returns the last error associated with the result.

Definition at line 370 of file qsqlresult.cpp.

References d.

Referenced by QSqlQuery::exec(), QSQLiteResult::exec(), QOCIResult::execBatch(), and QSqlQuery::lastError().

+ Here is the caller graph for this function:

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

Definition at line 927 of file qsqlresult.cpp.

Referenced by QSqlQuery::lastInsertId().

+ Here is the caller graph for this function:

◆ 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 230 of file qsqlresult.cpp.

References d.

Referenced by QSqlQuery::exec(), exec(), QOCIResult::exec(), QSqlQuery::exec(), QOCIResult::gotoNext(), and QSqlQuery::lastQuery().

+ Here is the caller graph for this function:

◆ nextResult()

bool QSqlResult::nextResult ( )
protectedvirtual

Reimplemented in QDB2Result, QMYSQLResult, QODBCResult, and QPSQLResult.

Definition at line 1009 of file qsqlresult.cpp.

Referenced by QSqlQuery::nextResult().

+ Here is the caller graph for this function:

◆ numericalPrecisionPolicy()

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

Definition at line 1001 of file qsqlresult.cpp.

References d.

Referenced by QDB2Result::data(), QMYSQLResult::data(), QODBCResult::data(), QMimerSQLResult::data(), QPSQLResult::data(), QSqlQuery::exec(), QIBaseResult::gotoNext(), QSqlQuery::numericalPrecisionPolicy(), and QSqlQuery::prepare().

+ Here is the caller graph for this function:

◆ numRowsAffected()

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

Referenced by QSqlQuery::exec(), QSqlQuery::exec(), and QSqlQuery::numRowsAffected().

+ Here is the caller graph for this function:

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

Definition at line 576 of file qsqlresult.cpp.

References d.

Referenced by QMimerSQLResult::prepare(), QOCIResult::prepare(), QPSQLResult::prepare(), QMYSQLResult::prepare(), and savePrepare().

+ Here is the caller graph for this function:

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

Definition at line 908 of file qsqlresult.cpp.

Referenced by QSqlQuery::isNull(), QSqlQuery::record(), and QSqlQuery::value().

+ Here is the caller graph for this function:

◆ reset()

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

Referenced by QSqlQuery::exec().

+ Here is the caller graph for this function:

◆ resetBindCount()

void QSqlResult::resetBindCount ( )
protected

Resets the number of bind parameters.

Definition at line 849 of file qsqlresult.cpp.

References d.

Referenced by QSqlQuery::exec(), QSqlQuery::execBatch(), and QOCIResult::execBatch().

+ Here is the caller graph for this function:

◆ 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 550 of file qsqlresult.cpp.

References d, driver(), hasFeature(), QSqlDriver::NamedPlaceholders, prepare(), and QSqlDriver::PreparedQueries.

Referenced by QSqlQuery::prepare().

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

◆ 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 343 of file qsqlresult.cpp.

References d.

Referenced by QMYSQLResult::cleanup(), QPSQLResult::cleanup(), QSqlCachedResult::cleanup(), QDB2Result::exec(), QIBaseResult::exec(), QMimerSQLResult::exec(), QMYSQLResult::exec(), QOCIResult::exec(), QODBCResult::exec(), QSQLiteResult::exec(), QSqlQuery::exec(), QSqlQuery::finish(), QDB2Result::nextResult(), QMYSQLResult::nextResult(), QODBCResult::nextResult(), QSqlQuery::prepare(), QDB2Result::prepare(), QIBaseResult::prepare(), QODBCResult::prepare(), QDB2Result::reset(), QMYSQLResult::reset(), and QODBCResult::reset().

+ Here is the caller graph for this function:

◆ 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 289 of file qsqlresult.cpp.

References d.

Referenced by QMYSQLResult::cleanup(), QPSQLResult::cleanup(), QSqlCachedResult::cleanup(), QSqlCachedResult::clearValues(), QDB2Result::exec(), QIBaseResult::exec(), QMimerSQLResult::exec(), QMYSQLResult::exec(), QOCIResult::exec(), QODBCResult::exec(), QSqlQuery::exec(), QDB2Result::fetch(), QMimerSQLResult::fetch(), QMYSQLResult::fetch(), QODBCResult::fetch(), QPSQLResult::fetch(), QSqlCachedResult::fetch(), QDB2Result::fetchFirst(), QMimerSQLResult::fetchFirst(), QODBCResult::fetchFirst(), QPSQLResult::fetchFirst(), QSqlCachedResult::fetchFirst(), QDB2Result::fetchLast(), QMimerSQLResult::fetchLast(), QODBCResult::fetchLast(), QPSQLResult::fetchLast(), QSqlCachedResult::fetchLast(), QDB2Result::fetchNext(), QMimerSQLResult::fetchNext(), QMYSQLResult::fetchNext(), QODBCResult::fetchNext(), QPSQLResult::fetchNext(), QSqlCachedResult::fetchNext(), QODBCResult::fetchPrevious(), QSqlQuery::finish(), QIBaseResult::gotoNext(), QOCIResult::gotoNext(), QSqlQuery::next(), QDB2Result::nextResult(), QMYSQLResult::nextResult(), QODBCResult::nextResult(), QPSQLResult::nextResult(), QSqlQuery::prepare(), QDB2Result::prepare(), QIBaseResult::prepare(), QODBCResult::prepare(), QSqlQuery::previous(), QDB2Result::reset(), QMYSQLResult::reset(), QODBCResult::reset(), and QSqlQuery::seek().

◆ 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 535 of file qsqlresult.cpp.

References d.

Referenced by QODBCResult::exec(), QPSQLResult::exec(), QODBCResult::reset(), QPSQLResult::reset(), and QSqlQuery::setForwardOnly().

+ Here is the caller graph for this function:

◆ setLastError()

void QSqlResult::setLastError ( const QSqlError error)
protectedvirtual

◆ setNumericalPrecisionPolicy()

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

Reimplemented in QSqlCachedResult.

Definition at line 993 of file qsqlresult.cpp.

References d, and policy.

Referenced by QSqlResult(), QSqlResult(), QSqlQuery::exec(), QSqlQuery::prepare(), QSqlCachedResult::setNumericalPrecisionPolicy(), and QSqlQuery::setNumericalPrecisionPolicy().

+ Here is the caller graph for this function:

◆ 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 217 of file qsqlresult.cpp.

References d.

Referenced by exec(), and QSqlQuery::exec().

+ Here is the caller graph for this function:

◆ 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 305 of file qsqlresult.cpp.

References d, and select().

Referenced by QDB2Result::exec(), QMimerSQLResult::exec(), QMYSQLResult::exec(), QOCIResult::exec(), QODBCResult::exec(), QSQLiteResult::exec(), QDB2Result::nextResult(), QMYSQLResult::nextResult(), QODBCResult::nextResult(), QIBaseResult::prepare(), QSQLiteResult::prepare(), QMYSQLResult::prepare(), QDB2Result::reset(), QMYSQLResult::reset(), and QODBCResult::reset().

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

◆ size()

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

Referenced by QSqlQuery::exec(), QSqlQuery::exec(), and QSqlQuery::size().

+ Here is the caller graph for this function:

◆ virtual_hook()

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

Reimplemented in QDB2Result, QMYSQLResult, QOCIResult, QODBCResult, QPSQLResult, QSQLiteResult, and QSqlCachedResult.

Definition at line 934 of file qsqlresult.cpp.

Referenced by QDB2Result::virtual_hook(), QMYSQLResult::virtual_hook(), QODBCResult::virtual_hook(), QPSQLResult::virtual_hook(), and QSqlCachedResult::virtual_hook().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ ::tst_QSqlQuery

friend class ::tst_QSqlQuery
friend

Definition at line 30 of file qsqlresult.h.

◆ QSqlQuery

friend class QSqlQuery
friend

Definition at line 27 of file qsqlresult.h.

◆ QSqlTableModelPrivate

friend class QSqlTableModelPrivate
friend

Definition at line 28 of file qsqlresult.h.

Member Data Documentation

◆ d_ptr

QSqlResultPrivate* QSqlResult::d_ptr
protected

Definition at line 108 of file qsqlresult.h.

Referenced by QSqlResult().


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