DB2嵌入式静态SQL应用与实践
2012-04-29陈景彦
陈景彦
摘要:随着计算机技术的飞速发展,DB2以其具有的通用性与高效运行的巨大优势渗透到各行各业中,面对越来越大的数据信息处理这一问题,如何提高效率、避免庞大的数据库系统被重复编译,增强应用时的可维护性,使得数据库对每条SQL语句可以先择最优的运行。以下从理论出发,结合例程,阐述了静态SQL的应用。
关键词:嵌入式;静态SQL;游标
中图分类号:TP311文献标识码:A文章编号:1009-3044(2012)12-2667-04
DB2 Embedded Static SQL Application and Practice
CHEN Jing-yan
(Medical College of Shantou University, Shantou 515041, China)
Abstract:With the rapid development of computer technology, with the DB2 for its versatility and efficient operation of the great advan tages of penetration into all walks of life, in the face of increasing data and information to deal with this issue, how to improve efficiency, to avoid a huge databaserepeat the compilation, and enhance the maintainability of the application, making the database for each SQL state ment, you can choose the optimal operation. The following from the theory, combined with the routine, described the application of static SQL.
Key words:embedded; static SQL; cursor
1概述
一个嵌入式SQL应用程序文件就是一个含有SQL语句,且带有特殊扩展名的文该文件。在开始进行嵌入式SQL应用程序开发前,首先需要了解如何把这样一个文件转化成宿主语言编译器可以识别和处理的格式,如何同数据库服务器进行交互、对数据进行查询修改和删除等操作,以及如何构建可执行的程序,文章源代码均用C语言。
2构建嵌入式SQL应用程序过程
建立一个嵌入式SQL应用程序前,我们应对其用发中常用的基本概今有一定了解,其具体步骤分为:
2.1开发环境
使用文本编辑器或者集成开发环境(IDE)编辑源文件。
2.2预编译
在程序文件编辑完成后,应预编译每个连接到数据库的源程序文件。无论是嵌入式静态SQL还是嵌入式动态SQL,都需要先进行预编译,并绑定到特定的数据库。它将源文件中的SQL语句注释掉,并把SQL语句替换成DB2运行时的API调用,这些API调用是源语言编译器能够理解的函数调用,预编工作由预编译器来完成。
预编译命令:
Precompile filename [参数名可用数值]…
PREP filename [参数名可用数值]…
