完全版 ESQL/C资料二( 七 )


一个源文件在数据库中可有多个PACKAGE存在 。为了区分不同的PACKAGE,DB2中引入了时间戳的概念 。在PREP执行时,系统对生成的修改过的C语言程序和BIND文件以及PACKAGE中都加入了一个时间戳 。BIND文件在生成PACKAGE时也将时间戳传递下来,修改过的C语言程序在生成可执行程序时,同样也将时间戳传递下去 。当应用程序运行时,可执行程序是通过时间戳找到相应的PACKAGE,如果时间戳不匹配,则说明版本更新,需要做BIND 。
本章第一个例子被编译后所生成的C程序:
static char sqla_program_id[40] =
{111,65,65,66,65,73,65,70,89,65,78,71,90,72,32,32,68,69,77,79,
68,66,50,32,67,65,51,54,75,75,67,81,48,49,49,49,49,50,32,32};
#include "sqladef.h"
static struct sqla_runtime_info sqla_rtinfo =
{{"S","Q","L","A","R","T","I","N"}, sizeof(wchar_t), 0, {" "," "," "," "}};
#line 1 "demodb2.sqc"
#include
#include
#include
#include "util.h"
#include
/*
EXEC SQL INCLUDE SQLCA;
*/
/* SQL Communication Area - SQLCA - structures and constants */
#include "sqlca.h"
struct sqlca sqlca;
#line 6 "demodb2.sqc"
#define CHECKERR(CE_STR) if (check_error (CE_STR, &sqlca) != 0) return 1;
int check_error (char eString[], struct sqlca *caPointer) {
char eBuffer[1024];
char sBuffer[1024];
short rc, Erc;
if (caPointer->sqlcode != 0) {
printf ("--- error report ---n");
printf ("ERROR occured : %s.nSQLCODE : %ldn", eString,
caPointer->sqlcode);
}
return 0;
}
int main(int argc, char *argv[]) {
/*
EXEC SQL BEGIN DECLARE SECTION;
*/
#line 21 "demodb2.sqc"
char firstname[13];
char userid[9];
char passwd[19];
/*
EXEC SQL END DECLARE SECTION;
*/
#line 25 "demodb2.sqc"printf( "Sample C program: STATICn" );
if (argc == 1) {
/*
EXEC SQL CONNECT TO sample;
*/
{
#line 28 "demodb2.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 28 "demodb2.sqc"
sqlaaloc(2,1,1,0L);
{
struct sqla_setd_list sql_setdlist[1];
#line 28 "demodb2.sqc"
sql_setdlist[0].sqltype = 460; sql_setdlist[0].sqllen = 7;
#line 28 "demodb2.sqc"
sql_setdlist[0].sqldata = https://www.rkxy.com.cn/dnjc/(void*)"sample";
#line 28 "demodb2.sqc"
sql_setdlist[0].sqlind = 0L;
#line 28 "demodb2.sqc"
sqlasetd(2,0,1,sql_setdlist,0L);
}
#line 28 "demodb2.sqc"
sqlacall((unsigned short)29,4,2,0,0L);
#line 28 "demodb2.sqc"
sqlastop(0L);
}
#line 28 "demodb2.sqc"
CHECKERR ("CONNECT TO SAMPLE");
}
else if (argc == 3) {
strcpy (userid, argv[1]);
strcpy (passwd, argv[2]);
/*
EXEC SQL CONNECT TO sample USER :userid USING :passwd;
*/
{
#line 34 "demodb2.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 34 "demodb2.sqc"
sqlaaloc(2,3,2,0L);
{
struct sqla_setd_list sql_setdlist[3];
#line 34 "demodb2.sqc"
sql_setdlist[0].sqltype = 460; sql_setdlist[0].sqllen = 7;
#line 34 "demodb2.sqc"
sql_setdlist[0].sqldata = https://www.rkxy.com.cn/dnjc/(void*)"sample";
#line 34 "demodb2.sqc"
sql_setdlist[0].sqlind = 0L;
#line 34 "demodb2.sqc"
sql_setdlist[1].sqltype = 460; sql_setdlist[1].sqllen = 9;
#line 34 "demodb2.sqc"
sql_setdlist[1].sqldata = https://www.rkxy.com.cn/dnjc/(void*)userid;
#line 34 "demodb2.sqc"
sql_setdlist[1].sqlind = 0L;
#line 34 "demodb2.sqc"
sql_setdlist[2].sqltype = 460; sql_setdlist[2].sqllen = 19;
#line 34 "demodb2.sqc"
sql_setdlist[2].sqldata = https://www.rkxy.com.cn/dnjc/(void*)passwd;
#line 34 "demodb2.sqc"
sql_setdlist[2].sqlind = 0L;
#line 34 "demodb2.sqc"
sqlasetd(2,0,3,sql_setdlist,0L);
}
#line 34 "demodb2.sqc"
sqlacall((unsigned short)29,5,2,0,0L);
#line 34 "demodb2.sqc"
sqlastop(0L);
}#line 34 "demodb2.sqc"
CHECKERR ("CONNECT TO SAMPLE");
}
else {
printf ("nUSAGE: static [userid passwd]nn");
return 1;
} /* endif */
/*
EXEC SQL SELECT FIRSTNME INTO :firstname
FROM employee
WHERE LASTNAME = "JOHNSON";

推荐阅读