Qt 4.8
Public Functions | Protected Functions | Properties | Friends | List of all members
QSQLite2Result Class Reference

#include <qsql_sqlite2.h>

Inheritance diagram for QSQLite2Result:
QSqlCachedResult QSqlResult

Public Functions

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. More...
 
 QSQLite2Result (const QSQLite2Driver *db)
 
 ~QSQLite2Result ()
 
- Public Functions inherited from QSqlCachedResult
virtual ~QSqlCachedResult ()
 
- Public Functions inherited from QSqlResult
virtual ~QSqlResult ()
 Destroys the object and frees any allocated resources. More...
 

Protected Functions

bool gotoNext (QSqlCachedResult::ValueCache &row, int idx)
 
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. More...
 
QSqlRecord record () const
 Returns the current record if the query is active; otherwise returns an empty QSqlRecord. More...
 
bool reset (const QString &query)
 Sets the result to use the SQL statement query for subsequent data retrieval. More...
 
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. More...
 
void virtual_hook (int id, void *data)
 
- Protected Functions inherited from QSqlCachedResult
ValueCachecache ()
 
void cleanup ()
 
void clearValues ()
 
int colCount () const
 
QVariant data (int i)
 Returns the data for field index in the current row as a QVariant. More...
 
bool fetch (int i)
 Positions the result to an arbitrary (zero-based) row index. More...
 
bool fetchFirst ()
 Positions the result to the first record (row 0) in the result. More...
 
bool fetchLast ()
 Positions the result to the last record (last row) in the result. More...
 
bool fetchNext ()
 Positions the result to the next available record (row) in the result. More...
 
bool fetchPrevious ()
 Positions the result to the previous record (row) in the result. More...
 
void init (int colCount)
 
bool isNull (int i)
 Returns true if the field at position index in the current row is null; otherwise returns false. More...
 
 QSqlCachedResult (const QSqlDriver *db)
 
void virtual_hook (int id, void *data)
 
- Protected Functions inherited from QSqlResult
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). More...
 
int at () const
 Returns the current (zero-based) row position of the result. More...
 
BindingSyntax bindingSyntax () const
 Returns the binding syntax used by prepared queries. More...
 
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). More...
 
virtual void bindValue (const QString &placeholder, const QVariant &val, QSql::ParamType type)
 Binds the value val of parameter type paramType to the placeholder name in the current record (row). More...
 
QSql::ParamType bindValueType (const QString &placeholder) const
 Returns the parameter type for the value bound with the given placeholder name. More...
 
QSql::ParamType bindValueType (int pos) const
 Returns the parameter type for the value bound at position index. More...
 
QVariant boundValue (const QString &placeholder) const
 Returns the value bound by the given placeholder name in the current record (row). More...
 
QVariant boundValue (int pos) const
 Returns the value bound at position index in the current record (row). More...
 
int boundValueCount () const
 Returns the number of bound values in the result. More...
 
QString boundValueName (int pos) const
 Returns the name of the bound value at position index in the current record (row). More...
 
QVector< QVariant > & boundValues () const
 Returns a vector of the result's bound values for the current record (row). More...
 
void clear ()
 Clears the entire result set and releases any associated resources. More...
 
void detachFromResultSet ()
 
const QSqlDriverdriver () const
 Returns the driver associated with the result. More...
 
virtual bool exec ()
 Executes the query, returning true if successful; otherwise returns false. More...
 
bool execBatch (bool arrayBind=false)
 Executes a prepared query in batch mode if the driver supports it, otherwise emulates a batch execution using bindValue() and exec(). More...
 
QString executedQuery () const
 Returns the query that was actually executed. More...
 
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. More...
 
bool isActive () const
 Returns true if the result has records to be retrieved; otherwise returns false. More...
 
bool isForwardOnly () const
 Returns true if you can only scroll forward through the result set; otherwise returns false. More...
 
bool isSelect () const
 Returns true if the current result is from a SELECT statement; otherwise returns false. More...
 
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. More...
 
QSqlError lastError () const
 Returns the last error associated with the result. More...
 
virtual QVariant lastInsertId () const
 Returns the object ID of the most recent inserted row if the database supports it. More...
 
QString lastQuery () const
 Returns the current SQL query text, or an empty string if there isn't one. More...
 
bool nextResult ()
 
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy () const
 
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. More...
 
 QSqlResult (const QSqlDriver *db)
 Creates a QSqlResult using database driver db. More...
 
virtual bool savePrepare (const QString &sqlquery)
 Prepares the given query, using the underlying database functionality where possible. More...
 
virtual void setActive (bool a)
 This function is provided for derived classes to set the internal active state to active. More...
 
virtual void setAt (int at)
 This function is provided for derived classes to set the internal (zero-based) row position to index. More...
 
virtual void setForwardOnly (bool forward)
 Sets forward only mode to forward. More...
 
virtual void setLastError (const QSqlError &e)
 This function is provided for derived classes to set the last error to error. More...
 
void setNumericalPrecisionPolicy (QSql::NumericalPrecisionPolicy policy)
 
virtual void setQuery (const QString &query)
 Sets the current query for the result to query. More...
 
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. More...
 

Properties

QSQLite2ResultPrivated
 

Friends

class QSQLite2Driver
 
class QSQLite2ResultPrivate
 

Additional Inherited Members

- Public Types inherited from QSqlCachedResult
typedef QVector< QVariantValueCache
 
- Protected Types inherited from QSqlResult
enum  BindingSyntax { PositionalBinding, NamedBinding }
 This enum type specifies the different syntaxes for specifying placeholders in prepared queries. More...
 
enum  VirtualHookOperation { BatchOperation, DetachFromResultSet, SetNumericalPrecision, NextResult }
 

Detailed Description

Definition at line 65 of file qsql_sqlite2.h.

Constructors and Destructors

◆ QSQLite2Result()

QSQLite2Result::QSQLite2Result ( const QSQLite2Driver db)
explicit

Definition at line 250 of file qsql_sqlite2.cpp.

251 : QSqlCachedResult(db)
252 {
253  d = new QSQLite2ResultPrivate(this);
254  d->access = db->d->access;
255  d->utf8 = db->d->utf8;
256 }
friend class QSQLite2ResultPrivate
Definition: qsql_sqlite2.h:68
QSQLite2ResultPrivate * d
Definition: qsql_sqlite2.h:83
QSqlCachedResult(const QSqlDriver *db)
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119

◆ ~QSQLite2Result()

QSQLite2Result::~QSQLite2Result ( )

Definition at line 258 of file qsql_sqlite2.cpp.

259 {
260  d->cleanup();
261  delete d;
262 }
QSQLite2ResultPrivate * d
Definition: qsql_sqlite2.h:83

Functions

◆ gotoNext()

bool QSQLite2Result::gotoNext ( QSqlCachedResult::ValueCache row,
int  idx 
)
protectedvirtual

Implements QSqlCachedResult.

Definition at line 321 of file qsql_sqlite2.cpp.

322 {
323  return d->fetchNext(row, idx, false);
324 }
bool fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
QSQLite2ResultPrivate * d
Definition: qsql_sqlite2.h:83

◆ handle()

QVariant QSQLite2Result::handle ( ) const
virtual

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

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

Reimplemented from QSqlResult.

Definition at line 343 of file qsql_sqlite2.cpp.

Referenced by QSQLite2Driver::open().

344 {
346 }
sqlite_vm * currentMachine
QSQLite2ResultPrivate * d
Definition: qsql_sqlite2.h:83
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336

◆ numRowsAffected()

int QSQLite2Result::numRowsAffected ( )
protectedvirtual

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

Implements QSqlResult.

Definition at line 331 of file qsql_sqlite2.cpp.

332 {
333  return sqlite_changes(d->access);
334 }
QSQLite2ResultPrivate * d
Definition: qsql_sqlite2.h:83

◆ record()

QSqlRecord QSQLite2Result::record ( ) const
protectedvirtual

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

Reimplemented from QSqlResult.

Definition at line 336 of file qsql_sqlite2.cpp.

Referenced by QSQLite2Driver::open().

337 {
338  if (!isActive() || !isSelect())
339  return QSqlRecord();
340  return d->rInf;
341 }
bool isActive() const
Returns true if the result has records to be retrieved; otherwise returns false.
Definition: qsqlresult.cpp:340
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
QSQLite2ResultPrivate * d
Definition: qsql_sqlite2.h:83
bool isSelect() const
Returns true if the current result is from a SELECT statement; otherwise returns false.
Definition: qsqlresult.cpp:379

◆ reset()

bool QSQLite2Result::reset ( const QString query)
protectedvirtual

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.

See also
setQuery()

Implements QSqlResult.

Definition at line 278 of file qsql_sqlite2.cpp.

279 {
280  // this is where we build a query.
281  if (!driver())
282  return false;
283  if (!driver()-> isOpen() || driver()->isOpenError())
284  return false;
285 
286  d->cleanup();
287 
288  // Um, ok. callback based so.... pass private static function for this.
289  setSelect(false);
290  char *err = 0;
291  int res = sqlite_compile(d->access,
292  d->utf8 ? query.toUtf8().constData()
293  : query.toAscii().constData(),
294  &(d->currentTail),
295  &(d->currentMachine),
296  &err);
297  if (res != SQLITE_OK || err) {
299  "Unable to execute statement"), QString::fromAscii(err),
301  sqlite_freemem(err);
302  }
303  //if (*d->currentTail != '\000' then there is more sql to eval
304  if (!d->currentMachine) {
305  setActive(false);
306  return false;
307  }
308  // we have to fetch one row to find out about
309  // the structure of the result set
310  d->skippedStatus = d->fetchNext(d->firstRow, 0, true);
311  if (lastError().isValid()) {
312  setSelect(false);
313  setActive(false);
314  return false;
315  }
316  setSelect(!d->rInf.isEmpty());
317  setActive(true);
318  return true;
319 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
const QSqlDriver * driver() const
Returns the driver associated with the result.
Definition: qsqlresult.cpp:389
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QVector< QVariant > firstRow
bool isEmpty() const
Returns true if there are no fields in the record; otherwise returns false.
Definition: qsqlrecord.cpp:380
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
virtual void setLastError(const QSqlError &e)
This function is provided for derived classes to set the last error to error.
Definition: qsqlresult.cpp:417
sqlite_vm * currentMachine
const char * currentTail
bool fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
virtual void setSelect(bool s)
This function is provided for derived classes to indicate whether or not the current statement is a S...
Definition: qsqlresult.cpp:367
QSQLite2ResultPrivate * d
Definition: qsql_sqlite2.h:83
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
QSqlError lastError() const
Returns the last error associated with the result.
Definition: qsqlresult.cpp:427
virtual void setActive(bool a)
This function is provided for derived classes to set the internal active state to active...
Definition: qsqlresult.cpp:402
bool isValid() const
Returns true if the result is positioned on a valid record (that is, the result is not positioned bef...
Definition: qsqlresult.cpp:320

◆ size()

int QSQLite2Result::size ( )
protectedvirtual

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

Implements QSqlResult.

Definition at line 326 of file qsql_sqlite2.cpp.

327 {
328  return -1;
329 }

◆ virtual_hook()

void QSQLite2Result::virtual_hook ( int  id,
void *  data 
)
protectedvirtual
Warning
This function is not part of the public interface.

Reimplemented from QSqlResult.

Definition at line 264 of file qsql_sqlite2.cpp.

265 {
266  switch (id) {
268  d->finalize();
269  break;
270  default:
272  }
273 }
QVariant data(int i)
Returns the data for field index in the current row as a QVariant.
QSQLite2ResultPrivate * d
Definition: qsql_sqlite2.h:83
void virtual_hook(int id, void *data)

Friends and Related Functions

◆ QSQLite2Driver

friend class QSQLite2Driver
friend

Definition at line 67 of file qsql_sqlite2.h.

◆ QSQLite2ResultPrivate

Definition at line 68 of file qsql_sqlite2.h.

Referenced by QSQLite2Result().

Properties

◆ d

QSQLite2ResultPrivate* QSQLite2Result::d
private

The documentation for this class was generated from the following files: