基于Oracle OCI的数据拜候C语言接口ORADBI-开辟技术[Oracle防范]
本文“基于Oracle OCI的数据拜候C语言接口ORADBI-开辟技术[Oracle防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
ORADBI是我在Oracle OCI(Oracle 调用接口)底子上开辟的,支持Oracle8i、9i、10g等数据库.按照Oracle公司的介绍:OCI是如此坚固,以至于Oracle数据库中的每一条SQL语句都通过OCI来履行.当利用程序开辟人员需求面向Oracle数据库服务器的最强盛的接口时,他们将调用 Oracle调用接口(OCI).OCI供应了对全部Oracle数据库功效的最全面的拜候.OCI API中包含了最新的性能、可伸缩性和安全性特点.
采取OCI的最大好处就是:它是最切近Oracle底层的技术,因此,效率是最高的.同时,它是跨平台的.因此,在我给出的ORADBI库,除了OCI之外,没有其他外部依靠,略加窜改,便可以移植到非Windows平台上或其他嵌入式平台.
但是,OCI也对比不简单利用.它的功效之强,粒度之细,语法之烦琐,都不合适本日熟习了快速开辟情势的人员利用.但是,OCI的高效,直接根植于数据库核心,跨平台的语言特点,是其他如OO4O、OLEDB、ADO等COM方法不具有的.我最初开辟Oralce数据库是4年从前,利用的是OO4O.直到近来,利用OCI成了我的爱好.于是,写了一套OCI的Helper库,便利OCI的利用.我不敢说是OCI的Wrapper库,因为我没本领包装OCI的各个方面.但是,我的ORADBI已经充足我(大概也包含你们)平常利用了.我就是用这套ORADBI操作BLOB等大数据字段的.
公布这套ORADBI库,没有任何商业上的风险:我拥有这个库的全部版权,任何个人或集体可认为任何目的免费地、无限制地利用ORADBI库,前提是不能声明对ORADBI库的版权.对利用ORADBI库所造成的任何后果,我不负任何责任.假如这套软件对您的工作产生了很大的帮忙,我不回绝任何您的赞助.
好了,让我们概览一下这个库,它包含下列文件:
.h文件 .c文件 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作为动态库衔接到你的工程里利用时,你在你的项目里加入近似下面的代码:
// test.cpp #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 */ ); |
以上是“基于Oracle OCI的数据拜候C语言接口ORADBI-开辟技术[Oracle防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |