使用OTL来访问数据库

OTL介绍:
OTL Oracle, Odbc and DB2-CLI Template Library 的缩写,是一个C++编译中操控关系数据库的模板库,它目前几乎支持所有的当前各种主流数据库,例如Oracle, MS SQL Server, Sybase, Informix, MySQL, DB2, Interbase / Firebird, PostgreSQL, SQLite, SAP/DB, TimesTen, MS ACCESS等等。OTL中直接操作Oracle主要是通过Oracle提供的OCI接口进行,进行操作DB2数据库则是通过CLI接口来进行,至于MS的数据库和其它一些数据库,则OTL只提供了ODBC来操作的方式。当然OracleDB2也可以由OTL间接使用ODBC的方式来进行操纵。

MS Windows and Unix 平台下,OTL目前支持的数据库版本主要有:Oracle 7 (直接使用 OCI7), Oracle 8 (直接使用 OCI8), Oracle 8i (直接使用OCI8i), Oracle 9i (直接使用OCI9i), Oracle 10g (直接使用OCI 10g ), DB2 (直接使用DB2 CLI), ODBC 3.x ,ODBC 2.5OTL最新版本为4.0,参见http://otl.sourceforge.net/,下载地址http://otl.sourceforge.net/otlv4_h.zip
优点:
      a.
跨平台
      b.
运行效率高,与C语言直接调用API相当
      c.
开发效率高
      d.
部署容易,不需要ADO组件,不需要.net framework
     
现提供有501个使用范例可参考http://otl.sourceforge.net/otl4_mssql_examples.htm

OTL的使用:

   OTL使用起来很简单,使用不同的数据库连接(连接字符串格式可以参考:http://www.connectionstrings.com/),主要是根据需要在程序开始的宏定义来指定的。 OTL是首先根据这个宏定义来初始化数据库连接环境。 OTL中用来区分连接方式的宏定义主要有下面这些:
 OTL_ORA7, OTL_ORA8, OTL_ODBC, OTL_DB2_CLI, OTL_ODBC_MYSQL...

不同的宏对应的数据库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_ORA 10G

for OCI 10g . All code that compiles and works  under #define OTL_ORA7, OTL_ORA8, OTL_ORA8I, OTL_ORA9I, should work with OTL_ORA 10G .

OTL_ORA 10G _R2

for OCI 10g , Release 2 (Oracle 10.2). All code that compiles and works  under #define OTL_ORA7, OTL_ORA8, OTL_ORA8I, OTL_ORA9I, and OTL_ORA 10G should work with OTL_ORA 10G _R2 .

  在编译OTL的程序时,需要使用到相应的数据库API,这就要程序在编译时联接lib库文件,不同的数据库对应的lib文件所在位置各不相同,下面是分别在windowsUnix下的数据库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

OCI 10g

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 数据库,使用MS VC++来编译OTL程序,就非常简单了,不用另外去找ODBC32.libVC的编译器中已经默认link到工程中了,具体请看如何编译OTLhttp://otl.sourceforge.net/otl3_compile.htm

 

你可能感兴趣的:(oracle,数据库,unix,db2,PostgreSQL,Informix)