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

#include <qsql_sqlite.h>

Inheritance diagram for QSQLiteDriver:
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...
 
QSqlIndex primaryIndex (const QString &table) const
 Returns the primary index for table tableName. More...
 
 QSQLiteDriver (QObject *parent=0)
 
 QSQLiteDriver (sqlite3 *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...
 
 ~QSQLiteDriver ()
 
- 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

QSQLiteDriverPrivated
 

Friends

class QSQLiteResult
 

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 88 of file qsql_sqlite.h.

Constructors and Destructors

◆ QSQLiteDriver() [1/2]

QSQLiteDriver::QSQLiteDriver ( QObject parent = 0)
explicit

Definition at line 497 of file qsql_sqlite.cpp.

498  : QSqlDriver(parent)
499 {
500  d = new QSQLiteDriverPrivate();
501 }
QSQLiteDriverPrivate * d
Definition: qsql_sqlite.h:116
QSqlDriver(QObject *parent=0)
Constructs a new driver with the given parent.
Definition: qsqldriver.cpp:112

◆ QSQLiteDriver() [2/2]

QSQLiteDriver::QSQLiteDriver ( sqlite3 *  connection,
QObject parent = 0 
)
explicit

Definition at line 503 of file qsql_sqlite.cpp.

504  : QSqlDriver(parent)
505 {
506  d = new QSQLiteDriverPrivate();
507  d->access = connection;
508  setOpen(true);
509  setOpenError(false);
510 }
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
QSQLiteDriverPrivate * d
Definition: qsql_sqlite.h:116
QSqlDriver(QObject *parent=0)
Constructs a new driver with the given parent.
Definition: qsqldriver.cpp:112

◆ ~QSQLiteDriver()

QSQLiteDriver::~QSQLiteDriver ( )

Definition at line 513 of file qsql_sqlite.cpp.

514 {
515  delete d;
516 }
QSQLiteDriverPrivate * d
Definition: qsql_sqlite.h:116

Functions

◆ beginTransaction()

bool QSQLiteDriver::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 603 of file qsql_sqlite.cpp.

604 {
605  if (!isOpen() || isOpenError())
606  return false;
607 
608  QSqlQuery q(createResult());
609  if (!q.exec(QLatin1String("BEGIN"))) {
610  setLastError(QSqlError(tr("Unable to begin transaction"),
611  q.lastError().databaseText(), QSqlError::TransactionError));
612  return false;
613  }
614 
615  return true;
616 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
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
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QSqlResult * createResult() const
Creates an empty SQL result on the database.
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 QSQLiteDriver::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 583 of file qsql_sqlite.cpp.

Referenced by open().

584 {
585  if (isOpen()) {
586  foreach (QSQLiteResult *result, d->results)
587  result->d->finalize();
588 
589  if (sqlite3_close(d->access) != SQLITE_OK)
590  setLastError(qMakeError(d->access, tr("Error closing database"),
592  d->access = 0;
593  setOpen(false);
594  setOpenError(false);
595  }
596 }
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
QSQLiteDriverPrivate * d
Definition: qsql_sqlite.h:116
static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::ErrorType type, int errorCode=-1)
Definition: qsql_sqlite.cpp:95
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
QSQLiteResultPrivate * d
Definition: qsql_sqlite.h:85
QList< QSQLiteResult * > results
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

◆ commitTransaction()

bool QSQLiteDriver::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 618 of file qsql_sqlite.cpp.

619 {
620  if (!isOpen() || isOpenError())
621  return false;
622 
623  QSqlQuery q(createResult());
624  if (!q.exec(QLatin1String("COMMIT"))) {
625  setLastError(QSqlError(tr("Unable to commit transaction"),
626  q.lastError().databaseText(), QSqlError::TransactionError));
627  return false;
628  }
629 
630  return true;
631 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
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
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QSqlResult * createResult() const
Creates an empty SQL result on the database.
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 * QSQLiteDriver::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 598 of file qsql_sqlite.cpp.

Referenced by beginTransaction(), commitTransaction(), primaryIndex(), record(), rollbackTransaction(), and tables().

599 {
600  return new QSQLiteResult(this);
601 }
friend class QSQLiteResult
Definition: qsql_sqlite.h:91

◆ escapeIdentifier()

QString QSQLiteDriver::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 743 of file qsql_sqlite.cpp.

744 {
745  Q_UNUSED(type);
746  return _q_escapeIdentifier(identifier);
747 }
int type
Definition: qmetatype.cpp:239
static QString _q_escapeIdentifier(const QString &identifier)
Definition: qsql_sqlite.cpp:67
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ handle()

QVariant QSQLiteDriver::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 738 of file qsql_sqlite.cpp.

739 {
740  return QVariant::fromValue(d->access);
741 }
QSQLiteDriverPrivate * d
Definition: qsql_sqlite.h:116
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336

◆ hasFeature()

bool QSQLiteDriver::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 518 of file qsql_sqlite.cpp.

◆ open()

bool QSQLiteDriver::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 545 of file qsql_sqlite.cpp.

546 {
547  if (isOpen())
548  close();
549 
550  if (db.isEmpty())
551  return false;
552  bool sharedCache = false;
553  int openMode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, timeOut=5000;
554  QStringList opts=QString(conOpts).remove(QLatin1Char(' ')).split(QLatin1Char(';'));
555  foreach(const QString &option, opts) {
556  if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) {
557  bool ok;
558  int nt = option.mid(21).toInt(&ok);
559  if (ok)
560  timeOut = nt;
561  }
562  if (option == QLatin1String("QSQLITE_OPEN_READONLY"))
563  openMode = SQLITE_OPEN_READONLY;
564  if (option == QLatin1String("QSQLITE_ENABLE_SHARED_CACHE"))
565  sharedCache = true;
566  }
567 
568  sqlite3_enable_shared_cache(sharedCache);
569 
570  if (sqlite3_open_v2(db.toUtf8().constData(), &d->access, openMode, NULL) == SQLITE_OK) {
571  sqlite3_busy_timeout(d->access, timeOut);
572  setOpen(true);
573  setOpenError(false);
574  return true;
575  } else {
576  setLastError(qMakeError(d->access, tr("Error opening database"),
578  setOpenError(true);
579  return false;
580  }
581 }
virtual void setOpen(bool o)
This function sets the open state of the database to open.
Definition: qsqldriver.cpp:283
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
Definition: qsqldriver.cpp:297
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QSQLiteDriverPrivate * d
Definition: qsql_sqlite.h:116
static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::ErrorType type, int errorCode=-1)
Definition: qsql_sqlite.cpp:95
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
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
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
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
#define nt(var, enu)
void close()
Derived classes must reimplement this pure virtual function in order to close the database connection...
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
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
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
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 & 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

◆ primaryIndex()

QSqlIndex QSQLiteDriver::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 710 of file qsql_sqlite.cpp.

711 {
712  if (!isOpen())
713  return QSqlIndex();
714 
715  QString table = tblname;
717  table = stripDelimiters(table, QSqlDriver::TableName);
718 
719  QSqlQuery q(createResult());
720  q.setForwardOnly(true);
721  return qGetTableInfo(q, table, true);
722 }
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition: qsqlindex.h:55
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
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.
static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool onlyPIndex=false)
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 QSQLiteDriver::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 724 of file qsql_sqlite.cpp.

725 {
726  if (!isOpen())
727  return QSqlRecord();
728 
729  QString table = tbl;
731  table = stripDelimiters(table, QSqlDriver::TableName);
732 
733  QSqlQuery q(createResult());
734  q.setForwardOnly(true);
735  return qGetTableInfo(q, table);
736 }
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
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.
static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool onlyPIndex=false)
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 QSQLiteDriver::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 633 of file qsql_sqlite.cpp.

634 {
635  if (!isOpen() || isOpenError())
636  return false;
637 
638  QSqlQuery q(createResult());
639  if (!q.exec(QLatin1String("ROLLBACK"))) {
640  setLastError(QSqlError(tr("Unable to rollback transaction"),
641  q.lastError().databaseText(), QSqlError::TransactionError));
642  return false;
643  }
644 
645  return true;
646 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
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
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QSqlResult * createResult() const
Creates an empty SQL result on the database.
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 QSQLiteDriver::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 648 of file qsql_sqlite.cpp.

649 {
650  QStringList res;
651  if (!isOpen())
652  return res;
653 
654  QSqlQuery q(createResult());
655  q.setForwardOnly(true);
656 
657  QString sql = QLatin1String("SELECT name FROM sqlite_master WHERE %1 "
658  "UNION ALL SELECT name FROM sqlite_temp_master WHERE %1");
659  if ((type & QSql::Tables) && (type & QSql::Views))
660  sql = sql.arg(QLatin1String("type='table' OR type='view'"));
661  else if (type & QSql::Tables)
662  sql = sql.arg(QLatin1String("type='table'"));
663  else if (type & QSql::Views)
664  sql = sql.arg(QLatin1String("type='view'"));
665  else
666  sql.clear();
667 
668  if (!sql.isEmpty() && q.exec(sql)) {
669  while(q.next())
670  res.append(q.value(0).toString());
671  }
672 
673  if (type & QSql::SystemTables) {
674  // there are no internal tables beside this one:
675  res.append(QLatin1String("sqlite_master"));
676  }
677 
678  return res;
679 }
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 QString class provides a Unicode character string.
Definition: qstring.h:83
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QSqlResult * createResult() const
Creates an empty SQL result on the database.
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723

Friends and Related Functions

◆ QSQLiteResult

friend class QSQLiteResult
friend

Definition at line 91 of file qsql_sqlite.h.

Referenced by createResult().

Properties

◆ d

QSQLiteDriverPrivate* QSQLiteDriver::d
private

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