C++类库:OTL通用的数据库连接类库
来源:互联网 发布:远程教学软件开发公司 编辑:程序博客网 时间:2024/05/06 17:06
From: http://www.cppblog.com/lovefeel2004/archive/2010/06/02/116946.aspx
OTL是一个纯C++的通用数据库连接模板库,可以支持各种当下流行的数据库,如Oracle,Sybase, MySQL, PostgreSQL, EnterpriseDB, SQLite,
下载网址:http://otl.sourceforge.net/
OTL使用简单, 只要头文件中包含有: #include "otlv4.h" 就可,实际上整个OTL就一个.H的文件,使用起来极为的方便。
OTL使用方法:
1、首先指定要连接的数据库类型,OTL用宏定义来指定要连接的数据库类型。OTL会根据这个宏定义来初始化数据库连接的环境。
相关的宏定义列表 http://otl.sourceforge.net/otl3_compile.htm
如: #define OTL_ORA8I 表示连接Oracle 8i 数据库。
2、例子
#include <iostream>using namespace std;#include <stdio.h>#define OTL_ORA8I // 指定连接的数据库类型#include <otlv4.h> // include the OTL 4 header fileotl_connect db; // 定义数据库实例void insert()// 添加记录{otl_stream o(50, // buffer size"insert into test_tab values(:f1<float>,:f2<char[31]>)",// SQL statementdb // connect object);char tmp[32];for(int i=1;i<=100;++i){#if defined(_MSC_VER)#if (_MSC_VER >= 1400) // VC++ 8.0 or highersprintf_s(tmp,sizeof(tmp),"Name%d",i);#elsesprintf(tmp,"Name%d",i);#endif#elsesprintf(tmp,"Name%d",i);#endifo<<static_cast<float>(i)<<tmp;}}//查询记录void select(){otl_stream i(50, // buffer size"begin "" open :cur1 for "" select * from test_tab "" where f1>=:f<int> and f1<=:f*2; ""end;", // SELECT statement via referenced cursordb, // connect object":cur1" // referenced cursor placeholder name);// create select streamotl_column_desc* desc;int desc_len;i<<4; // Before the child SELECT statement can be described,// the PL/SQL master block needs to be executed.// Forcing the execution of the blcok by entering its input// patameter.desc=i.describe_select(desc_len);for(int n=0;n<desc_len;++n){cout<<"========== COLUMN #"<<n+1<<" ==========="<<endl;cout<<"name="<<desc[n].name<<endl;cout<<"dbtype="<<desc[n].dbtype<<endl;cout<<"otl_var_dbtype="<<desc[n].otl_var_dbtype<<endl;cout<<"dbsize="<<desc[n].dbsize<<endl;cout<<"scale="<<desc[n].scale<<endl;cout<<"prec="<<desc[n].prec<<endl;cout<<"nullok="<<desc[n].nullok<<endl;}}int main(){otl_connect::otl_initialize(); // 初始化Oracle环境try{db.rlogon("scott/tiger"); // 连接Oracleotl_cursor::direct_exec(db,"drop table test_tab",otl_exception::disabled // disable OTL exceptions); // drop tableotl_cursor::direct_exec(db,"create table test_tab(f1 number, f2 varchar2(30))"); // create tableinsert(); select();}catch(otl_exception& p){ // intercept OTL exceptionscerr<<p.msg<<endl; // print out error messagecerr<<p.stm_text<<endl; // print out SQL that caused the errorcerr<<p.var_info<<endl; // print out the variable that caused the error}db.logoff(); //断开数据库连接return 0;}
- C++类库:OTL通用的数据库连接类库
- C++类库:OTL通用的数据库连接类库
- otl 数据库连接
- C++/OTL 4.0, OTL connect类
- OTL翻译(3) -- OTL的主要类
- OTL翻译(3) -- OTL的主要类
- C#编写的OleDb数据库连接通用类库
- 使用boost的any和otl库来实现通用的数据库操作
- 用于获得数据库连接的通用类
- 使用C#打造通用的数据库连接类
- 使用C#打造通用的数据库连接类
- 使用C#打造通用的数据库连接类
- 使用C#打造通用的数据库连接类
- OTL 4.0, OTL 类
- ASP通用数据库连接类
- 通用数据库连接管理类
- 数据库连接通用类
- OTL的封装类使用说明
- 数据库面试
- C#2005 获取DataGridView选中行的值
- 第二周任务2
- 重载是如何实现的?
- memcached server LRU 深入分析
- C++类库:OTL通用的数据库连接类库
- 设计模式(C#)之迭代器模式(Iterator Pattern)
- 解决同一IP不同端口或跨域访问站点iframe应用session丢失的问与及ASP.NET 开发相关超时设置
- xStream完美转换XML、JSON
- APUE(UNIX环境高级编程)的源代码编译与调试
- ANDROID开发-ASSET中文件超过1M的解决方法
- jdbc连接mysql中文乱码处理
- vim 配置
- 沉得住气,积累