简易的通用api wrapper: hisqlapi1.0.0.9发布

iihero_
《SybaseASE15.X全程实践》书籍作者
博客专家认证
2010-07-04 07:20:30
hisqlapi_1.0.0.9 数据库通用API: hisqlapi C++ wrapper
下载地址:
http://download.csdn.net/source/2515539

这是初始版本 for windows,目前支持ODBC, sqlite3
以及postgresql的一部分, 其它数据库的api wrapper在陆续开发中.

linux版本编译出来以后也会投放出来。

计划支持目标:
HiSQLAPI wrapper for MySQL
HiSQLAPI wrapper for PostgreSQL(已经完成一部分)
HiSQLAPI wrapper for Oracle (OCI)
HiSQLAPI wrapper for DB2 (CLI)
HiSQLAPI wrapper for ASE (openclient)
HiSQLAPI wrapper for SQL Server(ADO or OLEDB)

附加说明:
所有的库都是对最底层API的封装,同时又是松耦合,即使用hisqlapi里头的头文件,只有当你要连接具体的数据库时,它要用到的dll才会被加载。

1. 目前只提供了wrapper,总的接口并没有完全合笼。使用时可以直接使用具体类来操作sqlite3 (HiSQlite3Connection, HiSqlite3Statement, HiSqlite3ResultSet ...)
ODBC (HiODBCConnection, HiODBCStatement, HiODBCResultSet ...)

2. 使用时,不需要链接你原来的具体的库,只需要链接hisqlapi.lib, hisqlapi.dll即可,原始动态库,放到path里头即可。

3. 示例里有一个很简单的例子,来演示sqlite3的数据库操作:
	time_t t0; time(&t0);
HiSqlite3Connection conn;
try
{
conn.connect(dbPath, "", "");
conn.executeCmd("create table t(id int primary key, col2 varchar(32), col3 double, col4 blob)");
char sql[256];
conn.begin();
for (int i=0; i<1000; i++)
{
sprintf(sql, "insert into t(id, col2) values(%ld, 'xxx_%ld')", (i+1), (i+1));
conn.executeCmd(sql);
}
conn.commit();

memset(sql, 0, sizeof(sql));
sprintf(sql, "update t set col3 = :1, col4 = :col4 where id = :2");
HiSqlite3Statement* stmt = conn.prepareStatement(sql);
stmt->setDouble(1, 12345.45f);
HiMemStream ms;
for (int i=0; i<10000; i++)
{
ms<<i;
}
tblob_ lob;
ms.getData(lob);
stmt->setBlob(2, lob);
stmt->setInt(3, 1);
stmt->executeUpdate();
std::cout<<"after update, affected count = "<<stmt->affectedRows()<<std::endl;
delete stmt;

stmt = conn.createStatement();
HiSqlite3ResultSet* rset = stmt->executeQuery("select * from t where id = 1");
while (rset->next())
{
std::cout<<"col3 = "<<rset->getValue(3)<<std::endl;
}
rset->close();
delete rset;

delete stmt;

std::cout<<"default autocommit = " <<conn.getAutoCommit()<<std::endl;
conn.setAutoCommit(false);
std::cout<<"after set false, autocommit = " <<conn.getAutoCommit()<<std::endl;
conn.setAutoCommit(true);
std::cout<<"after set true, autocommit = " <<conn.getAutoCommit()<<std::endl;


conn.executeCmd("drop table t");
time_t t1; time(&t1);
std::cout<<"total time of testSqlite(insert): "<<difftime(t1, t0)<<" seconds"<<std::endl;

time(&t0);
conn.vacuumDB();
time(&t1);
std::cout<<"total time of testSqlite(vacuum db): "<<difftime(t1, t0)<<" seconds"<<std::endl;
}
catch (HiException& ex)
{
std::cout<<ex.errText()<<std::endl;
}

...全文
98 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
iihero_ 2010-07-04
  • 打赏
  • 举报
回复
嗯,有道理,我有时间整理一下子先。
ACMAIN_CHM 2010-07-04
  • 打赏
  • 举报
回复
iihero版主,最好能把你的资料整理一下,综合到一个贴子中。这样方便找资料的朋友下载。
ACMAIN_CHM 2010-07-04
  • 打赏
  • 举报
回复

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧