2012年(27)
分类: SQLite/嵌入式数据库
2012-04-15 20:53:10
A Template For SELECT Programs
The first two query examples illustrate a kind of template that every SELECT program will follow. Basically, we have:
SELECT程序的模板
前两个查询的例子说明SELECT程序遵从的模板,基本上,我们需要做的:
1. Initialize the azColumnName[] array for the callback.
为回调函数初始化azColumnName
2. Open a cursor into the table to be queried.
为要查询的表打开游标
3. For each record in the table, do:
对于表中每条记录,要做到:
a. If the WHERE clause evaluates to FALSE, then skip the steps that follow and continue to the next record.
如果where子语句判断为FALSE,跳过该记录,然后处理下一条记录
b. Compute all columns for the current row of the result.
计算当前结果行的所有列
c. Invoke the callback function for the current row of the result.
为当前结果的行调用回调函数
4. Close the cursor.
关闭游标
This template will be expanded considerably as we consider additional complications such as joins, compound selects, using indices to speed the search, sorting, and aggregate functions with and without GROUP BY and HAVING clauses. But the same basic ideas will continue to apply.
当我们考虑其他操作,如连接,复合选择,使用索引加快搜索,排序,使用或者不适用GROUPBY和HAVING子语句等都会使这个模板大大扩展。但是基本的思路不变。