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

#include <qsql_sqlite2.h>

Inheritance diagram for QSQLite2Driver:
QSqlDriver QObject

Public Functions

bool beginTransaction ()
 This function is called to begin a transaction. More...
 
void close ()
 Derived classes must reimplement this pure virtual function in order to close the database connection. More...
 
bool commitTransaction ()
 This function is called to commit a transaction. More...
 
QSqlResultcreateResult () const
 Creates an empty SQL result on the database. More...
 
QString escapeIdentifier (const QString &identifier, IdentifierType) const
 Returns the identifier escaped according to the database rules. More...
 
QVariant handle () const
 Returns the low-level database handle wrapped in a QVariant or an invalid variant if there is no handle. More...
 
bool hasFeature (DriverFeature f) const
 Returns true if the driver supports feature feature; otherwise returns false. More...
 
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 db, using user name user, password password, host host, port port and connection options options. More...
 
bool open (const QString &db, const QString &user, const QString &password, const QString &host, int port)
 
QSqlIndex primaryIndex (const QString &table) const
 Returns the primary index for table tableName. More...
 
 QSQLite2Driver (QObject *parent=0)
 
 QSQLite2Driver (sqlite *connection, QObject *parent=0)
 
QSqlRecord record (const QString &tablename) const
 Returns a QSqlRecord populated with the names of the fields in table tableName. More...
 
bool rollbackTransaction ()
 This function is called to rollback a transaction. More...
 
QStringList tables (QSql::TableType) const
 Returns a list of the names of the tables in the database. More...
 
 ~QSQLite2Driver ()
 
- Public Functions inherited from QSqlDriver
virtual QString formatValue (const QSqlField &field, bool trimStrings=false) const
 Returns a string representation of the field value for the database. More...
 
bool isIdentifierEscaped (const QString &identifier, IdentifierType type) const
 Returns whether identifier is escaped according to the database rules. More...
 
virtual bool isOpen () const
 Returns true if the database connection is open; otherwise returns false. More...
 
bool isOpenError () const
 Returns true if the there was an error opening the database connection; otherwise returns false. More...
 
QSqlError lastError () const
 Returns a QSqlError object which contains information about the last error that occurred on the database. More...
 
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy () const
 Returns the current default precision policy for the database connection. More...
 
 QSqlDriver (QObject *parent=0)
 Constructs a new driver with the given parent. More...
 
void setNumericalPrecisionPolicy (QSql::NumericalPrecisionPolicy precisionPolicy)
 Sets the default numerical precision policy used by queries created by this driver to precisionPolicy. More...
 
virtual QString sqlStatement (StatementType type, const QString &tableName, const QSqlRecord &rec, bool preparedStatement) const
 Returns a SQL statement of type type for the table tableName with the values from rec. More...
 
QString stripDelimiters (const QString &identifier, IdentifierType type) const
 Returns the identifier with the leading and trailing delimiters removed, identifier can either be a table name or field name, dependent on type. More...
 
QStringList subscribedToNotifications () const
 Returns a list of the names of the event notifications that are currently subscribed to. More...
 
bool subscribeToNotification (const QString &name)
 This function is called to subscribe to event notifications from the database. More...
 
bool unsubscribeFromNotification (const QString &name)
 This function is called to unsubscribe from event notifications from the database. More...
 
 ~QSqlDriver ()
 Destroys the object and frees any allocated resources. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Properties

QSQLite2DriverPrivated
 

Friends

class QSQLite2Result
 

Additional Inherited Members

- Public Types inherited from QSqlDriver
enum  DriverFeature {
  Transactions, QuerySize, BLOB, Unicode,
  PreparedQueries, NamedPlaceholders, PositionalPlaceholders, LastInsertId,
  BatchOperations, SimpleLocking, LowPrecisionNumbers, EventNotifications,
  FinishQuery, MultipleResultSets
}
 This enum contains a list of features a driver might support. More...
 
enum  IdentifierType { FieldName, TableName }
 This enum contains a list of SQL identifier types. More...
 
enum  StatementType {
  WhereStatement, SelectStatement, UpdateStatement, InsertStatement,
  DeleteStatement
}
 This enum contains a list of SQL statement (or clause) types the driver can create. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QSqlDriver
void notification (const QString &name)
 This signal is emitted when the database posts an event notification that the driver subscribes to. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QSqlDriver
bool isIdentifierEscapedImplementation (const QString &identifier, IdentifierType type) const
 This slot returns whether identifier is escaped according to the database rules. More...
 
QString stripDelimitersImplementation (const QString &identifier, IdentifierType type) const
 This slot returns identifier with the leading and trailing delimiters removed, identifier can either be a tablename or field name, dependent on type. More...
 
QStringList subscribedToNotificationsImplementation () const
 Returns a list of the names of the event notifications that are currently subscribed to. More...
 
bool subscribeToNotificationImplementation (const QString &name)
 This slot is called to subscribe to event notifications from the database. More...
 
bool unsubscribeFromNotificationImplementation (const QString &name)
 This slot is called to unsubscribe from event notifications from the database. More...
 
- Protected Functions inherited from QSqlDriver
virtual void setLastError (const QSqlError &e)
 This function is used to set the value of the last error, error, that occurred on the database. More...
 
virtual void setOpen (bool o)
 This function sets the open state of the database to open. More...
 
virtual void setOpenError (bool e)
 This function sets the open error state of the database to error. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 86 of file qsql_sqlite2.h.

Constructors and Destructors

◆ QSQLite2Driver() [1/2]

QSQLite2Driver::QSQLite2Driver ( QObject parent = 0)
explicit

Definition at line 350 of file qsql_sqlite2.cpp.

351  : QSqlDriver(parent)
352 {
353  d = new QSQLite2DriverPrivate();
354 }
QSqlDriver(QObject *parent=0)
Constructs a new driver with the given parent.
Definition: qsqldriver.cpp:112
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119

◆ QSQLite2Driver() [2/2]

QSQLite2Driver::QSQLite2Driver ( sqlite *  connection,
QObject parent = 0 
)
explicit

Definition at line 356 of file qsql_sqlite2.cpp.

357  : QSqlDriver(parent)
358 {
359  d = new QSQLite2DriverPrivate();
360  d->access = connection;
361  setOpen(true);
362  setOpenError(false);
363 }
virtual void setOpen(bool o)
This function sets the open state of the database to open.
Definition: qsqldriver.cpp:283
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
Definition: qsqldriver.cpp:297
QSqlDriver(QObject *parent=0)
Constructs a new driver with the given parent.
Definition: qsqldriver.cpp:112
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119

◆ ~QSQLite2Driver()

QSQLite2Driver::~QSQLite2Driver ( )

Definition at line 366 of file qsql_sqlite2.cpp.

367 {
368  delete d;
369 }
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119

Functions

◆ beginTransaction()

bool QSQLite2Driver::beginTransaction ( )
virtual

This function is called to begin a transaction.

If successful, return true, otherwise return false. The default implementation does nothing and returns false.

See also
commitTransaction(), rollbackTransaction()

Reimplemented from QSqlDriver.

Definition at line 429 of file qsql_sqlite2.cpp.

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 }
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 tr(const char *sourceText, const char *comment=0, int n=-1)
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
bool isOpenError() const
Returns true if the there was an error opening the database connection; otherwise returns false...
Definition: qsqldriver.cpp:192
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119
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

◆ close()

void QSQLite2Driver::close ( )
virtual

Derived classes must reimplement this pure virtual function in order to close the database connection.

Return true on success, false on failure.

See also
open(), setOpen()

Implements QSqlDriver.

Definition at line 414 of file qsql_sqlite2.cpp.

Referenced by open().

415 {
416  if (isOpen()) {
417  sqlite_close(d->access);
418  d->access = 0;
419  setOpen(false);
420  setOpenError(false);
421  }
422 }
virtual void setOpen(bool o)
This function sets the open state of the database to open.
Definition: qsqldriver.cpp:283
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
Definition: qsqldriver.cpp:297
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119

◆ commitTransaction()

bool QSQLite2Driver::commitTransaction ( )
virtual

This function is called to commit a transaction.

If successful, return true, otherwise return false. The default implementation does nothing and returns false.

See also
beginTransaction(), rollbackTransaction()

Reimplemented from QSqlDriver.

Definition at line 446 of file qsql_sqlite2.cpp.

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 }
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 tr(const char *sourceText, const char *comment=0, int n=-1)
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
bool isOpenError() const
Returns true if the there was an error opening the database connection; otherwise returns false...
Definition: qsqldriver.cpp:192
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119
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

◆ createResult()

QSqlResult * QSQLite2Driver::createResult ( ) const
virtual

Creates an empty SQL result on the database.

Derived classes must reimplement this function and return a QSqlResult object appropriate for their database to the caller.

Implements QSqlDriver.

Definition at line 424 of file qsql_sqlite2.cpp.

Referenced by primaryIndex(), record(), and tables().

425 {
426  return new QSQLite2Result(this);
427 }
friend class QSQLite2Result
Definition: qsql_sqlite2.h:89

◆ escapeIdentifier()

QString QSQLite2Driver::escapeIdentifier ( const QString identifier,
IdentifierType  type 
) const
virtual

Returns the identifier escaped according to the database rules.

identifier can either be a table name or field name, dependent on type.

The default implementation does nothing.

See also
isIdentifierEscaped()

Reimplemented from QSqlDriver.

Definition at line 564 of file qsql_sqlite2.cpp.

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 }
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QString & prepend(QChar c)
Definition: qstring.h:261
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
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString & append(QChar c)
Definition: qstring.cpp:1777
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

◆ handle()

QVariant QSQLite2Driver::handle ( ) const
virtual

Returns the low-level database handle wrapped in a QVariant or an invalid variant 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 connection is modified (for example, if you close the connection).
The handle can be NULL if the connection is not open 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 connection to sqlite:

QSqlDatabase db = ...;
QVariant v = db.driver()->handle();
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0) {
// v.data() returns a pointer to the handle
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
if (handle != 0) { // check that it is not NULL
...
}
}

This snippet returns the handle for PostgreSQL or MySQL:

if (qstrcmp(v.typeName(), "PGconn*") == 0) {
PGconn *handle = *static_cast<PGconn **>(v.data());
if (handle != 0) ...
}
if (qstrcmp(v.typeName(), "MYSQL*") == 0) {
MYSQL *handle = *static_cast<MYSQL **>(v.data());
if (handle != 0) ...
}
See also
QSqlResult::handle()

Reimplemented from QSqlDriver.

Definition at line 559 of file qsql_sqlite2.cpp.

560 {
561  return QVariant::fromValue(d->access);
562 }
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119

◆ hasFeature()

bool QSQLite2Driver::hasFeature ( DriverFeature  feature) const
virtual

Returns true if the driver supports feature feature; otherwise returns false.

Note that some databases need to be open() before this can be determined.

See also
DriverFeature

Implements QSqlDriver.

Definition at line 371 of file qsql_sqlite2.cpp.

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 }
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119

◆ open() [1/2]

bool QSQLite2Driver::open ( const QString db,
const QString user,
const QString password,
const QString host,
int  port,
const QString options 
)
virtual

Derived classes must reimplement this pure virtual function to open a database connection on database db, using user name user, password password, host host, port port and connection options options.

The function must return true on success and false on failure.

See also
setOpen()

Implements QSqlDriver.

Definition at line 388 of file qsql_sqlite2.cpp.

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 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
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
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
Definition: qsqldriver.cpp:297
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void close()
Derived classes must reimplement this pure virtual function in order to close the database connection...
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
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119
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

◆ open() [2/2]

bool QSQLite2Driver::open ( const QString db,
const QString user,
const QString password,
const QString host,
int  port 
)
inline

Definition at line 101 of file qsql_sqlite2.h.

105  { return open (db, user, password, host, port, QString()); }
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...
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ primaryIndex()

QSqlIndex QSQLite2Driver::primaryIndex ( const QString tableName) const
virtual

Returns the primary index for table tableName.

Returns an empty QSqlIndex if the table doesn't have a primary index. The default implementation returns an empty index.

Reimplemented from QSqlDriver.

Definition at line 508 of file qsql_sqlite2.cpp.

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 }
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition: qsqlindex.h:55
int type
Definition: qmetatype.cpp:239
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const
Returns whether identifier is escaped according to the database rules.
Definition: qsqldriver.cpp:429
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.
const char * name
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.
quint16 index
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
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

◆ record()

QSqlRecord QSQLite2Driver::record ( const QString tableName) const
virtual

Returns a QSqlRecord populated with the names of the fields in table tableName.

Use query.

If no such table exists, an empty record is returned. The default implementation returns an empty record.

record() instead.

Reimplemented from QSqlDriver.

Definition at line 545 of file qsql_sqlite2.cpp.

Referenced by primaryIndex().

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 }
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const
Returns whether identifier is escaped according to the database rules.
Definition: qsqldriver.cpp:429
QSqlResult * createResult() const
Creates an empty SQL result on the database.
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

◆ rollbackTransaction()

bool QSQLite2Driver::rollbackTransaction ( )
virtual

This function is called to rollback a transaction.

If successful, return true, otherwise return false. The default implementation does nothing and returns false.

See also
beginTransaction(), commitTransaction()

Reimplemented from QSqlDriver.

Definition at line 463 of file qsql_sqlite2.cpp.

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 }
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 tr(const char *sourceText, const char *comment=0, int n=-1)
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
bool isOpenError() const
Returns true if the there was an error opening the database connection; otherwise returns false...
Definition: qsqldriver.cpp:192
QSQLite2DriverPrivate * d
Definition: qsql_sqlite2.h:119
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

◆ tables()

QStringList QSQLite2Driver::tables ( QSql::TableType  tableType) const
virtual

Returns a list of the names of the tables in the database.

The default implementation returns an empty list.

The tableType argument describes what types of tables should be returned. Due to binary compatibility, the string contains the value of the enum QSql::TableTypes as text. An empty string should be treated as QSql::Tables for backward compatibility.

Reimplemented from QSqlDriver.

Definition at line 480 of file qsql_sqlite2.cpp.

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 }
int type
Definition: qmetatype.cpp:239
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QSqlResult * createResult() const
Creates an empty SQL result on the database.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66

Friends and Related Functions

◆ QSQLite2Result

friend class QSQLite2Result
friend

Definition at line 89 of file qsql_sqlite2.h.

Referenced by createResult().

Properties

◆ d

QSQLite2DriverPrivate* QSQLite2Driver::d
private

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