Oracle应用Linux开发C[4]

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

本文简介:

(sqlo_bind_by_name(sth, ":1", SQLOT_STR, packet_name, 64, NULL, 0)
))
{ printf("sqlo_bind_param failed failed: %sn", sqlo_geterror(dbh) );
return 0;
}
}
if (SQLO_SUCCESS != sqlo_execute(sth, 1))
{ printf("sqlo_execute failed: %sn", sqlo_geterror(dbh) );
return 0;
}
    上面的代码显示了如何通过名字绑定变量,“:1”在Oracle SQL语句中表示为一个变量(名字随意),在sqlo_bind_by_name函数中与packet_name变量绑定。在变量绑定完毕后,就可以调用sqlo_execute函数来执行这个SQL语句。
好了,我们已经向大家介绍了Libsqlora8的基本使用方法,如果希望了解更多内容,Libsqlora8的程序包中带有详细的说明和例子,大家不妨自己钻研一下。有什么心得,欢迎和我联系。E-mail:nick_chen@yeah.net


 


/*-------------------------------------------------------------------------
* testlora.c
* Test programm for libsqlora8(Kai Poitschke)
* Assuming you installed the library with prefix=/usr/local, the command
* to compile this is:
* gcc -o sample sample.c -lsqlora8 -L$ORACLE_HOME/lib -lclntsh
*-----------------------------------------------------------------------*/
#include
#include
#include


#include "sqlora.h"


#define MAX_ITERS 10


#define MAX_LOOPS 1 /* how many time we run the tests */


#define CLOSE_CURSOR 1


 


/*-------------------------------------------------------------------------
* create our test table
*-----------------------------------------------------------------------*/
int create_table( int dbh )
{
int nkey;
char ckey[6];
double nval;
char cval[21];
char dval[11];


int sth;


char * create_table =
"CREATE TABLE T_SQLORA_TEST (n"
"NKEY NUMBER(8) NOT NULL,n"
"CKEY VARCHAR2(5) NOT NULL,n"
"NVAL NUMBER(16,4) NULL,n"
"CVAL VARCHAR2(20) NULL,n"
"DVAL DATE)";



/* Check if the table already exists */
if (SQLO_NO_DATA ==
sqlo_exists(dbh, "USER_TABLES", "TABLE_NAME", "T_SQLORA_TEST", NULL))
{
/* No, create it */
if (SQLO_SUCCESS != sqlo_exec(dbh, create_table))
{
printf("create_table failed: %sn%sn", sqlo_geterror(dbh),
create_table);
return 0;
}
printf("Table T_SQLORA_TEST createdn");
}


return 1;
}


/*-------------------------------------------------------------------------
* Query the test table
*-----------------------------------------------------------------------*/
int do_select( int dbh )
{
int sd;
const char **v;
int argc;
const char *argv[1];
char * select_stmt =
"SELECT NKEY, CKEY, NVAL, CVAL, DVAL FROM T_SQLORA_TEST WHERE NKEY >= :1";


argc = 0;
argv[argc++] = "0";


/* Select all and display */
if (0>(sd = sqlo_open(dbh, select_stmt, argc, argv)))
{

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

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

go top