基于Oracle OCI的数据访问C语言接口ORADBI .
oradbi.h* oradbi.c
oracol.h oracol.c
oraconn.h oraconn.c
oradate.h oradate.c
oraerr.h oraerr.c
oraparam.h oraparam.c
orarows.h orarows.c
orastmt.h orastmt.c
oratype.h
unistd.h
list.h list.c
hashmap.h hashmap.c
其中,oradbi.h是你唯一需要包含的头文件。当把ORADBI作为动态库连接到你的工程里使用时,你在你的项目里加入类似下面的代码:
#include "../oradbi/oradbi.h"
#ifdef _DEBUG
#pragma comment(lib, "../oradbi/debug/oradbid.lib")
#else
#pragma comment(lib, "../oradbi/release/oradbi.lib")
#endif
下面是oradbi.h的全部内容:
oradbi.h - Created by cheungmine, All rights reserved.
First : Mar. 8, 2008
======================================================================*/
#ifndef ORADBI_H_INCLUDED
#define ORADBI_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ORADBI_DLLEXPORT
# define ORADB_CALL __declspec(dllexport)
# define ORADB_CALL1(x) __declspec(dllexport) x
#endif
#ifndef ORADB_CALL
# define ORADB_CALL
#endif
#ifndef ORADB_CALL1
# define ORADB_CALL1(x) x ORADB_CALL
#endif
/* NOT SUPPORT UNICODE */
#ifdef UNICODE
#pragma message( __FILE__" Warning UNICODE: Cannot use UNICODE" )
#endif
/* NOT SUPPORT UNICODE */
#ifdef _UNICODE
#pragma message( __FILE__" Warning UNICODE: Cannot use UNICODE" )
#endif
#include "unistd.h"
#include "oratype.h"
#include "oraerr.h"
/*======================================================================
connection Functions - oraconn.c
======================================================================*/
/* connects the application to the oracle server. */
lresult ORADB_CALL ORA_connection_create (
OUT ora_connection *connection,
IN const char *service_name,
IN const char *username,
IN const char *password,
IN ulong env_mode, /* =OCI_THREADED|OCI_OBJECT */
IN BOOL non_blocking_mode, /* =FALSE */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* disconnects the application from the oracle server. */
void ORADB_CALL ORA_connection_free (
IN ora_connection connection
);
/* executes a sql statement with no result */
lresult ORADB_CALL ORA_connection_execute (
IN ora_connection connection,
IN const char *sql_block,
IN int sql_len, /* -1 for strlen called*/
OUT ora_error_t *error /* NULL for no err msg return */
);
/* prepares (and returns) a sql statement for execution */
lresult ORADB_CALL ORA_connection_prepare (
IN ora_connection connection,
IN const char *sql_block,
IN int sql_len, /* -1 for strlen called*/
OUT ora_sqlstmt *sqlstmt, /* a sql statement for execution returned */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* executes a select sql statement and return the result set */
lresult ORADB_CALL ORA_connection_select (
IN ora_connection connection,
IN const char *sql_select,
IN int sql_len, /* -1 for strlen called*/
OUT ora_rowset *rowset, /* the result set returned */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* commits changes */
lresult ORADB_CALL ORA_connection_commit (
IN ora_connection connection,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* rollbacks changes */
lresult ORADB_CALL ORA_connection_rollback (
IN ora_connection connection,
OUT ora_error_t *error /* NULL for no err msg return */
);
/*======================================================================
sqlstmt Functions - orastmt.c
======================================================================*/
lresult ORADB_CALL ORA_sqlstmt_create (
OUT ora_sqlstmt *sqlstmt,
IN ora_connection connection,
IN const char *sql_block,
IN int sql_len, /* -1 for strlen to be called*/
IN ushort fetch_size, /* 0 for default or bind array size for INSERT */
OUT ora_error_t *error /* NULL for no err msg return */
);
void ORADB_CALL ORA_sqlstmt_free (
IN ora_sqlstmt sqlstmt
);
/* executes a sql statement with no output parameters */
lresult ORADB_CALL ORA_sqlstmt_execute (
IN ora_sqlstmt sqlstmt,
IN ORADBI_ExecMode mode, /* execute mode: MOD_DEFAULT=0 */
IN ushort iters, /* 0 is default */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* executes a select sql statement and returns the result set */
lresult ORADB_CALL ORA_sqlstmt_select (
IN ora_sqlstmt sqlstmt,
IN ORADBI_ExecMode mode, /* execute mode: MOD_DEFAULT=0 */
OUT ora_rowset *rowset,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* binds a named variable to sqlstmt but for lob, when type is set to ODT_UNKNOWN type is taken from name's prefix */
lresult ORADB_CALL ORA_sqlstmt_bind (
IN ora_sqlstmt sqlstmt,
IN const char *name, /* param name bound */
IN ORADBI_DataType type, /* param type bound. set ODT_UNKNOWN for simplely. cannot be a lob type */
IN int size, /* param size for TEXT, LOB. 0 for others */
OUT ora_param *param, /* a out param bound to sqlstmt */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* binds a named variable to sqlstmt only with lob type */
lresult ORADB_CALL ORA_sqlstmt_bind_lob (
IN ora_sqlstmt sqlstmt,
IN const char *name, /* param name bound */
IN int max_size, /* maximum size of lob data, 0 for default. if 0, client_data must be a valid pointer */
IN ORADBI_InBind *inbind, /* can be null. if null, max_size must be a meaningful value not more than 65535 */
IN ORADBI_OutBind *outbind, /* can be null */
OUT ora_param *param, /* a out param bound to sqlstmt */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* accesses param in the sqlstmt by name. gets a reference to param */
ora_param ORADB_CALL ORA_sqlstmt_get_param_by_name (
IN ora_sqlstmt sqlstmt,
IN const char* param_name, /* MUST be a valid name string */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* accesses param in the sqlstmt by index: 1-based. gets a reference to param */
ora_param ORADB_CALL ORA_sqlstmt_get_param_by_index (
IN ora_sqlstmt sqlstmt,
IN ushort param_index, /* PARAM_INDEX_BASE based */
OUT ora_error_t *error /* NULL for no err msg return */
);
/*======================================================================
rowset Functions - orarows.c
======================================================================*/
/* returns number of rows fetched so far */
lresult ORADB_CALL ORA_rowset_num_rows (
IN ora_rowset rowset,
OUT size_t *num_rows,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns number of columns */
lresult ORADB_CALL ORA_rowset_num_columns (
IN ora_rowset rowset,
OUT size_t *num_cols,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* fetches next row of record. TRUE for NOT completed; FALSE for completed */
BOOL ORADB_CALL ORA_rowset_next (
IN ora_rowset rowset
);
/* frees a ora_rowset. a freed rowset handle is an invalid pointer and cannot be used any more */
void ORADB_CALL ORA_rowset_free (
IN ora_rowset rowset
);
/* accesses column in the current row by name. gets a reference to column */
ora_column ORADB_CALL ORA_rowset_get_column_by_name (
IN ora_rowset rowset,
IN const char* col_name, /* MUST be a valid name string */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* accesses column in the current row by index: 1-based. gets a reference to column */
ora_column ORADB_CALL ORA_rowset_get_column_by_index (
IN ora_rowset rowset,
IN ushort col_index, /* COLUMN_INDEX_BASE based */
OUT ora_error_t *error /* NULL for no err msg return */
);
/*======================================================================
column Functions - oracol.c
======================================================================*/
/* returns column data type */
ORADB_CALL1(const char*) ORA_column_get_name (
IN ora_column column
);
/* returns column data type */
ORADBI_DataType ORADB_CALL ORA_column_get_type (
IN ora_column column
);
/* returns column display size */
size_t ORADB_CALL ORA_column_get_dispsize (
IN ora_column column
);
/* returns column precision of numberic data type */
int ORADB_CALL ORA_column_get_precision (
IN ora_column column
);
/* returns column scale of numberic data type */
int ORADB_CALL ORA_column_get_scale (
IN ora_column column
);
/* returns whether column is null ok */
BOOL ORADB_CALL ORA_column_is_null_ok (
IN ora_column column
);
/* returns whether column value is null */
BOOL ORADB_CALL ORA_column_is_null (
IN ora_column column
);
/* returns column value as string */
lresult ORADB_CALL ORA_column_as_string (
IN ora_column column,
OUT char **outval, /* Returns address of pointer to actual data */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns column value as double */
lresult ORADB_CALL ORA_column_as_double (
IN ora_column column,
OUT double *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns column value as float32 */
lresult ORADB_CALL ORA_column_as_float (
IN ora_column column,
OUT float *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns column value as long */
lresult ORADB_CALL ORA_column_as_long (
IN ora_column column,
OUT long *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns column value as unsigned long */
lresult ORADB_CALL ORA_column_as_ulong (
IN ora_column column,
OUT ulong *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns column value as int64 */
lresult ORADB_CALL ORA_column_as_longlong (
IN ora_column column,
OUT longlong *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns column value as uint64 */
lresult ORADB_CALL ORA_column_as_ulonglong (
IN ora_column column,
OUT ulonglong *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns column value as datetime */
lresult ORADB_CALL ORA_column_as_datetime (
IN ora_column column,
OUT ora_datetime *outval,
OUT ora_error_t *error
);
/* gets lob size for read. if a column isn't a LOB type or NULL, return 0 */
size_t ORADB_CALL ORA_column_lob_size (
IN ora_column column
);
/* read lob column value - pulling mode */
/* An example of pulling lob data with ORA_column_read_lob:
#define BUFF_SIZE 512
byte lob_buf[BUFF_SIZE];
lob_siz = ORA_column_lob_size (col);
lob_data = (byte*) malloc (lob_siz);
cb_offs = 0;
cb_read = BUFF_SIZE;
while ((rc=ORA_column_read_lob (col, lob_siz, cb_offs, lob_buf, &cb_read, &err))==ORC_NEED_DATA || rc==ORC_SUCCESS)
{
memcpy (lob_data+cb_offs, lob_buf, cb_read);
cb_offs += cb_read;
if (rc==ORC_SUCCESS)
break;
cb_read = BUFF_SIZE;
}
ASSERT (cb_offs == lob_siz);
*/
lresult ORADB_CALL ORA_column_read_lob (
IN ora_column column,
IN size_t lobsize_to_read, /* total bytes to read, usually is lob_size */
IN size_t cb_offset, /* offset bytes from the start of lob data */
INOUT byte* in_buf, /* when returned, in_buf has actual data */
INOUT size_t* cb_read, /* input is buf size and output is size of bytes be read */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns lob column value as bytes once for all. out_buf is allocated by caller for fetch bytes.
* buf_size is size of out_buf
* ORA_column_as_bytes calls ORA_column_read_lob internally.
*/
/* An example of pulling lob data with ORA_column_as_bytes:
size_t lob_size = ORA_column_lob_size (col);
byte* out_buf = malloc (lob_size);
ORA_column_as_bytes (col, out_buf, &lob_size, NULL);
...
free (out_buf);
*/
lresult ORADB_CALL ORA_column_as_bytes (
IN ora_column column,
INOUT byte* out_buf,
INOUT size_t* lob_size, /* size bytes of lob data which must <= size of buffer */
OUT ora_error_t *error /* NULL for no err msg return */
);
/*======================================================================
param Functions - oraparam.c
======================================================================*/
ORADBI_DataType ORADB_CALL ORA_param_get_type (
IN ora_param param
);
lresult ORADB_CALL ORA_param_set_long (
IN ora_param param,
IN long val,
OUT ora_error_t *error /* NULL for no err msg return */
);
lresult ORADB_CALL ORA_param_set_ulong (
IN ora_param param,
IN ulong val,
OUT ora_error_t *error /* NULL for no err msg return */
);
lresult ORADB_CALL ORA_param_set_longlong (
IN ora_param param,
IN longlong val,
OUT ora_error_t *error /* NULL for no err msg return */
);
lresult ORADB_CALL ORA_param_set_ulonglong (
IN ora_param param,
IN ulonglong val,
OUT ora_error_t *error /* NULL for no err msg return */
);
lresult ORADB_CALL ORA_param_set_datetime (
IN ora_param param,
IN ora_datetime val,
OUT ora_error_t *error /* NULL for no err msg return */
);
void ORADB_CALL ORA_param_set_null (
IN ora_param param
);
lresult ORADB_CALL ORA_param_set_float (
IN ora_param param,
IN float val,
OUT ora_error_t *error /* NULL for no err msg return */
);
lresult ORADB_CALL ORA_param_set_double (
IN ora_param param,
IN double val,
OUT ora_error_t *error /* NULL for no err msg return */
);
lresult ORADB_CALL ORA_param_set_string (
IN ora_param param,
IN const char *val,
IN short len, /* -1 for strlen called */
OUT ora_error_t *error /* NULL for no err msg return */
);
lresult ORADB_CALL ORA_param_set_bytes (
IN ora_param param,
IN const byte *in_buf,
IN ushort size_buf,
OUT ora_error_t *error /* NULL for no err msg return */
);
BOOL ORADB_CALL ORA_param_is_null (
IN ora_param param
);
/* returns column value as string */
lresult ORADB_CALL ORA_param_as_string (
IN ora_param param,
OUT char **outval, /* Returns address of pointer to actual data */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns param value as double */
lresult ORADB_CALL ORA_param_as_double (
IN ora_param param,
OUT double *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns param value as float32 */
lresult ORADB_CALL ORA_param_as_float (
IN ora_param param,
OUT float *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns param value as long */
lresult ORADB_CALL ORA_param_as_long (
IN ora_param param,
OUT long *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns param value as unsigned long */
lresult ORADB_CALL ORA_param_as_ulong (
IN ora_param param,
OUT ulong *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns param value as long */
lresult ORADB_CALL ORA_param_as_longlong (
IN ora_param param,
OUT longlong *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns param value as unsigned long */
lresult ORADB_CALL ORA_param_as_ulonglong (
IN ora_param param,
OUT ulonglong *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns param value as datetime */
lresult ORADB_CALL ORA_param_as_datetime (
IN ora_param param,
OUT ora_datetime *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/* returns param value as rowset */
lresult ORADB_CALL ORA_param_as_rowset (
IN ora_param param,
OUT ora_rowset *outval,
OUT ora_error_t *error /* NULL for no err msg return */
);
/*======================================================================
datetime Functions - oradate.c
======================================================================*/
/* creates a datetime opaque pointer which must be free after using */
lresult ORADB_CALL ORA_datetime_create (
OUT ora_datetime *dt /* must be a valid pointer */
);
lresult ORADB_CALL ORA_datetime_set_all (
IN ora_datetime dt,
IN short year, /* gregorian year; range is -4712 <= year <= 9999 */
IN ORADBI_DTMonth month, /* month; range is 1 <= month < 12 */
IN byte day, /* day; range is 1 <= day <= 31 */
IN byte hours, /* hours; range is 0 <= hours <=23 */
IN byte minutes, /* minutes; range is 0 <= minutes <= 59 */
IN byte seconds, /* seconds; range is 0 <= seconds <= 59 */
OUT ora_error_t *error /* NULL for no err msg return */
);
void ORADB_CALL ORA_datetime_get_all (
IN ora_datetime dt,
OUT short *year, /* gregorian year; range is -4712 <= year <= 9999 */
OUT ORADBI_DTMonth *month, /* month; range is 1 <= month < 12 */
OUT byte *day, /* day; range is 1 <= day <= 31 */
OUT byte *hours, /* hours; range is 0 <= hours <=23 */
OUT byte *minutes, /* minutes; range is 0 <= minutes <= 59 */
OUT byte *seconds /* seconds; range is 0 <= seconds <= 59 */
);
lresult ORADB_CALL ORA_datetime_set_fld (
IN ora_datetime dt,
IN ORADBI_DTField dt_field,
IN short dt_val,
OUT ora_error_t *error /* NULL for no err msg return */
);
short ORADB_CALL ORA_datetime_get_fld (
IN ora_datetime dt,
IN ORADBI_DTField dt_field
);
lresult ORADB_CALL ORA_string_to_datetime (
IN const char *dt_string, /* datetime string such as: 1975-08-14 12:53:42 */
IN char *dt_format, /* datetime format such as: yyyy-mm-dd hh:uu:ss */
OUT ora_datetime dt_to, /* datetime that string translated to */
OUT ora_error_t *error /* NULL for no err msg return */
);
lresult ORADB_CALL ORA_datetime_to_string (
IN ora_datetime dt_in, /* datetime to be translated */
IN char *dt_format, /* datetime format such as: yyyy-mm-dd hh:uu:ss */
OUT char *string_to, /* datetime string such as: 1975-08-14 12:53:42 */
OUT ora_error_t *error /* NULL for no err msg return */
);
/* frees a ora_datetime */
void ORADB_CALL ORA_datetime_free (
IN ora_datetime dt
);
#ifdef __cplusplus
}
#endif
/*====================================================================*/
#endif /* ndef ORADBI_H_INCLUDED . cheungmine@gmail.com */
您可以在下面的链接中下载整个工程(包含测试一个项目),用VS2005(VC8)打开、编译。如果有任何问题,可以留言或发e-mail给我。
http://download.csdn.net/source/399444
基于Oracle OCI的数据访问C语言接口ORADBI .的更多相关文章
- 数据访问层的接口IBaseDAL
using System; using System.Collections; using System.Data; using System.Data.Common; using System.Co ...
- MyBatis框架的XML数据访问Dao层接口的组合使用
MyBatis 的前生为Apache的开源项目iBatis.其优势在于灵活,几乎可以替代JDBC,同时提供了编程接口.目前MyBatis的数据访问Dao层不需要实现类,也不需要像JDBC那样拼接Hql ...
- Dojo Data Store——统一数据访问接口
原文地址:http://www.infoq.com/cn/articles/wq-dojo-data-store 无论在传统的桌面应用还是在主流的互联网应用中,数据始终占据着软件应用中的核心地位.当下 ...
- 支持SQL Server数据库又支持MongoDB数据库的数据访问设计
网站整体架构建议采用工厂模式 分别包括:数据访问层DAL,数据访问接口层IDAL,工厂层DALFactory,业务逻辑层,显示层这样的架构方式 在WebConfig配置采用何种数据库的数据访问层 &l ...
- servlet层调用biz业务层出现浏览器 500错误,解决方法 dao数据访问层 数据库Util工具类都可能出错 通过新建一个测试类复制代码逐步测试查找出最终出错原因
package com.swift.jztk.servlet; import java.io.IOException; import javax.servlet.ServletException; i ...
- 随机获得MySQL数据库中100条数据方法 驾照题库项目 MVC架构 biz业务层的实现类 根据考试类型rand或order通过dao数据访问层接口得到数据库中100或全部数据
package com.swift.jztk.biz; import java.util.Collections; import java.util.Comparator; import java.u ...
- 【转】在Spring中基于JDBC进行数据访问时怎么控制超时
http://www.myexception.cn/database/1651797.html 在Spring中基于JDBC进行数据访问时如何控制超时 超时分类 超时根据作用域可做如下层级划分: Tr ...
- ASP.NET Core 实战:基于 Dapper 扩展你的数据访问方法
一.前言 在非静态页面的项目开发中,必定会涉及到对于数据库的访问,最开始呢,我们使用 Ado.Net,通过编写 SQL 帮助类帮我们实现对于数据库的快速访问,后来,ORM(Object Relatio ...
- 基于SqlSugar的开发框架循序渐进介绍(4)-- 在数据访问基类中对GUID主键进行自动赋值处理
我们在设计数据库表的时候,往往为了方便,主键ID一般采用字符串类型或者GUID类型,这样对于数据库表记录的迁移非常方便,而且有时候可以在处理关联记录的时候,提前对应的ID值.但有时候进行数据记录插入的 ...
随机推荐
- 第六十五篇、OC_iOS7 自定义转场动画push pop
自定义转场动画,在iOS7及以上的版本才开始出现的,在一些应用中,我们常常需要定制自定义的的跳转动画 1.遵守协议:<UIViewControllerAnimatedTransitioning& ...
- OpenGL7-1-快速绘制接口(使用高效的函数接口进行绘制)
代码下载 #include "CELLWinApp.hpp"#include <gl/GLU.h>#include <assert.h>#include & ...
- javascript笔记——工作笔记
1.防止普通用户缓存静态文件,每次修改之后给静态文件的应用后面加上参数后缀[项目文件较多时最好使用前端构建工具] 比如: <script src="$!webPath/resource ...
- [GeekBand] 探讨C++新标准之新语法——C++ 11~14
一. 可变参数模板(Variadic Templates) 在C++11中,出现了参数数目可变的模板,这部分在之前C++高级编程的时候就有学习到. 其实,在C中就有类似的设定.最常用的printf() ...
- poj 3614 Sunscreen
...
- WiFi相关知识
1. 无线路由器的覆盖范围和带机量 覆盖范围取决于发射功率.接收灵敏度,以及对端的发射功率和接收灵敏度.因为Wi-Fi设备在发出数据包后,一定要等待对方回ACK才会确认发送成功,所以,如果任意一方的发 ...
- apache重写
---- 本文旨在提供如何用Apache重写规则来解决一些常见的URL重写方法的问题,通过常见的实例给用户一些使用重写规则的基本方法和线索. 一.为什么需要用重写规则 ---- 网站的生命在于不断地进 ...
- 【ASP.NET+MVC4+Web+编程】读书笔记
模型:数据和业务逻辑 视图:展示 控制器:接收视图输入数据,通过模型层业务逻辑处理后 返回给视图 分离关注点(模型 视图 控制器).惯例优先原则 browser-->routing-->c ...
- Jquery-zTree的基本用法
[简介] zTree 是利用 JQuery 的核心代码,实现一套能完成大部分常用功能的 Tree 插件 兼容 IE.FireFox.Chrome 等浏览器 在一个页面内可同时生成多个 Tree 实例 ...
- present的时候是可以直接回到第一个viewcon的
最新:我并没有记错,是可以直接回到的 [self.presentingViewController.presentingViewController dismissModalViewControlle ...