![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases. More...
#include <qsqlresult.h>
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 QSqlDriver * | driver () 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. | |
| QVariantList & | boundValues (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 | |
| QSqlResultPrivate * | d_ptr |
Friends | |
| class | QSqlQuery |
| class | QSqlTableModelPrivate |
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.
Definition at line 22 of file qsqlresult.h.
|
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")
| Enumerator | |
|---|---|
| PositionalBinding | |
| NamedBinding | |
Definition at line 33 of file qsqlresult.h.
|
protected |
Definition at line 95 of file qsqlresult.h.
|
virtual |
Destroys the object and frees any allocated resources.
Definition at line 216 of file qsqlresult.cpp.
|
explicitprotected |
Creates a QSqlResult using database driver db.
The object is initialized to an inactive state.
Definition at line 194 of file qsqlresult.cpp.
|
protected |
Definition at line 204 of file qsqlresult.cpp.
Binds the value val of parameter type paramType to the next available position in the current record (row).
Definition at line 729 of file qsqlresult.cpp.
|
protected |
Returns the current (zero-based) row position of the result.
May return the special values QSql::BeforeFirstRow or QSql::AfterLastRow.
Definition at line 255 of file qsqlresult.cpp.
|
protected |
Returns the binding syntax used by prepared queries.
Definition at line 828 of file qsqlresult.cpp.
|
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).
Reimplemented in QSqlNullResult.
Definition at line 706 of file qsqlresult.cpp.
|
protectedvirtual |
Binds the value val of parameter type paramType to position index in the current record (row).
Reimplemented in QSqlNullResult.
Definition at line 682 of file qsqlresult.cpp.
|
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 781 of file qsqlresult.cpp.
|
protected |
Returns the parameter type for the value bound at position index.
Definition at line 769 of file qsqlresult.cpp.
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).
Definition at line 757 of file qsqlresult.cpp.
|
protected |
Returns the value bound at position index in the current record (row).
Definition at line 743 of file qsqlresult.cpp.
|
protected |
Returns the number of bound values in the result.
Definition at line 792 of file qsqlresult.cpp.
|
protected |
Returns the name of the bound value at position index in the current record (row).
Definition at line 887 of file qsqlresult.cpp.
|
protected |
Returns the names of all bound values.
Definition at line 872 of file qsqlresult.cpp.
|
protected |
|
protected |
|
protected |
Clears the entire result set and releases any associated resources.
Definition at line 838 of file qsqlresult.cpp.
|
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, QFirebirdResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSqlNullResult, XyzResult, and XyzResult.
|
protectedvirtual |
Reimplemented in QDB2Result, QDB2Result, QFirebirdResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QSqlCachedResult, QSQLiteResult, and QSQLiteResult.
Definition at line 997 of file qsqlresult.cpp.
|
protected |
Returns the driver associated with the result.
This is the object that was passed to the constructor.
Definition at line 341 of file qsqlresult.cpp.
|
protectedvirtual |
Executes the query, returning true if successful; otherwise returns false.
Reimplemented in QDB2Result, QDB2Result, QFirebirdResult, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, and QSqlNullResult.
Definition at line 632 of file qsqlresult.cpp.
|
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:
Here, we insert two rows into a SQL table, with each row containing three values.
Reimplemented in QFirebirdResult, QMimerSQLResult, QMimerSQLResult, QOCIResult, QSQLiteResult, and QSQLiteResult.
Definition at line 976 of file qsqlresult.cpp.
|
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.
Definition at line 852 of file qsqlresult.cpp.
|
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.
Implemented in QDB2Result, QDB2Result, QFirebirdResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSqlNullResult, XyzResult, and XyzResult.
|
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.
Implemented in QDB2Result, QDB2Result, QFirebirdResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSqlNullResult, XyzResult, and XyzResult.
|
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.
Implemented in QDB2Result, QDB2Result, QFirebirdResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSqlNullResult, XyzResult, and XyzResult.
|
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.
Reimplemented in QDB2Result, QDB2Result, QFirebirdResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, and QSqlCachedResult.
Definition at line 490 of file qsqlresult.cpp.
|
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 QFirebirdResult, QODBCResult, QODBCResult, and QSqlCachedResult.
Definition at line 506 of file qsqlresult.cpp.
|
virtual |
Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVariant if there is no handle.
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:
This snippet returns the handle for PostgreSQL or MySQL:
Reimplemented in QDB2Result, QDB2Result, QFirebirdResult, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, and QSQLiteResult.
Definition at line 1069 of file qsqlresult.cpp.
|
protected |
Returns true if at least one of the query's bound values is a QSql::Out or a QSql::InOut; otherwise returns false.
Definition at line 899 of file qsqlresult.cpp.
|
protected |
Returns true if the result has records to be retrieved; otherwise returns false.
Definition at line 288 of file qsqlresult.cpp.
|
protected |
Returns true if you can only scroll forward through the result set; otherwise returns false.
Definition at line 517 of file qsqlresult.cpp.
|
protectedpure virtual |
Returns true if the field at position index in the current row is null; otherwise returns false.
Implemented in QDB2Result, QDB2Result, QFirebirdResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSqlNullResult, XyzResult, and XyzResult.
|
protected |
Definition at line 1027 of file qsqlresult.cpp.
|
protected |
Returns true if the current result is from a SELECT statement; otherwise returns false.
Definition at line 330 of file qsqlresult.cpp.
|
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.
Definition at line 270 of file qsqlresult.cpp.
|
protected |
Returns the last error associated with the result.
Definition at line 382 of file qsqlresult.cpp.
|
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.
Reimplemented in QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, and QSQLiteResult.
Definition at line 939 of file qsqlresult.cpp.
|
protected |
Returns the current SQL query text, or an empty string if there isn't one.
Definition at line 242 of file qsqlresult.cpp.
|
protectedvirtual |
Reimplemented in QDB2Result, QDB2Result, QMYSQLResult, QMYSQLResult, QODBCResult, QODBCResult, QPSQLResult, and QPSQLResult.
Definition at line 1036 of file qsqlresult.cpp.
|
protected |
Definition at line 1011 of file qsqlresult.cpp.
|
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.
Implemented in QDB2Result, QDB2Result, QFirebirdResult, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, QSqlNullResult, XyzResult, and XyzResult.
|
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.
Reimplemented in QDB2Result, QDB2Result, QFirebirdResult, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, and QSqlNullResult.
Definition at line 588 of file qsqlresult.cpp.
|
protectedvirtual |
Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
The default implementation always returns an empty QSqlRecord.
Reimplemented in QDB2Result, QDB2Result, QFirebirdResult, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, XyzResult, and XyzResult.
Definition at line 920 of file qsqlresult.cpp.
|
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.
Implemented in QDB2Result, QDB2Result, QFirebirdResult, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, QSqlNullResult, XyzResult, and XyzResult.
|
protected |
Resets the number of bind parameters.
Definition at line 861 of file qsqlresult.cpp.
|
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()".
Reimplemented in QSqlNullResult.
Definition at line 562 of file qsqlresult.cpp.
|
protectedvirtual |
This function is provided for derived classes to set the internal active state to active.
Reimplemented in QSqlNullResult.
Definition at line 355 of file qsqlresult.cpp.
|
protectedvirtual |
This function is provided for derived classes to set the internal (zero-based) row position to index.
Reimplemented in QSqlNullResult.
Definition at line 301 of file qsqlresult.cpp.
|
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.
Reimplemented in QSqlNullResult.
Definition at line 547 of file qsqlresult.cpp.
This function is provided for derived classes to set the last error to error.
Reimplemented in QSqlNullResult.
Definition at line 371 of file qsqlresult.cpp.
|
protectedvirtual |
Reimplemented in QSqlCachedResult.
Definition at line 1003 of file qsqlresult.cpp.
|
protected |
Definition at line 1019 of file qsqlresult.cpp.
Sets the current query for the result to query.
You must call reset() to execute the query on the database.
Reimplemented in QSqlNullResult.
Definition at line 229 of file qsqlresult.cpp.
|
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.
Reimplemented in QSqlNullResult.
Definition at line 317 of file qsqlresult.cpp.
|
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.
Implemented in QDB2Result, QDB2Result, QFirebirdResult, QIBaseResult, QIBaseResult, QMimerSQLResult, QMimerSQLResult, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSQLiteResult, QSQLiteResult, QSqlNullResult, XyzResult, and XyzResult.
Reimplemented in QDB2Result, QDB2Result, QMYSQLResult, QMYSQLResult, QOCIResult, QODBCResult, QODBCResult, QPSQLResult, QPSQLResult, QSqlCachedResult, QSQLiteResult, and QSQLiteResult.
Definition at line 946 of file qsqlresult.cpp.
|
friend |
Definition at line 25 of file qsqlresult.h.
|
friend |
Definition at line 26 of file qsqlresult.h.
|
protected |
Definition at line 106 of file qsqlresult.h.