來源:
http://read.newbooks.com.cn/info/157869.html
OTL介紹:
OTL 是 Oracle, Odbc and DB2-CLI Template Library 的縮寫,是一個(gè)C++編譯中操控關(guān)系數(shù)據(jù)庫(kù)的模板庫(kù),它目前幾乎支持所有的當(dāng)前各種主流數(shù)據(jù)庫(kù),例如Oracle, MS SQL Server, Sybase, Informix, MySQL, DB2, Interbase / Firebird, PostgreSQL, SQLite, SAP/DB, TimesTen, MS ACCESS等等。OTL中直接操作Oracle主要是通過Oracle提供的OCI接口進(jìn)行,進(jìn)行操作DB2數(shù)據(jù)庫(kù)則是通過CLI接口來進(jìn)行,至于MS的數(shù)據(jù)庫(kù)和其它一些數(shù)據(jù)庫(kù),則OTL只提供了ODBC來操作的方式。當(dāng)然Oracle和DB2也可以由OTL間接使用ODBC的方式來進(jìn)行操縱。
在MS Windows and Unix 平臺(tái)下,OTL目前支持的數(shù)據(jù)庫(kù)版本主要有:Oracle 7 (直接使用 OCI7), Oracle 8 (直接使用 OCI8), Oracle 8i (直接使用OCI8i), Oracle 9i (直接使用OCI9i), Oracle 10g (直接使用OCI10g), DB2 (直接使用DB2 CLI), ODBC 3.x ,ODBC 2.5。OTL最新版本為4.0,參見http://otl.sourceforge.net/,下載地址http://otl.sourceforge.net/otlv4_h.zip。
優(yōu)點(diǎn):
a. 跨平臺(tái)
b. 運(yùn)行效率高,與C語(yǔ)言直接調(diào)用API相當(dāng)
c. 開發(fā)效率高
d. 部署容易,不需要ADO組件,不需要.net framework 等
現(xiàn)提供有501個(gè)使用范例可參考http://otl.sourceforge.net/otl4_mssql_examples.htm。
OTL的使用:
OTL使用起來很簡(jiǎn)單,使用不同的數(shù)據(jù)庫(kù)連接(連接字符串格式可以參考:http://www.connectionstrings.com/),主要是根據(jù)需要在程序開始的宏定義來指定的。 OTL是首先根據(jù)這個(gè)宏定義來初始化數(shù)據(jù)庫(kù)連接環(huán)境。 OTL中用來區(qū)分連接方式的宏定義主要有下面這些:
OTL_ORA7, OTL_ORA8, OTL_ODBC, OTL_DB2_CLI, OTL_ODBC_MYSQL...
不同的宏對(duì)應(yīng)的數(shù)據(jù)庫(kù)API,具體說明如下:
|
宏定義名
|
說明
|
|
OTL_DB2_CLI
|
for DB2 Call Level Interface (CLI)
|
|
OTL_INFORMIX_CLI
|
for Informix Call Level Interface for Unix (when OTL_ODBC_UNIX is enabled).
|
|
OTL_IODBC_BSD
|
for ODBC on BSD Unix, when iODBC package is used
|
|
OTL_ODBC
|
for ODBC
|
|
OTL_ODBC_MYSQL
|
for MyODBC/MySQL. The difference between OTL_ODBC_MYSQL and OTL_ODBC is that transactional ODBC function calls are turned off for OTL_ODBC_MYSQL, since MySQL does not have transactions
|
|
OTL_ODBC_ POSTGRESQL
|
for the PostgreSQL ODBC driver 3.5 (and higher) that are connected to PostgerSQL 7.4 / 8.0 (and higher) servers.
|
|
OTL_ODBC_UNIX
|
for ODBC bridges in Unix
|
|
OTL_ODBC_zOS
|
for ODBC on IBM zOS.
|
|
OTL_ODBC_XTG_IBASE6
|
for Interbase 6.x via XTG Systems' ODBC driver. The reason for introducing this #define is that the ODBC driver is the only Open Source ODBC driver for Interbase. Other drivers, like Easysoft's ODBC for Interbase, are commercial products, and it beats the purpose of using Interbase, as an Open Source.database server.
|
|
OTL_ORA7
|
for OCI7
|
|
OTL_ORA8
|
for OCI8
|
|
OTL_ORA8I
|
for OCI8i
|
|
OTL_ORA9I
|
for OCI9i. All code that compiles and works under #define OTL_ORA7, OTL_ORA8, and OTL_ORA8I, should work when OTL_ORA9I is used
|
|
OTL_ORA10G
|
for OCI10g. All code that compiles and works under #define OTL_ORA7, OTL_ORA8, OTL_ORA8I, OTL_ORA9I, should work with OTL_ORA10G.
|
|
OTL_ORA10G_R2
|
for OCI10g, Release 2 (Oracle 10.2). All code that compiles and works under #define OTL_ORA7, OTL_ORA8, OTL_ORA8I, OTL_ORA9I, and OTL_ORA10G should work with OTL_ORA10G_R2 .
|
在編譯OTL的程序時(shí),需要使用到相應(yīng)的數(shù)據(jù)庫(kù)API,這就要程序在編譯時(shí)聯(lián)接lib庫(kù)文件,不同的數(shù)據(jù)庫(kù)對(duì)應(yīng)的lib文件所在位置各不相同,下面是分別在windows與Unix下的數(shù)據(jù)庫(kù)API所需要的頭文件及lib文件所在的位置列表:
|
API
|
API header files for Windows
|
API libraries for Windows
|
|
OCI7
|
In <ORACLE_HOME>\oci\include
|
<ORACLE_HOME>\oci\lib\<compiler_specific>\ociw32.lib
|
|
OCI8
|
In <ORACLE_HOME>\oci\include
|
<ORACLE_HOME>\oci\lib\<compiler_specific>\oci.lib
|
|
OCI8i
|
In <ORACLE_HOME>\oci\include
|
<ORACLE_HOME>\oci\lib\<compiler_specific>\oci.lib
|
|
OCI9i
|
In <ORACLE_HOME>\oci\include
|
<ORACLE_HOME>\oci\lib\<compiler_specific>\oci.lib
|
|
OCI10g
|
In <ORACLE_HOME>\oci\include
|
<ORACLE_HOME>\oci\lib\<compiler_specific>\oci.lib
|
|
ODBC
|
Normally, in one of the C++ compiler system directories, no need to include explicitly.
|
Normally, in one of the C++ compiler system directories: odbc32.lib
|
|
DB2 CLI
|
In <DB2_HOME>\include
|
<DB2_HOME>\lib\db2api.lib <DB2_HOME>\lib\db2cli.lib
|
如果在windows下操縱MS的 數(shù)據(jù)庫(kù),使用MS VC++來編譯OTL程序,就非常簡(jiǎn)單了,不用另外去找ODBC32.lib,VC的編譯器中已經(jīng)默認(rèn)link到工程中了,具體請(qǐng)看如何編譯OTL:http://otl.sourceforge.net/otl3_compile.htm。