Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

QSqlDriver Class Reference

The QSqlDriver class is an abstract base class for accessing SQL databases. More...

#include <QSqlDriver>

Inherits QObject.

Public Types

Writable Properties

Public Functions

Public Slots

Signals

Static Public Members

Protected Functions


Detailed Description

The QSqlDriver class is an abstract base class for accessing SQL databases.

This class should not be used directly. Use QSqlDatabase instead.

If you want to create your own driver you can subclass this class and reimplement its pure virtual functions, and those virtual functions that you need.


Member Type Documentation

enum QSqlDriver::DriverFeature

This enum contains a list of features a driver might support. Use hasFeature() to query whether a feature is supported or not.

QSqlDriver::Transactionswhether the driver supports SQL transactions
QSqlDriver::QuerySizewhether the database is capable of reporting the size of a query. Note that some databases do not support returning the size (i.e. number of rows returned) of a query, in which case QSqlQuery::size() will return -1
QSqlDriver::BLOBwhether the driver supports Binary Large Object fields
QSqlDriver::Unicodewhether the driver supports Unicode strings if the database server does
QSqlDriver::PreparedQuerieswhether the driver supports prepared query execution
QSqlDriver::NamedPlaceholderswhether the driver supports the use of named placeholders
QSqlDriver::PositionalPlaceholderswhether the driver supports the use of positional placeholders

More information about supported features can be found in the Qt SQL driver documentation.

See also hasFeature().

enum QSqlDriver::StatementType

This enum contains a list of SQL statement types the driver can create.

QSqlDriver::WhereStatementa SQL WHERE statement, for example WHERE f = 5
QSqlDriver::SelectStatementa SQL SELECT statement, for example SELECT f FROM t
QSqlDriver::UpdateStatementa SQL UPDATE statement, for example UPDATE TABLE t set f = 1
QSqlDriver::InsertStatementa SQL INSERT statement, for example INSERT INTO t (f) values (1)
QSqlDriver::DeleteStatementa SQL DELETE statement, for example DELETE FROM t

See also sqlStatement().


Member Function Documentation

QSqlDriver::QSqlDriver ( QObject * parent = 0 )

Default constructor. Creates a new driver with the given parent.

QSqlDriver::~QSqlDriver ()

Destroys the object and frees any allocated resources.

bool QSqlDriver::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() and rollbackTransaction().

void QSqlDriver::close ()   [pure 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() and setOpen().

bool QSqlDriver::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() and rollbackTransaction().

QSqlResult * QSqlDriver::createResult () const   [pure 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.

QString QSqlDriver::formatValue ( const QSqlField & field, bool trimStrings = false ) const   [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns a string representation of the field value for the database. This is used, for example, when constructing INSERT and UPDATE statements.

The default implementation returns the value formatted as a string according to the following rules:

See also QCoreVariant::toString() and ..

bool QSqlDriver::hasFeature ( DriverFeature f ) const   [pure virtual]

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

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

See also DriverFeature.

bool QSqlDriver::isOpen () const   [virtual]

Returns true if the database connection is open; otherwise returns false.

bool QSqlDriver::isOpenError () const

Returns true if the there was an error opening the database connection; otherwise returns false.

QSqlError QSqlDriver::lastError () const

Returns a QSqlError object which contains information about the last error that occurred on the database.

bool QSqlDriver::open ( const QString & db, const QString & user = QString(), const QString & password = QString(), const QString & host = QString(), int port = -1, const QString & connOpts = QString() )   [pure virtual]

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

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

See also setOpen().

QSqlIndex QSqlDriver::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.

QSqlRecord QSqlDriver::record ( const QString & tableName ) const   [virtual]

Returns a QSqlRecord populated with the names of the fields in table tableName. If no such table exists, an empty record is returned. The default implementation returns an empty record.

bool QSqlDriver::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() and commitTransaction().

void QSqlDriver::setLastError ( const QSqlError & e )   [virtual protected]

This function is used to set the value of the last error, e, that occurred on the database.

See also lastError().

void QSqlDriver::setOpen ( bool o )   [virtual protected]

This function sets the open state of the database to o. Derived classes can use this function to report the status of open().

See also open() and setOpenError().

void QSqlDriver::setOpenError ( bool e )   [virtual protected]

This function sets the open error state of the database to e. Derived classes can use this function to report the status of open(). Note that if e is true the open state of the database is set to closed (i.e. isOpen() returns false).

See also open() and setOpenError().

QString QSqlDriver::sqlStatement ( StatementType type, const QString & tableName, const QSqlRecord & rec, bool preparedStatement ) const   [virtual]

Returns a SQL statement of type type for the table tableName with the values from rec. If preparedStatement is TRUE, the string will contain placeholders instead of values.

This method can be used to manipulate tables without having to worry about database-dependend SQL dialects. For non-prepared statements, the values will be properly escaped.

QStringList QSqlDriver::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.

See also QSql::TableType.


Copyright © 2004 Trolltech. Trademarks
Qt 4.0.0-tp2