Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QSqlResult Class Reference

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

    #include <QSqlResult>

- List of all members, including inherited members

### Public Functions

- virtual ~QSqlResult ()

### Protected Types

- enum BindMethod { BindByPosition, BindByName }

### Protected Functions

- QSqlResult ( const QSqlDriver * db )
- void addBindValue ( const QCoreVariant & val, QSql::ParamType tp )
- int at () const
- BindMethod bindMethod () const
- virtual void bindValue ( int pos, const QCoreVariant & val, QSql::ParamType tp )
- virtual void bindValue ( const QString & placeholder, const QCoreVariant & val, QSql::ParamType tp )
- QSql::ParamType bindValueType ( int pos ) const
- QSql::ParamType bindValueType ( const QString & placeholder ) const
- QCoreVariant boundValue ( int pos ) const
- QCoreVariant boundValue ( const QString & placeholder ) const
- int boundValueCount () const
- QString boundValueName ( int pos ) const
- QVector<QCoreVariant> & boundValues () const
- void clear ()
- virtual QCoreVariant data ( int i ) = 0
- const QSqlDriver * driver () const
- virtual bool exec ()
- QString executedQuery () const
- virtual bool fetch ( int i ) = 0
- virtual bool fetchFirst () = 0
- virtual bool fetchLast () = 0
- virtual bool fetchNext ()
- virtual bool fetchPrevious ()
- bool hasOutValues () const
- bool isActive () const
- bool isForwardOnly () const
- virtual bool isNull ( int i ) = 0
- bool isSelect () const
- bool isValid () const
- QSqlError lastError () const
- QString lastQuery () const
- virtual int numRowsAffected () = 0
- virtual bool prepare ( const QString & query )
- virtual QSqlRecord record () const
- virtual bool reset ( const QString & query ) = 0
- virtual bool savePrepare ( const QString & query )
- virtual void setActive ( bool a )
- virtual void setAt ( int at )
- virtual void setForwardOnly ( bool forward )
- virtual void setLastError ( const QSqlError & e )
- virtual void setQuery ( const QString & query )
- virtual void setSelect ( bool s )
- virtual int size () = 0

## Detailed Description

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

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 you will need to provide your own QSqlResult subclass that implements all the pure virtual functions, and the other virtual functions that you need, (as well as a QSqlDriver subclass).

See also QSql.

## Member Type Documentation

### enum QSqlResult::BindMethod

`QSqlResult::BindByPosition` |
`QSqlResult::BindByName` |

## Member Function Documentation

### QSqlResult::QSqlResult ( const QSqlDriver * db ) `[protected]`

This constructor creates a QSqlResult using database db. The object is initialized to an inactive state.

### QSqlResult::~QSqlResult () `[virtual]`

Destroys the object and frees any allocated resources.

### void QSqlResult::addBindValue ( const QCoreVariant & val, QSql::ParamType tp ) `[protected]`

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

### int QSqlResult::at () const `[protected]`

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

### BindMethod QSqlResult::bindMethod () const `[protected]`

Returns the bind method used for prepared queries, either `BindByPosition` or `BindByName`.

### void QSqlResult::bindValue ( int pos, const QCoreVariant & val, QSql::ParamType tp ) `[virtual protected]`

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

### void QSqlResult::bindValue ( const QString & placeholder, const QCoreVariant & val, QSql::ParamType tp ) `[virtual protected]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Binds the value val of parameter type tp to the placeholder name in the current record (row).

### QSql::ParamType QSqlResult::bindValueType ( int pos ) const `[protected]`

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

### QSql::ParamType QSqlResult::bindValueType ( const QString & placeholder ) const `[protected]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the parameter type for the value bound with the given placeholder name.

### QCoreVariant QSqlResult::boundValue ( int pos ) const `[protected]`

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

### QCoreVariant QSqlResult::boundValue ( const QString & placeholder ) const `[protected]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the value bound by the given placeholder name in the current record (row).

### int QSqlResult::boundValueCount () const `[protected]`

Returns the number of bound values in the result.

See also boundValues().

### QString QSqlResult::boundValueName ( int pos ) const `[protected]`

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

### QVector<QCoreVariant> & QSqlResult::boundValues () const `[protected]`

Returns a vector of the result's bound values for the current record (row).

See also boundValueCount().

### void QSqlResult::clear () `[protected]`

Clears the entire result set and releases any associated resources.

### QCoreVariant QSqlResult::data ( int i ) `[pure virtual protected]`

Returns the data for field i (zero-based) in the current row as a QCoreVariant. This function is only called if the result is in an active state and is positioned on a valid record and i is non-negative. Derived classes must reimplement this function and return the value of field i, or QCoreVariant() if it cannot be determined.

### const QSqlDriver * QSqlResult::driver () const `[protected]`

Returns the driver associated with the result.

### bool QSqlResult::exec () `[virtual protected]`

Executes the query.

See also prepare().

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

### bool QSqlResult::fetch ( int i ) `[pure virtual protected]`

Positions the result to an arbitrary (zero-based) row i. 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 i, and call setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

### bool QSqlResult::fetchFirst () `[pure virtual protected]`

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.

### bool QSqlResult::fetchLast () `[pure virtual protected]`

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.

### bool QSqlResult::fetchNext () `[virtual protected]`

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.

### bool QSqlResult::fetchPrevious () `[virtual protected]`

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.

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

### bool QSqlResult::isActive () const `[protected]`

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

### bool QSqlResult::isForwardOnly () const `[protected]`

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

See also setForwardOnly().

### bool QSqlResult::isNull ( int i ) `[pure virtual protected]`

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

### bool QSqlResult::isSelect () const `[protected]`

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

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

### QSqlError QSqlResult::lastError () const `[protected]`

Returns the last error associated with the result.

### QString QSqlResult::lastQuery () const `[protected]`

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

### int QSqlResult::numRowsAffected () `[pure virtual protected]`

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

### bool QSqlResult::prepare ( const QString & query ) `[virtual protected]`

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

### QSqlRecord QSqlResult::record () const `[virtual protected]`

The base class implementation does nothing and returns an empty QSqlRecord.

### bool QSqlResult::reset ( const QString & query ) `[pure virtual protected]`

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.

### bool QSqlResult::savePrepare ( const QString & query ) `[virtual protected]`

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

### void QSqlResult::setActive ( bool a ) `[virtual protected]`

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

See also isActive().

### void QSqlResult::setAt ( int at ) `[virtual protected]`

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

See also at().

### void QSqlResult::setForwardOnly ( bool forward ) `[virtual protected]`

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. forward only mode is off by default.

See also isForwardOnly() and fetchNext().

### void QSqlResult::setLastError ( const QSqlError & e ) `[virtual protected]`

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

See also lastError().

### void QSqlResult::setQuery ( const QString & query ) `[virtual protected]`

Sets the current query for the result to query. The result must be reset() in order to execute the query on the database.

### void QSqlResult::setSelect ( bool s ) `[virtual protected]`

This function is provided for derived classes to indicate whether or not the current statement is a SQL `SELECT` statement. The s parameter should be true if the statement is a `SELECT` statement; otherwise it should be false.

### int QSqlResult::size () `[pure virtual protected]`

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

See also numRowsAffected().