Qt 4.8
Public Functions | Public Variables | List of all members
QSQLiteResultPrivate Class Reference

Public Functions

void cleanup ()
 
bool fetchNext (QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
 
void finalize ()
 
void initColumns (bool emptyResultset)
 
 QSQLiteResultPrivate (QSQLiteResult *res)
 

Public Variables

sqlite3 * access
 
QVector< QVariantfirstRow
 
QSQLiteResultq
 
QSqlRecord rInf
 
bool skippedStatus
 
bool skipRow
 
sqlite3_stmt * stmt
 

Detailed Description

Definition at line 112 of file qsql_sqlite.cpp.

Constructors and Destructors

◆ QSQLiteResultPrivate()

QSQLiteResultPrivate::QSQLiteResultPrivate ( QSQLiteResult res)

Definition at line 133 of file qsql_sqlite.cpp.

133  : q(res), access(0),
134  stmt(0), skippedStatus(false), skipRow(false)
135 {
136 }
QSQLiteResult * q
sqlite3_stmt * stmt

Functions

◆ cleanup()

void QSQLiteResultPrivate::cleanup ( )

Definition at line 138 of file qsql_sqlite.cpp.

Referenced by QSQLiteResult::prepare(), and QSQLiteResult::~QSQLiteResult().

139 {
140  finalize();
141  rInf.clear();
142  skippedStatus = false;
143  skipRow = false;
145  q->setActive(false);
146  q->cleanup();
147 }
QSQLiteResult * q
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
virtual void setActive(bool a)
This function is provided for derived classes to set the internal active state to active...
Definition: qsqlresult.cpp:402
void clear()
Removes all the record&#39;s fields.
Definition: qsqlrecord.cpp:367

◆ fetchNext()

bool QSQLiteResultPrivate::fetchNext ( QSqlCachedResult::ValueCache values,
int  idx,
bool  initialFetch 
)

Definition at line 209 of file qsql_sqlite.cpp.

Referenced by QSQLiteResult::exec(), and QSQLiteResult::gotoNext().

210 {
211  int res;
212  int i;
213 
214  if (skipRow) {
215  // already fetched
216  Q_ASSERT(!initialFetch);
217  skipRow = false;
218  for(int i=0;i<firstRow.count();i++)
219  values[i]=firstRow[i];
220  return skippedStatus;
221  }
222  skipRow = initialFetch;
223 
224  if(initialFetch) {
225  firstRow.clear();
226  firstRow.resize(sqlite3_column_count(stmt));
227  }
228 
229  if (!stmt) {
230  q->setLastError(QSqlError(QCoreApplication::translate("QSQLiteResult", "Unable to fetch row"),
231  QCoreApplication::translate("QSQLiteResult", "No query"), QSqlError::ConnectionError));
233  return false;
234  }
235  res = sqlite3_step(stmt);
236 
237  switch(res) {
238  case SQLITE_ROW:
239  // check to see if should fill out columns
240  if (rInf.isEmpty())
241  // must be first call.
242  initColumns(false);
243  if (idx < 0 && !initialFetch)
244  return true;
245  for (i = 0; i < rInf.count(); ++i) {
246  switch (sqlite3_column_type(stmt, i)) {
247  case SQLITE_BLOB:
248  values[i + idx] = QByteArray(static_cast<const char *>(
249  sqlite3_column_blob(stmt, i)),
250  sqlite3_column_bytes(stmt, i));
251  break;
252  case SQLITE_INTEGER:
253  values[i + idx] = sqlite3_column_int64(stmt, i);
254  break;
255  case SQLITE_FLOAT:
256  switch(q->numericalPrecisionPolicy()) {
258  values[i + idx] = sqlite3_column_int(stmt, i);
259  break;
261  values[i + idx] = sqlite3_column_int64(stmt, i);
262  break;
264  case QSql::HighPrecision:
265  default:
266  values[i + idx] = sqlite3_column_double(stmt, i);
267  break;
268  };
269  break;
270  case SQLITE_NULL:
271  values[i + idx] = QVariant(QVariant::String);
272  break;
273  default:
274  values[i + idx] = QString(reinterpret_cast<const QChar *>(
275  sqlite3_column_text16(stmt, i)),
276  sqlite3_column_bytes16(stmt, i) / sizeof(QChar));
277  break;
278  }
279  }
280  return true;
281  case SQLITE_DONE:
282  if (rInf.isEmpty())
283  // must be first call.
284  initColumns(true);
286  sqlite3_reset(stmt);
287  return false;
288  case SQLITE_CONSTRAINT:
289  case SQLITE_ERROR:
290  // SQLITE_ERROR is a generic error code and we must call sqlite3_reset()
291  // to get the specific error message.
292  res = sqlite3_reset(stmt);
294  "Unable to fetch row"), QSqlError::ConnectionError, res));
296  return false;
297  case SQLITE_MISUSE:
298  case SQLITE_BUSY:
299  default:
300  // something wrong, don't get col info, but still return false
302  "Unable to fetch row"), QSqlError::ConnectionError, res));
303  sqlite3_reset(stmt);
305  return false;
306  }
307  return false;
308 }
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
QVector< QVariant > firstRow
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::ErrorType type, int errorCode=-1)
Definition: qsql_sqlite.cpp:95
bool isEmpty() const
Returns true if there are no fields in the record; otherwise returns false.
Definition: qsqlrecord.cpp:380
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QSQLiteResult * q
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
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
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
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
int count() const
Returns the number of fields in the record.
Definition: qsqlrecord.cpp:573
sqlite3_stmt * stmt
void initColumns(bool emptyResultset)

◆ finalize()

void QSQLiteResultPrivate::finalize ( )

Definition at line 149 of file qsql_sqlite.cpp.

Referenced by cleanup(), QSQLiteDriver::close(), QSQLiteResult::exec(), and QSQLiteResult::prepare().

150 {
151  if (!stmt)
152  return;
153 
154  sqlite3_finalize(stmt);
155  stmt = 0;
156 }
sqlite3_stmt * stmt

◆ initColumns()

void QSQLiteResultPrivate::initColumns ( bool  emptyResultset)

Definition at line 158 of file qsql_sqlite.cpp.

Referenced by fetchNext().

159 {
160  int nCols = sqlite3_column_count(stmt);
161  if (nCols <= 0)
162  return;
163 
164  q->init(nCols);
165 
166  for (int i = 0; i < nCols; ++i) {
167  QString colName = QString(reinterpret_cast<const QChar *>(
168  sqlite3_column_name16(stmt, i))
169  ).remove(QLatin1Char('"'));
170 
171  // must use typeName for resolving the type to match QSqliteDriver::record
172  QString typeName = QString(reinterpret_cast<const QChar *>(
173  sqlite3_column_decltype16(stmt, i)));
174  // sqlite3_column_type is documented to have undefined behavior if the result set is empty
175  int stp = emptyResultset ? -1 : sqlite3_column_type(stmt, i);
176 
177  QVariant::Type fieldType;
178 
179  if (!typeName.isEmpty()) {
180  fieldType = qGetColumnType(typeName);
181  } else {
182  // Get the proper type for the field based on stp value
183  switch (stp) {
184  case SQLITE_INTEGER:
185  fieldType = QVariant::Int;
186  break;
187  case SQLITE_FLOAT:
188  fieldType = QVariant::Double;
189  break;
190  case SQLITE_BLOB:
191  fieldType = QVariant::ByteArray;
192  break;
193  case SQLITE_TEXT:
194  fieldType = QVariant::String;
195  break;
196  case SQLITE_NULL:
197  default:
198  fieldType = QVariant::Invalid;
199  break;
200  }
201  }
202 
203  QSqlField fld(colName, fieldType);
204  fld.setSqlType(stp);
205  rInf.append(fld);
206  }
207 }
static QVariant::Type qGetColumnType(const QString &tpName)
Definition: qsql_sqlite.cpp:78
The QString class provides a Unicode character string.
Definition: qstring.h:83
QSQLiteResult * q
const char * typeName
Definition: qmetatype.cpp:239
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
void append(const QSqlField &field)
Append a copy of field field to the end of the record.
Definition: qsqlrecord.cpp:312
sqlite3_stmt * stmt
void init(int colCount)
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Properties

◆ access

sqlite3* QSQLiteResultPrivate::access

◆ firstRow

QVector<QVariant> QSQLiteResultPrivate::firstRow

Definition at line 130 of file qsql_sqlite.cpp.

Referenced by QSQLiteResult::exec(), and fetchNext().

◆ q

QSQLiteResult* QSQLiteResultPrivate::q

Definition at line 122 of file qsql_sqlite.cpp.

Referenced by cleanup(), fetchNext(), and initColumns().

◆ rInf

QSqlRecord QSQLiteResultPrivate::rInf

◆ skippedStatus

bool QSQLiteResultPrivate::skippedStatus

Definition at line 127 of file qsql_sqlite.cpp.

Referenced by cleanup(), QSQLiteResult::exec(), and fetchNext().

◆ skipRow

bool QSQLiteResultPrivate::skipRow

Definition at line 128 of file qsql_sqlite.cpp.

Referenced by cleanup(), QSQLiteResult::exec(), and fetchNext().

◆ stmt

sqlite3_stmt* QSQLiteResultPrivate::stmt

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