本示例程序基于对oci库方法的简单的封装,若要实验本程序,要求有linux下的oci库libclntsh.a或libclntsh.so。
下面是对其简单的封装:
#include <stdio.h>
#include "oratypes.h"
#include "ocidfn.h"
#ifdef __STDC__
#include "ociapr.h"
#else
#include "ocikpr.h"
#endif
#include "ocidem.h"
#define OCI_EXIT_FAILURE 1
#define OCI_EXIT_SUCCESS 0
#define
#define
#define
void logon1(Lda_Def *lda,ub1 *hda,text *user,text* passwd);
void logoff (Lda_Def *lda,Cda_Def
void openCurs(Cda_Def *cda_cur,Lda_Def *lda_cur);
void parseSql(Cda_Def *cda_cur,text *sqlStmt,Lda_Def *lda);
void defineIntOut(Cda_Def *cda,Lda_Def *lda,int *out,sword index);
void defineTextOut(Cda_Def *cda,Lda_Def *lda,text *out,sword index,sword size);
void err_report(Cda_Def
void do_exit(eword status);
void close_cursor(Cda_Def *cda_cur);
void execute_sql(Cda_Def *cda_cur,Lda_Def *lda);
void bind_sql(Cda_Def *cda,text *txt,ub1 *ub,int size,int SQL_TYPE,Lda_Def *lda);
///////////////////////////////
ocihelper.h实现部分ocihelper.cpp
#include <stdio.h>
#include <stdlib.h>
#include "ocihelper.h"
void logon(Lda_Def *lda,ub1 *hda,text *user,text* passwd)
{
}
void logon1(Lda_Def *lda,ub1 *hda,text *user,text* passwd)
{
}
void openCurs(Cda_Def *cda_cur,Lda_Def *lda_cur)
{
}
void parseSql(Cda_Def *cda_cur,text *sqlStmt,Lda_Def *lda)
{
}
void logoff(Lda_Def *lda,Cda_Def
{
}
void close_cursor(Cda_Def *cda_cur)
{
}
void execute_sql(Cda_Def *cda_cur,Lda_Def *lda)
{
}
void do_exit(eword status)
{
}
void err_report(Cda_Def
{
}
void defineIntOut(Cda_Def *cda,Lda_Def *lda,int *out,sword index)
{
}
void defineTextOut(Cda_Def *cda,Lda_Def *lda,text *out,sword index,sword size)
{
}
void bind_sql(Cda_Def *cda,text *txt,ub1 *ub,int size,int SQL_TYPE,Lda_Def *lda)
{
}
然后将其打包为库:在此以两种方法库的形式给出,使用方法一样:都指出库路径所在目录或放在默认目录下即可
打包为动态链接库:
g++ -o libocihelper.so
打包为静态链接库:
g++ -c ocihelper.cpp
ar -rc libocihelper.aocihelper.o libclntsh.a
////////////////////////////////////////////////////////////////////
下面是使用示例,首先定义全局变量,并包含头文件ocihelper.h
////////////////////////////////////////////////////////////////////////
1. select序列的值
2.insert表值
text *insertStmt=(text *)"insert into certlist values(:certid,:userinfo,:inputtime);
logon(&lda,(ub1 *)hda,(text *)"orausr",(text *)"ora123");
3.update表值
4.获取满足SQL条件的记录条数
void getDatabaseCount(text *sqlStmt,sword *count)
{
}