Oracle应用Linux开发C[3]

[入库:2005年9月21日] [更新:2007年3月24日]

本文简介:

5)int sqlo_close(int sth) 关闭由上一个函数打开的游标。
6)int sqlo_fetch(int sth) 从打开的游标中获取一条记录,并将之存入一个已分配内存空间中。
7)const char **sqlo_values(int sth, int *numbalues, int dostrip) 从内存中返回上一次sqlo_fetch取得的值,是以字符串形式返回的。
8)以下介绍另一种检索方式,int sqlo_prepare(int dbh, char const *stmt),返回一个打开的游标sth。
9)int sqlo_bind_by_name(int sth, const char * param_name, int param_type, const void * param_addr, unsigned int param_size, short * ind_arr, int is_array) 将查询语句的传入参数,按照名字的形式与函数中的变量绑定。如果你使用数组,那么参数param_addr和ind_arr必须指向该数组。
int sqlo_bind_by_pos(int sth, int param_pos, int param_type, const void * param_addr, unsigned int param_size, short * ind_arr, int is_array) 将查询语句的传出值,按照位置顺序与函数中的变量绑定。
10)int sqlo_execute(int sth, int iterations) 执行查询语句。“Iterations”可设为“1”。
11)在执行完数据库操作后,我们可用int sqlo_commit (int dbh)提交操作,或用int sqlo_rollback(int dbh)回滚操作。
12)Libsqlora8还有其他一些操作函数,这里就不一一列出了。
下面举几个例子说明这些函数如何使用。
cstr = "ocitest/ocitest"; //用户名/口令
status = sqlo_init(0);
if (SQLO_SUCCESS != status)
{ printf ("sql_init failed. Exitingn");
exit(1);
}
status = sqlo_connect(&dbh, cstr); // int dbh
以上源代码,显示了如何连接数据库
/* Select all and display */
char *select_stmt="SELECT cname, clength, colid FROM ocicolu";
if (0>(sd = sqlo_open(dbh, select_stmt, 0, NULL)))
{ printf("sqlo_open failed: %sn", sqlo_geterror(dbh));
return 0;
}
while (0 == sqlo_fetch(sd,1))
{ v = sqlo_values(sd, NULL, 1);
printf("Result: %sn",v);
}
if (0 > sqlo_close(sd))
{ printf("sqlo_open failed: %sn", sqlo_geterror(dbh));
return 0;
}
以上例子展示了第一种查询方法,显然,这种方法较简单,但不够灵活。
char *update_stmt =
"UPDATE ocitest.upload_log SET upload_fresh = where log_name = :1";
if (0 <= (sth = sqlo_prepare(dbh, update_stmt)))
{ if (SQLO_SUCCESS !=

本文关键:Oracle应用Linux开发C
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top