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;
}