SQL编程

本文介绍了Qt框架中与SQL编程相关的类和概念,包括QSqlDatabase用于数据库连接,QSqlQuery执行SQL语句,以及QSqlTableModel等数据模型类用于数据呈现和编辑。文章强调了即使有QSqlTableModel这样的抽象接口,了解基础SQL知识仍然是重要的。同时,文章涵盖了数据库类的三层结构:驱动层、SQLAPI层和用户接口层。

SQL Programming

This overview assumes that you have at least a basic knowledge of SQL. You should be able to understand simple SELECT, INSERT, UPDATE, and 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的基本知识。您应该能够理解简单的SELECT、INSERT、UPDATE和DELETE语句。尽管QSqlTableModel类为数据库浏览和编辑提供了一个不需要SQL知识的界面,但强烈建议您对SQL有基本的了解。涵盖SQL数据库的标准文本是C.J.Date的《数据库系统导论》(第7版),ISBN 0201385902。

Topics:

话题:

  • 数据库类

  • 连接到数据库

  • SQL数据库驱动程序

  • 执行SQL语句

  • 支持Qt的数据库系统的数据类型

  • 使用SQL模型类

  • 在表视图中显示数据

  • 创建数据感知表单

Database Classes

数据库类

These classes provide access to SQL databases.

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

QSql

Contains miscellaneous identifiers used throughout the Qt SQL module

包含整个Qt SQL模块中使用的杂项标识符

QSqlDatabase

Handles a connection to a database

处理与数据库的连接

QSqlDriver

Abstract base class for accessing specific SQL databases

用于访问特定SQL数据库的抽象基类

QSqlDriverCreator

Template class that provides a SQL driver factory for a specific driver type

为特定驱动程序类型提供SQL驱动程序工厂的模板类

QSqlDriverCreatorBase

The base class for SQL driver factories

SQL驱动程序工厂的基类

QSqlError

SQL database error information

SQL数据库错误信息

QSqlField

Manipulates the fields in SQL database tables and views

操作SQL数据库表和视图中的字段

QSqlIndex

Functions to manipulate and describe database indexes

操作和描述数据库索引的函数

QSqlQuery

Means of executing and manipulating SQL statements

执行和操作SQL语句的方法

QSqlQueryModel

Read-only data model for SQL result sets

SQL结果集的只读数据模型

QSqlRecord

Encapsulates a database record

封装数据库记录

QSqlRelationalTableModel

Editable data model for a single database table, with foreign key support

单个数据库表的可编辑数据模型,支持外键

QSqlResult

Abstract interface for accessing data from specific SQL databases

用于访问特定SQL数据库中的数据的抽象接口

QSqlTableModel

Editable data model for a single database table

单个数据库表的可编辑数据模型

The SQL classes are divided into three layers:

SQL类分为三层:

Driver Layer

驱动层

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

这包括类QSqlDriver、QSqlDriverCreator、QSqlDRIVECreatorBase、QSqldrivePlugin和QSqlResult。

This layer provides the low-level bridge between the specific databases and the SQL API layer. See SQL Database Drivers for more information.

该层提供了特定数据库和SQLAPI层之间的低级桥梁。有关详细信息,请参阅SQL数据库驱动程序。

SQL API Layer

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, and QSqlRecord.

这些类提供对数据库的访问。使用QSqlDatabase类进行连接。数据库交互是通过使用QSqlQuery类来实现的。除了QSqlDatabase和QSqlQuery之外,QSqlError、QSqlField、QSqlIndex和QSqlRecord还支持SQL API层。

User Interface Layer

用户接口层

These classes link the data from a database to data-aware widgets. They include QSqlQueryModel, QSqlTableModel, and QSqlRelationalTableModel. These classes are designed to work with Qt's model/view framework.

这些类将数据库中的数据链接到数据感知小部件。它们包括QSqlQueryModel、QSqlTableModel和QSqlRelationalTableModel。这些类被设计用于与Qt的模型/视图框架一起工作。

Note that a QCoreApplication object must be instantiated before using any of these classes.

Connecting to Databases

请注意,在使用这些类之前,必须实例化QCoreApplication对象。

连接到数据库

© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值