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

#include <qsql_symsql.h>

Inheritance diagram for QSymSQLResult:
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...
 
 QSymSQLResult (const QSymSQLDriver *db)
 
 ~QSymSQLResult ()
 
- Public Functions inherited from QSqlResult
virtual ~QSqlResult ()
 Destroys the object and frees any allocated resources. More...
 

Protected Functions

QVariant data (int field)
 Returns the data for field index in the current row as a QVariant. More...
 
bool exec ()
 Executes the query, returning true if successful; otherwise returns false. 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...
 
bool isNull (int i)
 Returns true if the field at position index in the current row is null; otherwise returns false. More...
 
QVariant lastInsertId () const
 Returns the object ID of the most recent inserted row if the database supports it. More...
 
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...
 
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...
 
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 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...
 
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...
 
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
 
 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

QSymSQLResultPrivated
 

Friends

class QSymSQLDriver
 
class QSymSQLResultPrivate
 

Additional Inherited Members

- 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_symsql.h.

Constructors and Destructors

◆ QSymSQLResult()

QSymSQLResult::QSymSQLResult ( const QSymSQLDriver db)
explicit

Definition at line 297 of file qsql_symsql.cpp.

298  : QSqlResult(db)
299 {
300  d = new QSymSQLResultPrivate(this);
301  d->access = db->d->access;
302 }
QSqlResult(const QSqlDriver *db)
Creates a QSqlResult using database driver db.
Definition: qsqlresult.cpp:257
QSymSQLDriverPrivate * d
Definition: qsql_symsql.h:125
friend class QSymSQLResultPrivate
Definition: qsql_symsql.h:68
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94

◆ ~QSymSQLResult()

QSymSQLResult::~QSymSQLResult ( )

Definition at line 305 of file qsql_symsql.cpp.

306 {
307  d->cleanup();
308  delete d;
309 }
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94

Functions

◆ data()

QVariant QSymSQLResult::data ( int  index)
protectedvirtual

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

Implements QSqlResult.

Definition at line 500 of file qsql_symsql.cpp.

Referenced by exec().

501 {
502  QVariant r;
503 
504  switch (d->stmt.ColumnType(idx)) {
505  case ESqlBinary:
506  {
507  TPtrC8 data;
508  d->stmt.ColumnBinary(idx, data);
509  return QByteArray(reinterpret_cast<const char *>(data.Ptr()), data.Length());
510  break;
511  }
512  case ESqlInt:
513  r = QVariant(d->stmt.ColumnInt(idx));
514  break;
515  case ESqlInt64:
516  r = QVariant(d->stmt.ColumnInt64(idx));
517  break;
518  case ESqlReal:
519  switch(numericalPrecisionPolicy()) {
521  r = QVariant(d->stmt.ColumnInt(idx));
522  break;
524  r = QVariant(d->stmt.ColumnInt64(idx));
525  break;
527  r = QVariant(d->stmt.ColumnReal(idx));
528  break;
529  case QSql::HighPrecision:
530  default:
531  TPtrC res;
532  d->stmt.ColumnText(idx, res);
533  r = QVariant(qt_TDesC2QString(res));
534  break;
535  };
536  break;
537  case ESqlNull:
539  break;
540  default:
541  TPtrC res;
542  d->stmt.ColumnText(idx, res);
543  r = QVariant(qt_TDesC2QString(res));
544  break;
545  }
546 
547  return r;
548 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const
QVariant data(int field)
Returns the data for field index in the current row as a QVariant.
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94
RSqlStatement stmt

◆ exec()

bool QSymSQLResult::exec ( )
protectedvirtual

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

See also
prepare()

Reimplemented from QSqlResult.

Definition at line 341 of file qsql_symsql.cpp.

Referenced by reset().

342 {
343  if (d->prepareCalled == false) {
345  "Statement is not prepared"), QSqlError::StatementError, KErrGeneral));
346  return false;
347  }
348 
350 
351  d->skippedStatus = false;
352  d->skipRow = false;
355  int res = d->stmt.Reset();
356 
357  if (res != KErrNone) {
359  "Unable to reset statement"), QSqlError::StatementError, res));
360  d->finalize();
361  return false;
362  }
363  TPtrC tmp;
364  TInt paramCount = 0;
365  while (d->stmt.ParamName(paramCount, tmp) == KErrNone)
366  paramCount++;
367 
368  if (paramCount == values.count()) {
369  for (int i = 0; i < paramCount; ++i) {
370  res = KErrNone;
371  const QVariant value = values.at(i);
372 
373  if (value.isNull()) {
374  res = d->stmt.BindNull(i); //replaced i + 1 with i
375  } else {
376  switch (value.type()) {
377  case QVariant::ByteArray: {
378  const QByteArray *ba = static_cast<const QByteArray*>(value.constData());
379  TPtrC8 data(reinterpret_cast<const TUint8 *>(ba->constData()), ba->length());
380  res = d->stmt.BindBinary(i, data); //replaced i + 1 with i
381  break; }
382  case QVariant::Int:
383  res = d->stmt.BindInt(i, value.toInt()); //replaced i + 1 with i
384  break;
385  case QVariant::Double:
386  res = d->stmt.BindReal(i, value.toDouble()); //replaced i + 1 with i
387 
388  break;
389  case QVariant::UInt:
390  case QVariant::LongLong:
391  res = d->stmt.BindReal(i, value.toLongLong()); //replaced i + 1 with i
392  break;
393 
394  case QVariant::String: {
395  // lifetime of string == lifetime of its qvariant
396  const QString *str = static_cast<const QString*>(value.constData());
397  res = d->stmt.BindText(i, qt_QString2TPtrC(*str)); // replaced i + 1 with i
398  break; }
399  default: {
400  QString str = value.toString();
401  res = d->stmt.BindText(i, qt_QString2TPtrC(str)); //replaced i + 1 with i
402  break; }
403  }
404  }
405  if (res != KErrNone) {
407  "Unable to bind parameters"), QSqlError::StatementError, res));
408  d->finalize();
409  return false;
410  }
411  }
412  } else {
414  "Parameter count mismatch"), QString(), QSqlError::StatementError));
415  return false;
416  }
417 
418  d->skippedStatus = d->fetchNext(true);
419 
420  if (lastError().isValid()) {
421  setSelect(false);
422  setActive(false);
423  return false;
424  }
425 
426  if (d->stmt.ColumnCount() > 0) {
427  //If there is something, it has to be select
428  setSelect(true);
429  } else {
430  //If there isn't it might be just bad query, let's check manually whether we can find SELECT
431  QString query = this->lastQuery();
432  query = query.trimmed();
433  query = query.toLower();
434 
435  //Just check whether there is one in the beginning, don't know if this is enough
436  //Comments should be at the end of line if those are passed
437  //For some reason, case insensitive indexOf didn't work for me
438  if (query.indexOf(QLatin1String("select")) == 0) {
439  setSelect(true);
440  } else {
441  setSelect(false);
442  }
443  }
444 
445  setActive(true);
446  return true;
447 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool fetchNext(bool initialFetch)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString lastQuery() const
Returns the current SQL query text, or an empty string if there isn&#39;t one.
Definition: qsqlresult.cpp:294
virtual void setAt(int at)
This function is provided for derived classes to set the internal (zero-based) row position to index...
Definition: qsqlresult.cpp:352
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
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
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
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
quint16 values[128]
QVariant data(int field)
Returns the data for field index in the current row as a QVariant.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static QSqlError qMakeError(RSqlDatabase &access, const QString &descr, QSqlError::ErrorType type, int errorCode=-1)
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
const void * constData() const
Definition: qvariant.cpp:3065
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94
QSqlError lastError() const
Returns the last error associated with the result.
Definition: qsqlresult.cpp:427
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
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
QVector< QVariant > & boundValues() const
Returns a vector of the result&#39;s bound values for the current record (row).
Definition: qsqlresult.cpp:859
RSqlStatement stmt

◆ fetch()

bool QSymSQLResult::fetch ( int  index)
protectedvirtual

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.

See also
isActive(), fetchFirst(), fetchLast(), fetchNext(), fetchPrevious()

Implements QSqlResult.

Definition at line 555 of file qsql_symsql.cpp.

Referenced by fetchFirst().

556 {
557  //Single return point modified according to review
558  bool retVal = true;
559 
560  if (i < 0 || !isActive()) {
561  retVal = false;
562  } else {
563  if (at() <= -1 || i < at()) {
564  d->stmt.Reset();
565  setAt(-1);
566  d->skipRow = false;
567  }
568 
569  while (at() < i) {
570  if (!d->fetchNext(false)) {
571  retVal = false;
572  break;
573  }
574 
575  setAt(at() + 1);
576  }
577  }
578 
579  return retVal;
580 }
bool isActive() const
Returns true if the result has records to be retrieved; otherwise returns false.
Definition: qsqlresult.cpp:340
bool fetchNext(bool initialFetch)
int at() const
Returns the current (zero-based) row position of the result.
Definition: qsqlresult.cpp:306
virtual void setAt(int at)
This function is provided for derived classes to set the internal (zero-based) row position to index...
Definition: qsqlresult.cpp:352
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94
RSqlStatement stmt

◆ fetchFirst()

bool QSymSQLResult::fetchFirst ( )
protectedvirtual

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

Implements QSqlResult.

Definition at line 597 of file qsql_symsql.cpp.

Referenced by fetchLast().

598 {
599  return fetch(0);
600 }
bool fetch(int i)
Positions the result to an arbitrary (zero-based) row index.

◆ fetchLast()

bool QSymSQLResult::fetchLast ( )
protectedvirtual

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

Implements QSqlResult.

Definition at line 602 of file qsql_symsql.cpp.

603 {
604  if (!isActive())
605  return false;
606 
607  if (at() <= -1) {
608  if (!fetchFirst())
609  return false;
610  }
611 
612  TInt res;
613 
614  do {
615  res = d->stmt.Next();
616  setAt(at()+1);
617  } while (res == KSqlAtRow);
618 
619  if (res != KSqlAtEnd)
620  return false;
621 
622  d->skippedStatus = false;
623  d->skipRow = false;
624 
625  return fetchPrevious();
626 }
bool isActive() const
Returns true if the result has records to be retrieved; otherwise returns false.
Definition: qsqlresult.cpp:340
int at() const
Returns the current (zero-based) row position of the result.
Definition: qsqlresult.cpp:306
virtual void setAt(int at)
This function is provided for derived classes to set the internal (zero-based) row position to index...
Definition: qsqlresult.cpp:352
bool fetchFirst()
Positions the result to the first record (row 0) in the result.
bool fetchPrevious()
Positions the result to the previous record (row) in the result.
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94
RSqlStatement stmt

◆ fetchNext()

bool QSymSQLResult::fetchNext ( )
protectedvirtual

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

Reimplemented from QSqlResult.

Definition at line 582 of file qsql_symsql.cpp.

583 {
584  bool res = d->fetchNext(false);
585  if (res) {
586  setAt(at()+1);
587  }
588 
589  return res;
590 }
bool fetchNext(bool initialFetch)
int at() const
Returns the current (zero-based) row position of the result.
Definition: qsqlresult.cpp:306
virtual void setAt(int at)
This function is provided for derived classes to set the internal (zero-based) row position to index...
Definition: qsqlresult.cpp:352
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94

◆ fetchPrevious()

bool QSymSQLResult::fetchPrevious ( )
protectedvirtual

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.

Reimplemented from QSqlResult.

Definition at line 592 of file qsql_symsql.cpp.

Referenced by fetchLast().

593 {
594  return QSqlResult::fetchPrevious();
595 }
virtual bool fetchPrevious()
Positions the result to the previous record (row) in the result.
Definition: qsqlresult.cpp:571

◆ handle()

QVariant QSymSQLResult::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 482 of file qsql_symsql.cpp.

483 {
484  return qVariantFromValue(d->stmt);
485 }
QVariant qVariantFromValue(const T &)
Definition: qvariant.h:451
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94
RSqlStatement stmt

◆ isNull()

bool QSymSQLResult::isNull ( int  i)
protectedvirtual

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

Implements QSqlResult.

Definition at line 550 of file qsql_symsql.cpp.

551 {
552  return d->stmt.IsNull(i);
553 }
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94
RSqlStatement stmt

◆ lastInsertId()

QVariant QSymSQLResult::lastInsertId ( ) const
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.

See also
QSqlDriver::hasFeature()

Reimplemented from QSqlResult.

Definition at line 460 of file qsql_symsql.cpp.

461 {
462  if (isActive()) {
463  qint64 id = static_cast<qint64>(d->access.LastInsertedRowId());
464  if (id)
465  return id;
466  }
467 
468  return QVariant();
469 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool isActive() const
Returns true if the result has records to be retrieved; otherwise returns false.
Definition: qsqlresult.cpp:340
__int64 qint64
Definition: qglobal.h:942
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94

◆ numRowsAffected()

int QSymSQLResult::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 455 of file qsql_symsql.cpp.

456 {
457  return -1;
458 }

◆ prepare()

bool QSymSQLResult::prepare ( const QString query)
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.

See also
exec()

Reimplemented from QSqlResult.

Definition at line 319 of file qsql_symsql.cpp.

Referenced by reset().

320 {
321  if (!driver() || !driver()->isOpen() || driver()->isOpenError())
322  return false;
323 
324  d->cleanup();
325  setSelect(false);
326 
327  TInt res = d->stmt.Prepare(d->access, qt_QString2TPtrC(query));
328 
329  if (res != KErrNone) {
331  "Unable to execute statement"), QSqlError::StatementError, res));
332  d->finalize();
333  return false;
334  }
335 
336  d->prepareCalled = true;
337 
338  return true;
339 }
const QSqlDriver * driver() const
Returns the driver associated with the result.
Definition: qsqlresult.cpp:389
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
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
static QSqlError qMakeError(RSqlDatabase &access, const QString &descr, QSqlError::ErrorType type, int errorCode=-1)
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94
RSqlStatement stmt

◆ record()

QSqlRecord QSymSQLResult::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 471 of file qsql_symsql.cpp.

472 {
473  if (!isActive() || !isSelect())
474  return QSqlRecord();
475 
476  QSqlRecord res;
477  d->initColumns(res);
478 
479  return res;
480 }
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
void initColumns(QSqlRecord &rec)
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94
bool isSelect() const
Returns true if the current result is from a SELECT statement; otherwise returns false.
Definition: qsqlresult.cpp:379

◆ reset()

bool QSymSQLResult::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 311 of file qsql_symsql.cpp.

312 {
313  if (!prepare(query))
314  return false;
315 
316  return exec();
317 }
bool exec()
Executes the query, returning true if successful; otherwise returns false.
bool prepare(const QString &query)
Prepares the given query for execution; the query will normally use placeholders so that it can be ex...

◆ size()

int QSymSQLResult::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 450 of file qsql_symsql.cpp.

451 {
452  return -1;
453 }

◆ virtual_hook()

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

Reimplemented from QSqlResult.

Definition at line 488 of file qsql_symsql.cpp.

489 {
490  switch (id)
491  {
493  d->stmt.Reset();
494  break;
495  default:
497  }
498 }
virtual void virtual_hook(int id, void *data)
Definition: qsqlresult.cpp:962
QVariant data(int field)
Returns the data for field index in the current row as a QVariant.
QSymSQLResultPrivate * d
Definition: qsql_symsql.h:94
RSqlStatement stmt

Friends and Related Functions

◆ QSymSQLDriver

friend class QSymSQLDriver
friend

Definition at line 67 of file qsql_symsql.h.

◆ QSymSQLResultPrivate

friend class QSymSQLResultPrivate
friend

Definition at line 68 of file qsql_symsql.h.

Referenced by QSymSQLResult().

Properties

◆ d

QSymSQLResultPrivate* QSymSQLResult::d
private

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