都在ocilib.h的头文件中
一,select 方式
1, 连接数据库的初始化变量及函数
OCI_Connection *cn=NULL;
//oracle连接句柄
OCI_Statement *st = NULL;
//oracle初始化系统句柄
OCI_Resultset *rs = NULL;
//oracle数据查询句柄
OCI_ConnectionCreate(g_cfg->DbName,g_cfg->DbUser,g_cfg->DbPwd,OCI_SESSION_DEFAULT)//初始化连接函数
//OCI_SESSION_DEFAULT是一个宏啊
函数原型
OCI_EXPORT OCI_Connection * OCI_API
OCI_ConnectionCreate
(
const mtext *db,
const mtext *user,
const mtext *pwd,
unsigned int mode
);
2,设置环境状态
st =
OCI_CreateStatement(cn)//初始化系统环境函数
函数原型
OCI_EXPORT OCI_Statement * OCI_API
OCI_StatementCreate
(
OCI_Connection *con
);
3,执行动态sql语句
OCI_ExecuteStmt(st,strSql);
4,捕捉返回结果的活动区句柄
rs = OCI_GetResultset(st);
if (!rs)
{
OCI_StatementFree(st);
OCI_ConnectionFree(cn);
return
false;
}
5,循环处理结果OCI_FetchNext(rs)
while (OCI_FetchNext(rs))
6, 对数据库中的字段转化为程序中的字段的处理函数
OCI_GetUnsignedInt2(rs,"flow_type"),
OCI_GetString2(rs,"module_name")
OCI_GetString2(rs,"user_name"),
OCI_GetDouble2(rs,"online_time"),
OCI_GetUnsignedInt2(rs,"login_count"),
7,处理完数据之后资源进行释放
OCI_ConnectionFree(cn);
函数原型
OCI_EXPORT boolean OCI_API
OCI_ConnectionFree
(
OCI_Connection *con
);
释放查询结果
OCI_ReleaseResultsets(st2);
释放环境状态
OCI_StatementFree(st2);
释放连接
OCI_ConnectionFree(cn2);
二, update, delete, insert 方式
sprintf(strSql,"delete from ubas_v5_key_details
where module_id=%u and day_time=%s ",module_id,date);
int ret =
OCI_Immediate(cn,strSql);//执行sql语句的句柄
if(!ret)
{
//
}
OCI_Commit(cn);//提交数据
OCI_ConnectionFree(cn);
***********************************************
OCI_ExecuteStmt(st,strSql);
//执行oracle中的sql语句
函数原型
OCI_EXPORT boolean OCI_API
OCI_ExecuteStmt
(
OCI_Statement *stmt,
const mtext *sql
);
rs =
OCI_GetResultset(st);//判断执行是否成功
函数原型
OCI_EXPORT OCI_Resultset * OCI_API
OCI_GetResultset
(
OCI_Statement *stmt
);
OCI_FetchNext(rs);//循环执行语句
ret =
OCI_Immediate(cn,strSql);//更新语句
原型
OCI_EXPORT boolean
OCI_Immediate
(
OCI_Connection *con,
const mtext *sql,
...
);
OCI_ExecuteStmt(st,strSql);
原型
OCI_EXPORT boolean OCI_API
OCI_ExecuteStmt
(
OCI_Statement *stmt,
const mtext *sql
);
rs = OCI_GetResultset(st);
原型
OCI_EXPORT OCI_Resultset * OCI_API
OCI_GetResultset
(
OCI_Statement *stmt
);
if (!rs)
{
OCI_StatementFree(st);
原型
OCI_EXPORT boolean OCI_API
OCI_StatementFree
(
OCI_Statement *stmt
);
OCI_ConnectionFree(cn);
原型
OCI_EXPORT boolean OCI_API
OCI_ConnectionFree
(
OCI_Connection *con
);
return false;
}
while (OCI_FetchNext(rs))
原型
OCI_EXPORT boolean OCI_API
OCI_FetchNext
(
OCI_Resultset *rs
);
Flowstat[i].user_count
= OCI_GetUnsignedInt2(rs, "USERS_CNT");
原型
OCI_EXPORT unsigned int OCI_API
OCI_GetUnsignedInt2
(
OCI_Resultset *rs,
const mtext *name
);
OCI_ReleaseResultsets(st);
//释放句柄
原型
OCI_EXPORT boolean OCI_API
OCI_ReleaseResultsets
(
OCI_Statement *stmt
);
OCI_Commit(cn);
原型
OCI_EXPORT boolean OCI_API
OCI_Commit
(
OCI_Connection *con
);
OCI_StatementFree(st);
原型
OCI_EXPORT boolean OCI_API
OCI_StatementFree
(
OCI_Statement *stmt
);
OCI_ConnectionFree(cn);
原型
OCI_EXPORT boolean OCI_API
OCI_ConnectionFree
(
OCI_Connection *con
);
m_UserMap.insert(pair(username,UserFlow));/map中插入键值对