Open Database Connectivity,ODBC

内容来源于网络


开放数据库互连(Open Database Connectivity,ODBC)是微软公司开放服务结构(WOSA,Windows Open Services Architecture)中有关数据库的一个组成部分,它建立了一组规范,并提供一组对数据库访问的标准API。这些API利用SQL来完成其大部分任务。ODBC本身也提供了对SQL语言的支持,用户可以直接将SQL语句送给ODBC。




应用程序
应用程序为用户提供交互界面。简单来说,应用程序藉 ODBC 界面执行下列主要工作:

1. Request a connection(i.e.session) with a data source. 

2. Send SQL requests to the data source. 

3. Define storage areas and data formats for the result of SQL requests. 

4. Request results. 

5. Process errors. 

6. Request a commit or rollback of operations for transcation control. 

7. Terminate a connection a data source.


Driver Manager 
驱动管理员本身在MS Windows中一个动态连接链接库文件(ODBC.DLL)。应用程序透过驱动管理员去加载并连接数据源的驱动程序(driver)并连接数据源。驱动管理员主要工作如下:
1. Uses ODBC INI file to map a data source name to a specific driver DLL.
2. Processes server ODBC initalization calls.
3. Provides entry points to ODBC functions for each driver.
4. Provides parameter validation and sequence validation for ODBC calls.
Device drivers are normally enumerated, set up and managed by a separate Manager layer, which may provide additional functionality. For instance, printing systems often include functionality to provide spooling functionality on top of the drivers, providing print spooling for any supported printer.
In ODBC the Driver Manager (DM) provides these features.The DM can enumerate the installed drivers and present this as a list, often in a GUI-based form.
But more important to the operation of the ODBC system is the DM's concept of Data Source Names, or DSN. DSNs collect additional information needed to connect to a particular data source, as opposed to the DBMS itself. For instance, the same MySQL driver can be used to connect to any MySQL server, but the connection information to connect to a local private server is different than the information needed to connect to an internet-hosted public server. The DSN stores this information in a standardized format, and the DM provides this to the driver during connection requests. The DM also includes functionality to present a list of DSNs using human readable names, and to select them at run-time to connect to different resources.
The DM also includes the ability to save partially complete DSN's, with code and logic to ask the user for any missing information at runtime. For instance, a DSN can be created without a required password. When an ODBC application attempts to connect to the DMBS using this DSN, the system will pause and ask the user to provide the password before continuing. This frees the application developer from having to create this sort of code, as well as having to know which questions to ask. All of this is included in the driver and the DSNs.

Drivers 
驱动程序也是一个动态连接链接库文件,当应用程序呼叫 ODBC  API SQLConnect 或 SQLDriverConnect时,驱动管理员就会加载相对的驱动程序与应用程序呼应。驱动程序主要是执行 ODBC 之相对API,并与对应的数据源(Data Source)做沟通。驱动程序之工作如下:
1. Establishes a connect to a data source.
2. Submits requests to a data sources.
3. Translates data to or from other formats,if requested by the application.
4. Return results to the application.
5. Formats errors into standard error codes and returns them to the application.
6. Declares and manipulates cursors if necessary (invisible to the application).
7. Initiates transactions if the data source requires explicit transaction initiation(invisible to the app).
ODBC is based on the device driver model, where the driver encapsulates the logic needed to convert a standard set of commands and functions into the specific calls required by the underlying system. For instance, a printer driver presents a standard set of printing commands, the API, to applications using the printing system. Calls made to those APIs are converted by the driver into the format used by the actual hardware, say PostScript or PCL.
In the case of ODBC, the drivers encapsulate a number of functions that can be broken down into several broad categories. One set of functions is primarily concerned with finding, connecting to and disconnecting from the DBMS that driver talks to. A second set is used to send SQL commands from the ODBC system to the DBMS, converting or interpreting any commands that are not supported internally. For instance, a DBMS that does not support cursors can emulate this functionality in the driver. Finally, another set of commands, mostly used internally, is used to convert data from the DBMS's internal formats to a set of standardized ODBC formats, which are based on the C language formats.
An ODBC driver enables an ODBC-compliant application to use a data source, normally a DBMS. Some non-DBMS drivers exist, for such data sources as CSV files, by implementing a small DBMS inside the driver itself. ODBC drivers exist for most DBMSs, including Oracle, PostgreSQL, MySQL, Microsoft SQL Server (but not for the Compact aka CE edition), Sybase ASE, and DB2. Because different technologies have different capabilities, most ODBC drivers do not implement all functionality defined in the ODBC standard. Some drivers offer extra functionality not defined by the standard.

应用程序要访问一个数据库,首先必须用ODBC管理器注册一个数据源,管理器根据数据源提供的数据库位置、数据库类型及ODBC驱动程序等信息,建立起ODBC与具体数据库的联系。这样,只要应用程序将数据源名提供给ODBC,ODBC就能建立起与相应数据库的连接。
  在ODBC中,ODBC API不能直接访问数据库,必须通过驱动程序管理器与数据库交换信息。驱动程序管理器负责将应用程序对ODBC API的调用传递给正确的驱动程序,而驱动程序在执行完相应的操作后,将结果通过驱动程序管理器返回给应用程序。
  在访问ODBC数据源时需要ODBC驱动程序的支持。用Visual C++ 5.0安装程序可以安装SQL Server、 Access、 Paradox、 dBase、 FoxPro、 Excel、 Oracle 和Microsoft Text等驱动程序.在缺省情况下,VC5.0只会安装SQL Server、 Access、 FoxPro和dBase的驱动程序.如果用户需要安装别的驱动程序,则需要重新运行VC 5.0的安装程序并选择所需的驱动程序。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值