基于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值.但有时候进行数据记录插入的 ...
随机推荐
- 在Tomcat中配置基于springside的项目
注意点: Tomcat默认没有配置Transaction,需要在/Conf/Context.xml配置 1 <Transaction factory="org.objectweb.jo ...
- 第三十篇、iOS开发中常用的宏
//字符串是否为空 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str leng ...
- java新手笔记28 文件
1.目录.文件 package com.yfs.javase; import java.io.File; public class FileDemo1 { /** * File 目录 文件 */ pu ...
- 写在十年 2007-09-15 (写给L之三)
你知道吗? 那种时间很远,但心很近的感觉. 时间已经远去了十年, 但亲切的感觉依然清晰可见, 无论时光远去了十年,二十年,三十年, 永远…… 它已经植根,在心间……
- ArcSDE for oracle10g安装后post的时候出现错误
The Post Installation Setup can not locate required Oracle files in your path.Check your Oracle inst ...
- Java中的分代垃圾回收策略
一.分代GC的理论基础 分代的垃圾回收策略,是基于这样一个事实:不同的对象的生命周期是不一样的.因此,不同生命周期的对象可以采取不同的收集方式,以便提高回收效率. 在Java程序运行的过程中,会产生大 ...
- 【转】c#文件操作大全(二)
61.文件夹移动到整合操作 FolderDialog aa = new FolderDialog(); aa.DisplayDialog(); if (aa ...
- PHP服务器负载判断
<?php header("content-type:text/html;charset=utf-8"); // echo PHP_OS;exit; // echo get_ ...
- js判断屏幕分辨率的代码
通过下面的代码判断分辨率 <script language="JavaScript"> <!-- Begin function redirectPage() { ...
- Delphi代码优化
文章编目 1. 字符串优化 1.1. 不重复初始化 1.2. 使用SetLength预分配长字符串(AnsiString) 1.3. 字符串与动态数组的线程安全(Thread Safety) 1.4. ...