返回介绍

QSqlDriver Class

发布于 2019-10-04 15:02:52 字数 10308 浏览 864 评论 0 收藏 0

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

#include <qsqldriver.h>

Inherits QObject.

List of all member functions.

Public Members

  • enum DriverFeature { Transactions, QuerySize, BLOB }
  • QSqlDriver ( QObject*parent = 0, constchar*name = 0 )
  • ~QSqlDriver ()
  • bool isOpen () const
  • bool isOpenError () const
  • virtual bool beginTransaction ()
  • virtual bool commitTransaction ()
  • virtual bool rollbackTransaction ()
  • virtual QStringList tables ( constQString&user ) const
  • virtual QSqlIndex primaryIndex ( constQString&tableName ) const
  • virtual QSqlRecord record ( constQString&tableName ) const
  • virtual QSqlRecord record ( constQSqlQuery&query ) const
  • virtual QSqlRecordInfo recordInfo ( constQString&tablename ) const
  • virtual QSqlRecordInfo recordInfo ( constQSqlQuery&query ) const
  • virtual QString nullText () const
  • virtual QString formatValue ( constQSqlField*field, booltrimStrings = FALSE ) const
  • QSqlError lastError () const
  • virtual bool hasFeature ( DriverFeaturef ) const = 0
  • virtual bool open ( constQString&db, constQString&user = QString::null, constQString&password = QString::null, constQString&host = QString::null, intport = -1 ) = 0
  • virtual void close () = 0
  • virtual QSqlQuery createQuery () const = 0

Protected Members

  • virtual void setOpen ( boolo )
  • virtual void setOpenError ( boole )
  • virtual void setLastError ( constQSqlError&e )

Detailed Description

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

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

See also Database Classes.


Member Type Documentation

QSqlDriver::DriverFeature

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

The currently defined values are:

  • QSqlDriver::Transactions - whether the driver supports SQL transactions
  • QSqlDriver::QuerySize - whether 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::BLOB - whether the driver supports Binary Large Object fields

See also hasFeature().


Member Function Documentation

QSqlDriver::QSqlDriver ( QObject*parent = 0, constchar*name = 0 )

Default constructor. Creates a new driver with parent parent and name name.

QSqlDriver::~QSqlDriver ()

Destroys the object and frees any allocated resources.

bool QSqlDriver::beginTransaction () [virtual]

Protected function which derived classes can reimplement to begin a transaction. If successful, return TRUE, otherwise return FALSE. The default implementation returns FALSE.

See also commitTransaction() and rollbackTransaction().

void QSqlDriver::close () [pure virtual]

Derived classes must reimplement this abstract virtual function in order to close the database connection. Return TRUE on success, FALSE on failure.

See also setOpen().

bool QSqlDriver::commitTransaction () [virtual]

Protected function which derived classes can reimplement to commit a transaction. If successful, return TRUE, otherwise return FALSE. The default implementation returns FALSE.

See also beginTransaction() and rollbackTransaction().

QSqlQuery QSqlDriver::createQuery () const [pure virtual]

Creates an empty SQL result on the database. Derived classes must reimplement this function and return a QSqlQuery object appropriate for their database to the caller.

QString QSqlDriver::formatValue ( constQSqlField*field, booltrimStrings = FALSE ) const [virtual]

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:

  • If field is null, nullText() is returned.
  • If field is character data, the value is returned enclosed in single quotation marks, which is appropriate for many SQL databases. Any embedded single-quote characters are escaped (replaced with two single-quote characters). If trimStrings is TRUE (the default is FALSE), all trailing whitespace is trimmed from the field.
  • If field is date/time data, the value is formatted in ISO format and enclosed in single quotation marks. If the date/time data is invalid, nullText() is returned.
  • If field is bytearray data, and the driver can edit binary fields, the value is formatted as a hexadecimal string.
  • For any other field type toString() will be called on its value and the result returned.

See also QVariant::toString().

bool QSqlDriver::hasFeature ( DriverFeaturef ) 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

Returns TRUE if the database connection is open, FALSE otherwise.

bool QSqlDriver::isOpenError () const

Returns TRUE if the there was an error opening the database connection, FALSE otherwise.

QSqlError QSqlDriver::lastError () const

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

QString QSqlDriver::nullText () const [virtual]

Returns a string representation of the 'NULL' value for the database. This is used, for example, when constructing INSERT and UPDATE statements. The default implementation returns the string 'NULL'.

bool QSqlDriver::open ( constQString&db, constQString&user = QString::null, constQString&password = QString::null, constQString&host = QString::null, intport = -1 ) [pure virtual]

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

The function must return TRUE on success and FALSE on failure.

See also setOpen().

QSqlIndex QSqlDriver::primaryIndex ( constQString&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 ( constQString&tableName ) const [virtual]

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

QSqlRecord QSqlDriver::record ( constQSqlQuery&query ) const [virtual]

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

Returns a QSqlRecord populated with the names of the fields in the SQL query. The default implementation returns an empty record.

QSqlRecordInfo QSqlDriver::recordInfo ( constQString&tablename ) const [virtual]

Returns a QSqlRecordInfo object with meta data on the table tablename.

QSqlRecordInfo QSqlDriver::recordInfo ( constQSqlQuery&query ) const [virtual]

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

Returns a QSqlRecordInfo object with meta data for the QSqlQuery query. Note that this overloaded function may return not as much information as the recordInfo function which takes the name of a table as parameter.

bool QSqlDriver::rollbackTransaction () [virtual]

Protected function which derived classes can reimplement to rollback a transaction. If successful, return TRUE, otherwise return FALSE. The default implementation returns FALSE.

See also beginTransaction() and commitTransaction().

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

Protected function which allows derived classes to set the value of the last error, e, that occurred on the database.

See also lastError().

void QSqlDriver::setOpen ( boolo ) [virtual protected]

Protected function which 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 ( boole ) [virtual protected]

Protected function which 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().

QStringList QSqlDriver::tables ( constQString&user ) const [virtual]

Returns a list of tables in the database. The default implementation returns an empty list.

Currently the user argument is unused.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文