Qt Jambi Home

com.trolltech.qt.sql
Class QSqlResult

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.sql.QSqlResult
All Implemented Interfaces:
QtJambiInterface

public abstract class QSqlResult
extends QtJambiObject

The QSqlResult class provides an abstract interface for accessing data from specific 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 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

Nested Class Summary
static class QSqlResult.BindingSyntax
          This enum type specifies the different syntaxes for specifying placeholders in prepared queries.
static class QSqlResult.VirtualHookOperation
          Press link for info on QSqlResult.VirtualHookOperation
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Constructor Summary
protected QSqlResult(QSqlDriver db)
          Creates a QSqlResult using database driver db.
 
Method Summary
protected  void addBindValue(java.lang.Object val, QSql.ParamType type)
          Binds the value val of parameter type type to the next available position in the current record (row).
protected  void addBindValue(java.lang.Object val, QSql.ParamTypeFlag... type)
          Binds the value val of parameter type type to the next available position in the current record (row).
protected  int at()
          Returns the current (zero-based) row position of the result.
protected  QSqlResult.BindingSyntax bindingSyntax()
          Returns the binding syntax used by prepared queries.
protected  void bindValue(int pos, java.lang.Object val, QSql.ParamType type)
          Binds the value val of parameter type type to position pos in the current record (row).
protected  void bindValue(int pos, java.lang.Object val, QSql.ParamTypeFlag... type)
          Binds the value val of parameter type type to position index.
protected  void bindValue(java.lang.String placeholder, java.lang.Object val, QSql.ParamType type)
          Binds the value val of parameter type type to the placeholder name in the current record (row).
protected  void bindValue(java.lang.String placeholder, java.lang.Object val, QSql.ParamTypeFlag... type)
          Binds the value val of parameter type Type to the placeholder name in the current record (row).
protected  QSql.ParamType bindValueType(int pos)
          Returns the parameter type for the value bound at position pos.
protected  QSql.ParamType bindValueType(java.lang.String placeholder)
          Returns the parameter type for the value bound with the given placeholder name.
protected  java.lang.Object boundValue(int pos)
          Returns the value bound at position pos in the current record (row).
protected  java.lang.Object boundValue(java.lang.String placeholder)
          Returns the value bound by the given placeholder name in the current record (row).
protected  int boundValueCount()
          Returns the number of bound values in the result.
protected  java.lang.String boundValueName(int pos)
          Returns the name of the bound value at position pos in the current record (row).
protected  java.util.List<java.lang.Object> boundValues()
          Returns a vector of the result's bound values for the current record (row).
protected  void clear()
          Clears the entire result set and releases any associated resources.
protected abstract  java.lang.Object data(int i)
          Returns the data for field i in the current row as a QVariant.
protected  void detachFromResultSet()
          
protected  QSqlDriver driver()
          Returns the driver associated with the result.
protected  boolean exec()
          Executes the query, returning true if successful; otherwise returns false.
protected  boolean execBatch()
          Equivalent to execBatch(false).
protected  boolean execBatch(boolean arrayBind)
          
protected  java.lang.String executedQuery()
          Returns the query that was actually executed.
protected abstract  boolean fetch(int i)
          Positions the result to an arbitrary (zero-based) row i.
protected abstract  boolean fetchFirst()
          Positions the result to the first record (row 0) in the result.
protected abstract  boolean fetchLast()
          Positions the result to the last record (last row) in the result.
protected  boolean fetchNext()
          Positions the result to the next available record (row) in the result.
protected  boolean fetchPrevious()
          Positions the result to the previous record (row) in the result.
static QSqlResult fromNativePointer(QNativePointer nativePointer)
          This function returns the QSqlResult instance pointed to by nativePointer
 java.lang.Object handle()
          Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVariant if there is no handle.
protected  boolean hasOutValues()
          Returns true if at least one of the query's bound values is a QSql::Out or a QSql::InOut; otherwise returns false.
protected  boolean isActive()
          Returns true if the result has records to be retrieved; otherwise returns false.
protected  boolean isForwardOnly()
          Returns true if you can only scroll forward through the result set; otherwise returns false.
protected abstract  boolean isNull(int i)
          Returns true if the field at position i in the current row is null; otherwise returns false.
protected  boolean isSelect()
          Returns true if the current result is from a SELECT statement; otherwise returns false.
protected  boolean isValid()
          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  QSqlError lastError()
          Returns the last error associated with the result.
protected  java.lang.Object lastInsertId()
          Returns the object ID of the most recent inserted row if the database supports it.
protected  java.lang.String lastQuery()
          Returns the current SQL query text, or an empty string if there isn't one.
protected abstract  int numRowsAffected()
          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.
protected  boolean prepare(java.lang.String query)
          Prepares the given query for execution; the query will normally use placeholders so that it can be executed repeatedly.
protected  QSqlRecord record()
          Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
protected abstract  boolean reset(java.lang.String sqlquery)
          Sets the result to use the SQL statement sqlquery for subsequent data retrieval.
protected  boolean savePrepare(java.lang.String sqlquery)
          Prepares the given sqlquery, using the underlying database functionality where possible.
protected  void setActive(boolean a)
          This function is provided for derived classes to set the internal active state to a.
protected  void setAt(int at)
          This function is provided for derived classes to set the internal (zero-based) row position to at.
protected  void setForwardOnly(boolean forward)
          Sets forward only mode to forward.
protected  void setLastError(QSqlError e)
          This function is provided for derived classes to set the last error to e.
protected  void setNumericalPrecisionPolicy(QSql.NumericalPrecisionPolicy policy)
          
protected  void setQuery(java.lang.String query)
          Sets the current query for the result to query.
protected  void setSelect(boolean s)
          This function is provided for derived classes to indicate whether or not the current statement is a SQL SELECT statement.
protected abstract  int size()
          Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELECT statement.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QSqlResult

protected QSqlResult(QSqlDriver db)

Creates a QSqlResult using database driver db. The object is initialized to an inactive state.

See Also:
isActive, driver
Method Detail

addBindValue

protected final void addBindValue(java.lang.Object val,
                                  QSql.ParamTypeFlag... type)

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

See Also:
bindValue

addBindValue

protected final void addBindValue(java.lang.Object val,
                                  QSql.ParamType type)

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

See Also:
bindValue

at

protected final int at()

Returns the current (zero-based) row position of the result. May return the special values QSql::BeforeFirstRow or QSql::AfterLastRow.

See Also:
setAt, isValid

bindValueType

protected final QSql.ParamType bindValueType(int pos)

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

See Also:
boundValue

bindValueType

protected final QSql.ParamType bindValueType(java.lang.String placeholder)

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


bindingSyntax

protected final QSqlResult.BindingSyntax bindingSyntax()

Returns the binding syntax used by prepared queries.


boundValue

protected final java.lang.Object boundValue(int pos)

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

See Also:
bindValue, boundValues

boundValue

protected final java.lang.Object boundValue(java.lang.String placeholder)

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

See Also:
bindValueType

boundValueCount

protected final int boundValueCount()

Returns the number of bound values in the result.

See Also:
boundValues

boundValueName

protected final java.lang.String boundValueName(int pos)

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

See Also:
boundValue

boundValues

protected final java.util.List<java.lang.Object> boundValues()

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

See Also:
boundValueCount

clear

protected final void clear()

Clears the entire result set and releases any associated resources.


detachFromResultSet

protected final void detachFromResultSet()


driver

protected final QSqlDriver driver()

Returns the driver associated with the result. This is the object that was passed to the constructor.


execBatch

protected final boolean execBatch()

Equivalent to execBatch(false).


execBatch

protected final boolean execBatch(boolean arrayBind)

See Also:
exec, QSqlDriver::hasFeature

executedQuery

protected final java.lang.String executedQuery()

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

hasOutValues

protected final boolean hasOutValues()

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

isActive

protected final boolean isActive()

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


isForwardOnly

protected final boolean isForwardOnly()

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

See Also:
setForwardOnly

isSelect

protected final boolean isSelect()

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

See Also:
setSelect

isValid

protected final boolean isValid()

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

lastError

protected final QSqlError lastError()

Returns the last error associated with the result.

See Also:
setLastError

lastQuery

protected final java.lang.String lastQuery()

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

See Also:
setQuery

setNumericalPrecisionPolicy

protected final void setNumericalPrecisionPolicy(QSql.NumericalPrecisionPolicy policy)


bindValue

protected final void bindValue(int pos,
                               java.lang.Object val,
                               QSql.ParamTypeFlag... type)
Binds the value val of parameter type type to position index. in the current record (row).


bindValue

protected void bindValue(int pos,
                         java.lang.Object val,
                         QSql.ParamType type)

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

See Also:
addBindValue

bindValue

protected final void bindValue(java.lang.String placeholder,
                               java.lang.Object val,
                               QSql.ParamTypeFlag... type)
Binds the value val of parameter type Type to the placeholder name in the current record (row).

Note that binding an undefined placeholder will result in undefined behavior.


bindValue

protected void bindValue(java.lang.String placeholder,
                         java.lang.Object val,
                         QSql.ParamType type)

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

Note that binding an undefined placeholder will result in undefined behavior.


data

protected abstract java.lang.Object data(int i)

Returns the data for field i 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 i is non-negative. Derived classes must reimplement this function and return the value of field i, or QVariant if it cannot be determined.


exec

protected boolean exec()

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

See Also:
prepare

fetch

protected abstract boolean fetch(int i)

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.

See Also:
isActive, fetchFirst, fetchLast, fetchNext, fetchPrevious

fetchFirst

protected abstract boolean fetchFirst()

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

fetchLast

protected abstract boolean fetchLast()

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

fetchNext

protected boolean fetchNext()

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

fetchPrevious

protected boolean fetchPrevious()

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.


handle

public java.lang.Object handle()

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.

Warning: The handle returned here can become a stale pointer if the result is modified (for example, if you clear it).

Warning: 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:

    QSqlQuery query = ...
    QVariant v = query.result()->handle();
    if (v.isValid() && qstrcmp(v.typeName(), "sqlite3_stmt*")) {
        // v.data() returns a pointer to the handle
        sqlite3_stmt *handle = *static_cast<sqlite3_stmt **>(v.data());
        if (handle != 0) { // check that it is not NULL
            ...
        }
    }

This snippet returns the handle for PostgreSQL or MySQL:

    if (v.typeName() == "PGresult*") {
        PGresult *handle = *static_cast<PGresult **>(v.data());
        if (handle != 0) ...
    }

    if (v.typeName() == "MYSQL_STMT*") {
        MYSQL_STMT *handle = *static_cast<MYSQL_STMT **>(v.data());
        if (handle != 0) ...
    }

See Also:
QSqlDriver::handle

isNull

protected abstract boolean isNull(int i)

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


lastInsertId

protected java.lang.Object lastInsertId()

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

numRowsAffected

protected abstract int numRowsAffected()

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

prepare

protected boolean prepare(java.lang.String query)

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

record

protected QSqlRecord record()

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

reset

protected abstract boolean reset(java.lang.String sqlquery)

Sets the result to use the SQL statement sqlquery for subsequent data retrieval.

Derived classes must reimplement this function and apply the sqlquery 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

savePrepare

protected boolean savePrepare(java.lang.String sqlquery)

Prepares the given sqlquery, using the underlying database functionality where possible. Returns true if the query is prepared successfully; otherwise returns false.

See Also:
prepare

setActive

protected void setActive(boolean a)

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

See Also:
isActive

setAt

protected void setAt(int at)

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

See Also:
at

setForwardOnly

protected void setForwardOnly(boolean forward)

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.

See Also:
isForwardOnly, fetchNext

setLastError

protected void setLastError(QSqlError e)

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

See Also:
lastError

setQuery

protected void setQuery(java.lang.String query)

Sets the current query for the result to query. You must call reset to execute the query on the database.

See Also:
reset, lastQuery

setSelect

protected void setSelect(boolean s)

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.

See Also:
isSelect

size

protected abstract int size()

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

fromNativePointer

public static QSqlResult fromNativePointer(QNativePointer nativePointer)
This function returns the QSqlResult instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

Qt Jambi Home