Qt 4.8
qsql_sqlite2.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSql module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qsql_sqlite2.h"
43 
44 #include <qcoreapplication.h>
45 #include <qvariant.h>
46 #include <qdatetime.h>
47 #include <qfile.h>
48 #include <qregexp.h>
49 #include <qsqlerror.h>
50 #include <qsqlfield.h>
51 #include <qsqlindex.h>
52 #include <qsqlquery.h>
53 #include <qstringlist.h>
54 #include <qvector.h>
55 
56 #if !defined Q_WS_WIN32
57 # include <unistd.h>
58 #endif
59 #include <sqlite.h>
60 
61 typedef struct sqlite_vm sqlite_vm;
62 
64 Q_DECLARE_METATYPE(sqlite*)
65 
67 
69 {
70  QString tName = typeName.toUpper();
71  if (tName.startsWith(QLatin1String("INT")))
72  return QVariant::Int;
73  if (tName.startsWith(QLatin1String("FLOAT")) || tName.startsWith(QLatin1String("NUMERIC")))
74  return QVariant::Double;
75  if (tName.startsWith(QLatin1String("BOOL")))
76  return QVariant::Bool;
77  // SQLite is typeless - consider everything else as string
78  return QVariant::String;
79 }
80 
82 {
83 public:
85  sqlite *access;
86  bool utf8;
87 };
88 
90 {
91  utf8 = (qstrcmp(sqlite_encoding, "UTF-8") == 0);
92 }
93 
95 {
96 public:
98  void cleanup();
99  bool fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch);
100  bool isSelect();
101  // initializes the recordInfo and the cache
102  void init(const char **cnames, int numCols);
103  void finalize();
104 
106  sqlite *access;
107 
108  // and we have too keep our own struct for the data (sqlite works via
109  // callback.
110  const char *currentTail;
112 
113  bool skippedStatus; // the status of the fetchNext() that's skipped
114  bool skipRow; // skip the next fetchNext()?
115  bool utf8;
118 };
119 
120 static const uint initial_cache_size = 128;
121 
123  currentMachine(0), skippedStatus(false), skipRow(false), utf8(false)
124 {
125 }
126 
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 }
139 
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 }
155 
156 // called on first fetch
157 void QSQLite2ResultPrivate::init(const char **cnames, int numCols)
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 }
182 
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 }
249 
251 : QSqlCachedResult(db)
252 {
253  d = new QSQLite2ResultPrivate(this);
254  d->access = db->d->access;
255  d->utf8 = db->d->utf8;
256 }
257 
259 {
260  d->cleanup();
261  delete d;
262 }
263 
265 {
266  switch (id) {
268  d->finalize();
269  break;
270  default:
272  }
273 }
274 
275 /*
276  Execute \a query.
277 */
278 bool QSQLite2Result::reset (const QString& query)
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 }
320 
322 {
323  return d->fetchNext(row, idx, false);
324 }
325 
327 {
328  return -1;
329 }
330 
332 {
333  return sqlite_changes(d->access);
334 }
335 
337 {
338  if (!isActive() || !isSelect())
339  return QSqlRecord();
340  return d->rInf;
341 }
342 
344 {
346 }
347 
349 
351  : QSqlDriver(parent)
352 {
353  d = new QSQLite2DriverPrivate();
354 }
355 
357  : QSqlDriver(parent)
358 {
359  d = new QSQLite2DriverPrivate();
360  d->access = connection;
361  setOpen(true);
362  setOpenError(false);
363 }
364 
365 
367 {
368  delete d;
369 }
370 
372 {
373  switch (f) {
374  case Transactions:
375  case SimpleLocking:
376  return true;
377  case Unicode:
378  return d->utf8;
379  default:
380  return false;
381  }
382 }
383 
384 /*
385  SQLite dbs have no user name, passwords, hosts or ports.
386  just file names.
387 */
388 bool QSQLite2Driver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &)
389 {
390  if (isOpen())
391  close();
392 
393  if (db.isEmpty())
394  return false;
395 
396  char* err = 0;
397  d->access = sqlite_open(QFile::encodeName(db), 0, &err);
398  if (err) {
399  setLastError(QSqlError(tr("Error opening database"), QString::fromAscii(err),
401  sqlite_freemem(err);
402  err = 0;
403  }
404 
405  if (d->access) {
406  setOpen(true);
407  setOpenError(false);
408  return true;
409  }
410  setOpenError(true);
411  return false;
412 }
413 
415 {
416  if (isOpen()) {
417  sqlite_close(d->access);
418  d->access = 0;
419  setOpen(false);
420  setOpenError(false);
421  }
422 }
423 
425 {
426  return new QSQLite2Result(this);
427 }
428 
430 {
431  if (!isOpen() || isOpenError())
432  return false;
433 
434  char* err;
435  int res = sqlite_exec(d->access, "BEGIN", 0, this, &err);
436 
437  if (res == SQLITE_OK)
438  return true;
439 
440  setLastError(QSqlError(tr("Unable to begin transaction"),
442  sqlite_freemem(err);
443  return false;
444 }
445 
447 {
448  if (!isOpen() || isOpenError())
449  return false;
450 
451  char* err;
452  int res = sqlite_exec(d->access, "COMMIT", 0, this, &err);
453 
454  if (res == SQLITE_OK)
455  return true;
456 
457  setLastError(QSqlError(tr("Unable to commit transaction"),
459  sqlite_freemem(err);
460  return false;
461 }
462 
464 {
465  if (!isOpen() || isOpenError())
466  return false;
467 
468  char* err;
469  int res = sqlite_exec(d->access, "ROLLBACK", 0, this, &err);
470 
471  if (res == SQLITE_OK)
472  return true;
473 
474  setLastError(QSqlError(tr("Unable to rollback transaction"),
476  sqlite_freemem(err);
477  return false;
478 }
479 
481 {
482  QStringList res;
483  if (!isOpen())
484  return res;
485 
486  QSqlQuery q(createResult());
487  q.setForwardOnly(true);
488  if ((type & QSql::Tables) && (type & QSql::Views))
489  q.exec(QLatin1String("SELECT name FROM sqlite_master WHERE type='table' OR type='view'"));
490  else if (type & QSql::Tables)
491  q.exec(QLatin1String("SELECT name FROM sqlite_master WHERE type='table'"));
492  else if (type & QSql::Views)
493  q.exec(QLatin1String("SELECT name FROM sqlite_master WHERE type='view'"));
494 
495  if (q.isActive()) {
496  while(q.next())
497  res.append(q.value(0).toString());
498  }
499 
500  if (type & QSql::SystemTables) {
501  // there are no internal tables beside this one:
502  res.append(QLatin1String("sqlite_master"));
503  }
504 
505  return res;
506 }
507 
509 {
510  QSqlRecord rec(record(tblname)); // expensive :(
511 
512  if (!isOpen())
513  return QSqlIndex();
514 
515  QSqlQuery q(createResult());
516  q.setForwardOnly(true);
517  QString table = tblname;
519  table = stripDelimiters(table, QSqlDriver::TableName);
520  // finrst find a UNIQUE INDEX
521  q.exec(QLatin1String("PRAGMA index_list('") + table + QLatin1String("');"));
522  QString indexname;
523  while(q.next()) {
524  if (q.value(2).toInt()==1) {
525  indexname = q.value(1).toString();
526  break;
527  }
528  }
529  if (indexname.isEmpty())
530  return QSqlIndex();
531 
532  q.exec(QLatin1String("PRAGMA index_info('") + indexname + QLatin1String("');"));
533 
534  QSqlIndex index(table, indexname);
535  while(q.next()) {
536  QString name = q.value(2).toString();
538  if (rec.contains(name))
539  type = rec.field(name).type();
540  index.append(QSqlField(name, type));
541  }
542  return index;
543 }
544 
546 {
547  if (!isOpen())
548  return QSqlRecord();
549  QString table = tbl;
551  table = stripDelimiters(table, QSqlDriver::TableName);
552 
553  QSqlQuery q(createResult());
554  q.setForwardOnly(true);
555  q.exec(QLatin1String("SELECT * FROM ") + tbl + QLatin1String(" LIMIT 1"));
556  return q.record();
557 }
558 
560 {
561  return QVariant::fromValue(d->access);
562 }
563 
565 {
566  QString res = identifier;
567  if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) {
568  res.replace(QLatin1Char('"'), QLatin1String("\"\""));
569  res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
570  res.replace(QLatin1Char('.'), QLatin1String("\".\""));
571  }
572  return res;
573 }
574 
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
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition: qsqlindex.h:55
bool hasFeature(DriverFeature f) const
Returns true if the driver supports feature feature; otherwise returns false.
QVariant data(int i)
Returns the data for field index in the current row as a QVariant.
QVariant handle() const
Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVarian...
const QSqlDriver * driver() const
Returns the driver associated with the result.
Definition: qsqlresult.cpp:389
bool open(const QString &db, const QString &user, const QString &password, const QString &host, int port, const QString &connOpts)
Derived classes must reimplement this pure virtual function to open a database connection on database...
int type
Definition: qmetatype.cpp:239
static const uint initial_cache_size
bool isActive() const
Returns true if the result has records to be retrieved; otherwise returns false.
Definition: qsqlresult.cpp:340
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual void setOpen(bool o)
This function sets the open state of the database to open.
Definition: qsqldriver.cpp:283
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
QString escapeIdentifier(const QString &identifier, IdentifierType) const
Returns the identifier escaped according to the database rules.
DriverFeature
This enum contains a list of features a driver might support.
Definition: qsqldriver.h:75
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
Definition: qsqldriver.cpp:297
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
friend class QSQLite2ResultPrivate
Definition: qsql_sqlite2.h:68
void append(const QSqlField &field)
Appends the field field to the list of indexed fields.
Definition: qsqlindex.cpp:129
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QSQLite2Result(const QSQLite2Driver *db)
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
QSqlRecord record() const
Returns a QSqlRecord containing the field information for the current query.
Definition: qsqlquery.cpp:858
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString & prepend(QChar c)
Definition: qstring.h:261
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
QVector< QVariant > firstRow
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
struct sqlite_vm sqlite_vm
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
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool isEmpty() const
Returns true if there are no fields in the record; otherwise returns false.
Definition: qsqlrecord.cpp:380
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
void virtual_hook(int id, void *data)
The QSqlDriver class is an abstract base class for accessing specific SQL databases.
Definition: qsqldriver.h:68
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isActive() const
Returns true if the query is active.
Definition: qsqlquery.cpp:785
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool commitTransaction()
This function is called to commit a transaction.
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
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const
Returns whether identifier is escaped according to the database rules.
Definition: qsqldriver.cpp:429
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
bool isOpenError() const
Returns true if the there was an error opening the database connection; otherwise returns false...
Definition: qsqldriver.cpp:192
sqlite_vm * currentMachine
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const char * currentTail
bool fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
int size()
Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELE...
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
QSQLite2Result * q
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
const char * typeName
Definition: qmetatype.cpp:239
QStringList tables(QSql::TableType) const
Returns a list of the names of the tables in the database.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QSqlResult * createResult() const
Creates an empty SQL result on the database.
static bool init
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
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
unsigned int uint
Definition: qglobal.h:996
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
TableType
Definition: qsql.h:74
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
QSqlRecord record(const QString &tablename) const
Returns a QSqlRecord populated with the names of the fields in table tableName.
QSQLite2ResultPrivate * d
Definition: qsql_sqlite2.h:83
quint16 values[128]
QVariant::Type type() const
Returns the field&#39;s type as stored in the database.
Definition: qsqlfield.cpp:394
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
QSqlField field(int i) const
Returns the field at position index.
Definition: qsqlrecord.cpp:289
#define Q_DECLARE_METATYPE(TYPE)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor...
Definition: qmetatype.h:265
void setForwardOnly(bool forward)
Sets forward only mode to forward.
Definition: qsqlquery.cpp:835
QSQLite2ResultPrivate(QSQLite2Result *res)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool gotoNext(QSqlCachedResult::ValueCache &row, int idx)
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
int numRowsAffected()
Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or i...
static QVariant::Type nameToType(const QString &typeName)
QSQLite2Driver(QObject *parent=0)
QSqlIndex primaryIndex(const QString &table) const
Returns the primary index for table tableName.
QString & append(QChar c)
Definition: qstring.cpp:1777
void close()
Derived classes must reimplement this pure virtual function in order to close the database connection...
bool reset(const QString &query)
Sets the result to use the SQL statement query for subsequent data retrieval.
friend class QSQLite2Result
Definition: qsql_sqlite2.h:89
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void init(const char **cnames, int numCols)
bool beginTransaction()
This function is called to begin a transaction.
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
static void cleanup()
Definition: qpicture.cpp:1508
void append(const QSqlField &field)
Append a copy of field field to the end of the record.
Definition: qsqlrecord.cpp:312
bool contains(const QString &name) const
Returns true if there is a field in the record called name; otherwise returns false.
Definition: qsqlrecord.cpp:391
QSqlError lastError() const
Returns the last error associated with the result.
Definition: qsqlresult.cpp:427
bool isSelect() const
Returns true if the current result is from a SELECT statement; otherwise returns false.
Definition: qsqlresult.cpp:379
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
quint16 index
QVariant handle() const
Returns the low-level database handle wrapped in a QVariant or an invalid variant if there is no hand...
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
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
void init(int colCount)
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119
bool exec(const QString &query)
Executes the SQL in query.
Definition: qsqlquery.cpp:355
virtual void setLastError(const QSqlError &e)
This function is used to set the value of the last error, error, that occurred on the database...
Definition: qsqldriver.cpp:350
QString stripDelimiters(const QString &identifier, IdentifierType type) const
Returns the identifier with the leading and trailing delimiters removed, identifier can either be a t...
Definition: qsqldriver.cpp:455
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
QVariant value(int i) const
Returns the value of field index in the current record.
Definition: qsqlquery.cpp:403
bool next()
Retrieves the next record in the result, if available, and positions the query on the retrieved recor...
Definition: qsqlquery.cpp:594
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases...
Definition: qsqlresult.h:63
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void virtual_hook(int id, void *data)
IdentifierType
This enum contains a list of SQL identifier types.
Definition: qsqldriver.h:83
QSqlRecord record() const
Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
bool rollbackTransaction()
This function is called to rollback a transaction.