CopperSpice API
1.9.2
|
The QSqlResult class provides an abstract interface for accessing data from SQL databases. More...
Inherited by QSqlCachedResult, QSqlNullResult
Public Methods | |
virtual | ~QSqlResult () |
virtual QVariant | handle () const |
Protected Types | |
enum | BindingSyntax |
Protected Methods | |
QSqlResult (const QSqlDriver *db) | |
void | addBindValue (const QVariant &value, QSql::ParamType type) |
int | at () const |
BindingSyntax | bindingSyntax () const |
virtual void | bindValue (const QString &placeholder, const QVariant &value, QSql::ParamType type) |
virtual void | bindValue (int index, const QVariant &value, QSql::ParamType type) |
QSql::ParamType | bindValueType (const QString &placeholder) const |
QSql::ParamType | bindValueType (int index) const |
QVariant | boundValue (const QString &placeholder) const |
QVariant | boundValue (int index) const |
int | boundValueCount () const |
QString | boundValueName (int index) const |
QVector< QVariant > & | boundValues () const |
void | clear () |
virtual QVariant | data (int index) = 0 |
const QSqlDriver * | driver () const |
virtual bool | exec () |
QString | executedQuery () const |
virtual bool | fetch (int index) = 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 index) = 0 |
bool | isSelect () const |
bool | isValid () const |
QSqlError | lastError () const |
virtual QVariant | lastInsertId () 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 active) |
virtual void | setAt (int index) |
virtual void | setForwardOnly (bool forward) |
virtual void | setLastError (const QSqlError &error) |
virtual void | setQuery (const QString &query) |
virtual void | setSelect (bool select) |
virtual int | size () = 0 |
Friends | |
class | QSqlQuery |
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 by inheriting from QSqlDriver, provide your own QSqlResult subclass which overrides the pure virtual methods that you need.
|
protected |
This enum type specifies the different syntaxes for specifying placeholders in prepared queries.
Constant | Value | Description |
---|---|---|
QSqlResult::PositionalBinding | 0 | Use the ODBC-style positional syntax, with "?" as placeholders. |
QSqlResult::NamedBinding | 1 | Use the Oracle-style syntax with named placeholders (e.g., ":id") |
|
virtual |
Destroys the object and frees any allocated resources.
|
explicitprotected |
Creates a QSqlResult using the given database driver db. The object is initialized to an inactive state.
|
protected |
Binds the value of parameter type to the next available position in the current record (row).
|
protected |
|
protected |
Returns the binding syntax used by prepared queries.
|
protectedvirtual |
Binds the value parameter type to the placeholder name in the current record (row). Values can not be bound to multiple locations in the query.
Binding to name will bind to the first :name, but not the second.
|
protectedvirtual |
Binds the value of parameter type to position index in the current record (row).
|
protected |
Returns the parameter type for the value bound with the given placeholder name.
|
protected |
Returns the parameter type for the value bound at position index.
Returns the value bound by the given placeholder name in the current record (row).
|
protected |
Returns the value bound at position index in the current record (row).
|
protected |
Returns the number of bound values in the result.
|
protected |
Returns the name of the bound value at position index in the current record (row).
Returns a vector of the result's bound values for the current record (row).
|
protected |
Clears the entire result set and releases any associated resources.
|
protectedpure virtual |
Returns the data for field index in the current row as a QVariant. This method 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 can not be determined.
|
protected |
Returns the driver associated with the result. This is the object that was passed to the constructor.
|
protectedvirtual |
Executes the query and returns true if successful, otherwise returns false.
|
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 does not support prepared queries.
|
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.
|
protectedpure virtual |
Positions the result to the first record (row 0) in the result.
This method 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.
|
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.
|
protectedvirtual |
Positions the result to the next available record (row) in the result.
This method 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.
|
protectedvirtual |
Positions the result to the previous record (row) in the result.
This method 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.
|
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 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. 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 example returns the handle for PostgreSQL or MySQL.
|
protected |
Returns true if at least one of the query's bound values is a QSql::Out
or a QSql::InOut, otherwise returns false.
|
protected |
Returns true if the result has records to be retrieved, otherwise returns false.
|
protected |
Returns true if you can only scroll forward through the result set, otherwise returns false.
|
protectedpure virtual |
Returns true if the field at position index in the current row is null, otherwise returns false.
|
protected |
Returns true if the current result is from a SELECT
statement, otherwise returns false.
|
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.
|
protected |
Returns the last error associated with the result.
|
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.
|
protected |
Returns the current SQL query text, or an empty string if there is not one.
|
protectedpure virtual |
Returns the number of rows affected by the last query executed, or -1 if it can not be determined or if the query is a SELECT
statement.
|
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.
|
protectedvirtual |
Returns the current record if the query is active, otherwise returns an empty QSqlRecord.
The default implementation always returns an empty QSqlRecord.
|
protectedpure virtual |
Sets the result to use the SQL statement query for subsequent data retrieval.
Derived classes must reimplement this method and apply the sqlquery to the database. This method 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.
|
protectedvirtual |
Prepares the given query, using the underlying database functionality where possible. Returns true if the query is prepared successfully, otherwise returns false.
|
protectedvirtual |
This function is provided for derived classes to set the internal active state to active.
|
protectedvirtual |
This function is provided for derived classes to set the internal (zero-based) row position to index.
|
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.
|
protectedvirtual |
This method is provided for derived classes to set the last error to error.
|
protectedvirtual |
Sets the current query for the result to query. You must call reset() to execute the query on the database.
|
protectedvirtual |
This method 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.
|
protectedpure virtual |
Returns the size of the SELECT
result, or -1 if it can not be determined or if the query is not a SELECT
statement.