TQSqlResult Class

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

# TQSqlResult Class Reference
[sql module]

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

`#include <tqsqlresult.h>`

List of all member functions.

## Public Members

- virtual ~TQSqlResult ()

## Protected Members

- TQSqlResult ( const TQSqlDriver * db )
- int at () const
- TQString lastQuery () const
- TQSqlError lastError () const
- bool isValid () const
- bool isActive () const
- bool isSelect () const
- bool isForwardOnly () const
- const TQSqlDriver * driver () const
- virtual void setAt ( int at )
- virtual void setActive ( bool a )
- virtual void setLastError ( const TQSqlError & e )
- virtual void setQuery ( const TQString & query )
- virtual void setSelect ( bool s )
- virtual void setForwardOnly ( bool forward )
- virtual TQVariant data ( int i ) = 0
- virtual bool isNull ( int i ) = 0
- virtual bool reset ( const TQString & query ) = 0
- virtual bool fetch ( int i ) = 0
- virtual bool fetchNext ()
- virtual bool fetchPrev ()
- virtual bool fetchFirst () = 0
- virtual bool fetchLast () = 0
- virtual int size () = 0
- virtual int numRowsAffected () = 0

## Detailed Description

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

Normally you would use TQSqlQuery instead of TQSqlResult since TQSqlQuery provides a generic wrapper for database-specific implementations of TQSqlResult.

See also TQSql and Database Classes.

## Member Function Documentation

### TQSqlResult::TQSqlResult ( const TQSqlDriver * db )`[protected]`

Protected constructor which creates a TQSqlResult using database db. The object is initialized to an inactive state.

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

Destroys the object and frees any allocated resources.

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

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

### TQVariant TQSqlResult::data ( int i )`[pure virtual protected]`

Returns the data for field i (zero-based) as a TQVariant. 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 TQVariant() if it cannot be determined.

### const TQSqlDriver * TQSqlResult::driver () const`[protected]`

Returns the driver associated with the result.

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

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

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

Positions the result to the first record 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 TQSqlResult::fetchLast ()`[pure virtual protected]`

Positions the result to the last record 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 TQSqlResult::fetchNext ()`[virtual protected]`

Positions the result to the next available record 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 TQSqlResult::fetchPrev ()`[virtual protected]`

Positions the result to the previous available record 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 TQSqlResult::isActive () const`[protected]`

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

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

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

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

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

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

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

### bool TQSqlResult::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.

### TQSqlError TQSqlResult::lastError () const`[protected]`

Returns the last error associated with the result.

### TQString TQSqlResult::lastQuery () const`[protected]`

Returns the current SQL query text, or TQString::null if there is none.

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

Returns the number of rows affected by the last query executed.

### bool TQSqlResult::reset ( const TQString & 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 called only 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.

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

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

See also isActive().

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

Protected function provided for derived classes to set the internal (zero-based) result index to at.

See also at().

### void TQSqlResult::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 far less memory since results do not have to be cached. forward only mode is off by default.

See also fetchNext().

### void TQSqlResult::setLastError ( const TQSqlError & e )`[virtual protected]`

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

See also lastError().

### void TQSqlResult::setQuery ( const TQString & 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 TQSqlResult::setSelect ( bool s )`[virtual protected]`

Protected function 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, or false otherwise.

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

Returns the size of the result or -1 if it cannot be determined.

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.