最近在網上找到一個好東西SQLAPI++,它是可以訪問多個SQL數(shù)據(jù)庫(Oracle, SQL Server, DB2, Sybase, Informix, InterBase, SQLBase, MySQL, PostgreSQL)C++庫。SQLAPI++直接調用本地目標數(shù)據(jù)庫管理系統(tǒng)(DBMS)的API(不像ADO一樣使用OLEDB and/or ODBC 中間層)。SQLAPI++庫扮演了一個中間件以間接方便訪問數(shù)據(jù)庫的角色,這就是為什么SQLAPI++是訪問數(shù)據(jù)庫最快的方法。在開發(fā)和發(fā)布您的應用程序時不再需要安裝和配置OLEDB and/or ODBC的驅動。
SQLAPI支持的開發(fā)平臺有Microsoft Visual C++,Borland C++ Builder,Gun Project C and C++ Compiler。
示例代碼如下:
#include <stdio.h> #include <SQLAPI.h> 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
{
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,它提供評估版本給客戶測試。可惜評估版本的庫文件在連接數(shù)據(jù)庫成功后,會彈出一個MessageBox對話框.