数据集
Jam.py 框架使用的数据集概念非常接近 Embarcadero Delphi 的数据集。
备注
还有其他读取和修改数据库数据的方法。 您可以使用 任务(task) 的 connect 方法从连接池获取连接,并使用该连接通过 Python Database API 访问数据库。
所有 item_type 为 “item” 或 “table” 的实体项以及它们的明细表
(参见 任务树)都可以从项目数据库的关联表中访问数据并写入更改。
它们都是 Item 类的对象
这两个类具有与数据处理相关的相同属性、方法和事件。
要从项目数据集表中获取数据集(一组记录),请使用 open 方法。此方法根据参数生成 SQL 查询以获取数据集。
数据集打开后,应用程序可以浏览它、更改其记录或插入新记录,并将更改写入实体的数据库表。
例如,以下函数将把 support_rep_id 字段值设置为客户端和服务器上 id 字段的值:
function set_support_id(customers) {
customers.open();
while (!customers.eof()) {
customers.edit();
customers.support_rep_id.value = customers.id.value;
customers.post();
customers.next();
}
customers.apply();
}
def set_support_id(customers):
customers.open()
while not customers.eof():
customers.edit()
customers.support_rep_id.value = customers.id.value
customers.post()
customers.next()
customers.apply();
这些函数将 客户(customers) 实体作为参数。然后使用 open 方法从客户表中获取记录列表,并修改每条记录。最后,使用 apply 方法将更改保存在数据库表中(参见 修改数据集 )。
备注
有一种更简短的浏览数据集的方法(参见 导航数据集 )。例如,在 Python 中,以下循环是等效的:
while not customers.eof():
print customers.firstname.value
customers.next()
for c in customers:
print c.firstname.value
视频
Datasets 和 Datasets Part 2 通过具体示例演示了几乎所有的数据集操作方法。