最近在网上找到一个好东西SQLAPI ,他是能够访问多个SQL数据库(Oracle, SQL Server, DB2, Sybase, Informix, InterBase, SQLBase, MySQL, PostgreSQL)C 库。SQLAPI 直接调用本地目标数据库管理系统(DBMS)的API(不像ADO相同使用OLEDB and/or ODBC 中间层)。SQLAPI 库扮演了一个中间件以间接方便访问数据库的角色,这就是为什么SQLAPI 是访问数据库最快的方法。在研发和发布您的应用程式时不再需要安装和配置OLEDB and/or ODBC的驱动。
SQLAPI支持的研发平台有Microsoft Visual C ,Borland C Builder,Gun Project C and C Compiler。
示例代码如下:
#include <stdio.h> // for printf
#include <SQLAPI.h> // main SQLAPI header
int main(int argc, char* argv[])
{
SAConnection con; // 连接数据对象
SACommand cmd(
&con,
"Select fid, fvarchar20 from test_tbl");
// 命令对象,其中包含了一个查询语句,//您在测试的时候能够根据需要修改他。
// 本文转自 C Builder 研究 - http://www.ccrun.com/article.asp?i=1020&d=ssoqrd
try
{
// 连接数据库
// 在这个例程中连接的是Oracle数据库,
// 当然他也能够连接 Sybase, Informix, DB2
// SQLServer, InterBase, SQLBase and ODBC
con.Connect("test", "tester", "tester", SA_Oracle_Client);
// 执行查询语句
cmd.Execute();
// 显示查询后的结果
while(cmd.FetchNext())
{
printf("Row fetched: fid = %ld, fvarchar20 = '%s'\n",
cmd.Field("fid").asLong(),
(const char*)cmd.Field("fvarchar20").asString());
}
// 提交当前事务
con.Commit();
printf("Rows selected!\n");
}
catch(SAException &x)
{
// 异常处理
try
{
// 退出当前事务
con.Rollback();
}
catch(SAException &)
{
}
// 显示错误信息
printf("%s\n", (const char*)x.ErrText());
}
return 0;
}
SQLAPI 的官方网站是www.sqlapi.com,他提供评估版本给客户测试。可惜评估版本的库文档在连接数据库成功后,会弹出一个MessageBox对话框。我在测试他的时候觉得很烦,便把他破解掉了,假如需要能够到我的个人网站去下载他www.szsmart.net,但是只提供BCB的特别版本。
ccrun(老妖)注:也能够在本站下载:
http://www.ccrun.com/view.asp?id=430



