内容表

上一话题

在表格视图中呈现数据

下一话题

执行 SQL 语句

SQL 编程

Database integration for Qt applications.

This overview assumes that you have at least a basic knowledge of SQL. You should be able to understand simple SELECT , INSERT , UPDATE ,和 DELETE statements. Although the QSqlTableModel class provides an interface to database browsing and editing that does not require a knowledge of SQL, a basic understanding of SQL is highly recommended. A standard text covering SQL databases is An Introduction to Database Systems (7th Ed.) by C. J. Date, ISBN 0201385902.

数据库类

这些类提供对 SQL 数据库的访问。

qsql.html

The QSql namespace contains miscellaneous identifiers used throughout the Qt SQL module.

PySide2.QtSql.QSqlDriverCreatorBase

The QSqlDriverCreatorBase class is the base class for SQL driver factories.

QSqlDriverCreator

The QSqlDriverCreator class is a template class that provides a SQL driver factory for a specific driver type.

PySide2.QtSql.QSqlDatabase

The QSqlDatabase class handles a connection to a database.

PySide2.QtSql.QSqlDriver

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

PySide2.QtSql.QSqlError

The QSqlError class provides SQL database error information.

PySide2.QtSql.QSqlField

QSqlField 类操纵 SQL 数据库表和视图中的字段。

PySide2.QtSql.QSqlIndex

The QSqlIndex class provides functions to manipulate and describe database indexes.

PySide2.QtSql.QSqlQuery

QSqlQuery 类提供执行和操纵 SQL 语句的手段。

PySide2.QtSql.QSqlRecord

QSqlRecord 类封装数据库记录。

PySide2.QtSql.QSqlResult

The QSqlResult class provides an abstract interface for accessing data from specific SQL databases.

PySide2.QtSql.QSqlQueryModel

The QSqlQueryModel class provides a read-only data model for SQL result sets.

PySide2.QtSql.QSqlRelationalTableModel

The QSqlRelationalTableModel class provides an editable data model for a single database table, with foreign key support.

PySide2.QtSql.QSqlTableModel

The QSqlTableModel class provides an editable data model for a single database table.

SQL 类分为 3 层:

驱动层

This comprises the classes QSqlDriver , QSqlDriverCreator , QSqlDriverCreatorBase , QSqlDriverPlugin ,和 QSqlResult .

This layer provides the low-level bridge between the specific databases and the SQL API layer. See SQL 数据库驱动程序 了解更多信息。

SQL API 层

These classes provide access to databases. Connections are made using the QSqlDatabase class. Database interaction is achieved by using the QSqlQuery class. In addition to QSqlDatabase and QSqlQuery , the SQL API layer is supported by QSqlError , QSqlField , QSqlIndex ,和 QSqlRecord .

用户界面层

These classes link the data from a database to data-aware widgets. They include QSqlQueryModel , QSqlTableModel ,和 QSqlRelationalTableModel . These classes are designed to work with Qt’s 模型/视图框架 .

注意: QCoreApplication object must be instantiated before using any of these classes.