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

Public Functions

void cleanup ()
 
bool fetchNext (QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
 
void finalize ()
 
void init (const char **cnames, int numCols)
 
bool isSelect ()
 
 QSQLite2ResultPrivate (QSQLite2Result *res)
 

Public Variables

sqlite * access
 
sqlite_vmcurrentMachine
 
const char * currentTail
 
QVector< QVariantfirstRow
 
QSQLite2Resultq
 
QSqlRecord rInf
 
bool skippedStatus
 
bool skipRow
 
bool utf8
 

Detailed Description

Definition at line 94 of file qsql_sqlite2.cpp.

Constructors and Destructors

◆ QSQLite2ResultPrivate()

QSQLite2ResultPrivate::QSQLite2ResultPrivate ( QSQLite2Result res)

Definition at line 122 of file qsql_sqlite2.cpp.

122  : q(res), access(0), currentTail(0),
123  currentMachine(0), skippedStatus(false), skipRow(false), utf8(false)
124 {
125 }
sqlite_vm * currentMachine
const char * currentTail
QSQLite2Result * q

Functions

◆ cleanup()

void QSQLite2ResultPrivate::cleanup ( )

Definition at line 127 of file qsql_sqlite2.cpp.

Referenced by QSQLite2Result::reset(), and QSQLite2Result::~QSQLite2Result().

128 {
129  finalize();
130  rInf.clear();
131  currentTail = 0;
132  currentMachine = 0;
133  skippedStatus = false;
134  skipRow = false;
136  q->setActive(false);
137  q->cleanup();
138 }
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
sqlite_vm * currentMachine
const char * currentTail
QSQLite2Result * q
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 QSQLite2ResultPrivate::fetchNext ( QSqlCachedResult::ValueCache values,
int  idx,
bool  initialFetch 
)

Definition at line 183 of file qsql_sqlite2.cpp.

Referenced by QSQLite2Result::gotoNext(), and QSQLite2Result::reset().

184 {
185  // may be caching.
186  const char **fvals;
187  const char **cnames;
188  int colNum;
189  int res;
190  int i;
191 
192  if (skipRow) {
193  // already fetched
194  Q_ASSERT(!initialFetch);
195  skipRow = false;
196  for(int i=0;i<firstRow.count(); i++)
197  values[i] = firstRow[i];
198  return skippedStatus;
199  }
200  skipRow = initialFetch;
201 
202  if (!currentMachine)
203  return false;
204 
205  // keep trying while busy, wish I could implement this better.
206  while ((res = sqlite_step(currentMachine, &colNum, &fvals, &cnames)) == SQLITE_BUSY) {
207  // sleep instead requesting result again immidiately.
208 #if defined Q_WS_WIN32
209  Sleep(1000);
210 #else
211  sleep(1);
212 #endif
213  }
214 
215  if(initialFetch) {
216  firstRow.clear();
217  firstRow.resize(colNum);
218  }
219 
220  switch(res) {
221  case SQLITE_ROW:
222  // check to see if should fill out columns
223  if (rInf.isEmpty())
224  // must be first call.
225  init(cnames, colNum);
226  if (!fvals)
227  return false;
228  if (idx < 0 && !initialFetch)
229  return true;
230  for (i = 0; i < colNum; ++i)
231  values[i + idx] = utf8 ? QString::fromUtf8(fvals[i]) : QString::fromAscii(fvals[i]);
232  return true;
233  case SQLITE_DONE:
234  if (rInf.isEmpty())
235  // must be first call.
236  init(cnames, colNum);
238  return false;
239  case SQLITE_ERROR:
240  case SQLITE_MISUSE:
241  default:
242  // something wrong, don't get col info, but still return false
243  finalize(); // finalize to get the error message.
245  return false;
246  }
247  return false;
248 }
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
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< QVariant > firstRow
bool isEmpty() const
Returns true if there are no fields in the record; otherwise returns false.
Definition: qsqlrecord.cpp:380
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
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
sqlite_vm * currentMachine
QSQLite2Result * q
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
void init(const char **cnames, int numCols)

◆ finalize()

void QSQLite2ResultPrivate::finalize ( )

Definition at line 140 of file qsql_sqlite2.cpp.

Referenced by cleanup(), fetchNext(), and QSQLite2Result::virtual_hook().

141 {
142  if (!currentMachine)
143  return;
144 
145  char* err = 0;
146  int res = sqlite_finalize(currentMachine, &err);
147  if (err) {
149  "Unable to fetch results"), QString::fromAscii(err),
151  sqlite_freemem(err);
152  }
153  currentMachine = 0;
154 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
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
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
QSQLite2Result * q

◆ init()

void QSQLite2ResultPrivate::init ( const char **  cnames,
int  numCols 
)

Definition at line 157 of file qsql_sqlite2.cpp.

Referenced by fetchNext().

158 {
159  if (!cnames)
160  return;
161 
162  rInf.clear();
163  if (numCols <= 0)
164  return;
165  q->init(numCols);
166 
167  for (int i = 0; i < numCols; ++i) {
168  const char* lastDot = strrchr(cnames[i], '.');
169  const char* fieldName = lastDot ? lastDot + 1 : cnames[i];
170 
171  //remove quotations around the field name if any
172  QString fieldStr = QString::fromAscii(fieldName);
173  QLatin1Char quote('\"');
174  if ( fieldStr.length() > 2 && fieldStr.startsWith(quote) && fieldStr.endsWith(quote)) {
175  fieldStr = fieldStr.mid(1);
176  fieldStr.chop(1);
177  }
178  rInf.append(QSqlField(fieldStr,
179  nameToType(QString::fromAscii(cnames[i+numCols]))));
180  }
181 }
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
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
The QString class provides a Unicode character string.
Definition: qstring.h:83
QSQLite2Result * q
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
static QVariant::Type nameToType(const QString &typeName)
void append(const QSqlField &field)
Append a copy of field field to the end of the record.
Definition: qsqlrecord.cpp:312
void clear()
Removes all the record&#39;s fields.
Definition: qsqlrecord.cpp:367
void init(int colCount)
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isSelect()

bool QSQLite2ResultPrivate::isSelect ( )

Properties

◆ access

sqlite* QSQLite2ResultPrivate::access

◆ currentMachine

sqlite_vm* QSQLite2ResultPrivate::currentMachine

◆ currentTail

const char* QSQLite2ResultPrivate::currentTail

Definition at line 110 of file qsql_sqlite2.cpp.

Referenced by cleanup(), and QSQLite2Result::reset().

◆ firstRow

QVector<QVariant> QSQLite2ResultPrivate::firstRow

Definition at line 117 of file qsql_sqlite2.cpp.

Referenced by fetchNext(), and QSQLite2Result::reset().

◆ q

QSQLite2Result* QSQLite2ResultPrivate::q

Definition at line 105 of file qsql_sqlite2.cpp.

Referenced by cleanup(), fetchNext(), finalize(), and init().

◆ rInf

QSqlRecord QSQLite2ResultPrivate::rInf

◆ skippedStatus

bool QSQLite2ResultPrivate::skippedStatus

Definition at line 113 of file qsql_sqlite2.cpp.

Referenced by cleanup(), fetchNext(), and QSQLite2Result::reset().

◆ skipRow

bool QSQLite2ResultPrivate::skipRow

Definition at line 114 of file qsql_sqlite2.cpp.

Referenced by cleanup(), and fetchNext().

◆ utf8

bool QSQLite2ResultPrivate::utf8

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