Oracle8的OCI编程步骤

7 篇文章 0 订阅
5 篇文章 1 订阅

Oracle8的OCI编程步骤

The following section describes the stepsthat are required of a release 8.0 OCI application:

·Initialization,connection, and Session Creation初始化、连接和创建会话

·Processing SQLStatements        处理SQL语句

·Commit or Rollback    提交事务或者回滚事务

·Terminating the Application终止应用程序

·Error Handling    错误处理

1.      Initialization, connection, andSession Creation初始化、连接和创建会话

This section describes how to initialize theOracle 8 OCI environment, establish a connection to a server, and authorize auser to perform actions against a database.

The three main steps in initializing the OCIenvironment are described in this section:

1.1  Initialize the OCI Process 初始化OCI进程

Initialize the OCI Process 初始化OCI进程

Allocate Handles and Descriptors 分配句柄和描述符

Initialize the Application, Connection, and Authorization 初始化应用程序、连接和认证Allocate Handles and Descriptors     分配句柄和描述符

The initialize process call, OCIInitialize(),must be invoked before any other OCI call. The mode parameter of this call specifieswhether the application will run in a threaded environment (mode =OCI_THREADED), and whether or not it will use objects (mode = OCI_OBJECT).Initializing in object mode is necessary if the application will be binding anddefining objects, or if the application will be using the OCI’s objectnavigation calls.

The program may also choose to use neither of thesefeatures (mode = OCI_DEFAULT) or both, separating the options with avertical bar (mode = (OCI_THREADED | OCI_OBJECT)).

The OCIInitialize() call can also specifyuser-defined memory management functions.

Allocate Handles and Descriptors         分配句柄和描述符

Oracle provides OCI functions to allocate and deallocatehandles and descriptors. You must allocate handles using OCIHandleAlloc() beforepassing them into an OCI call, unless the OCI call allocates the handles for you(e.g. OCIBindByPos()).

 

Initialize theApplication, Connection, and Authorization 初始化应用程序、连接和认证

Anapplication must call OCIEnvCreate() to initialize the OCI environment handle.

Followingthis step, the application has two options for establishing a server connectionand beginning a user session: Single User, Single Connection; or MultipleSessions or Connections.

1.      Option1:Single User, Single Connection

2.      Option2:Multiple Sessions or Connections

Thisoption uses explicit attach and begin session calls.

Ifan application needs to maintain multiple user sessions on a databaseconnection, the application requires a different set of calls to set up thesessions and connections. This includes specific calls to attach to the serverand begin sessions:

·OCIServerAttach() creates an access path to the data server for OCIoperations.

·OCISessionBegin() establishes a session for a user against a particularserver. This call is required for the user to be able to execute any operationon the server.

Thesecalls set up an operational environment that allows you to execute SQL andPL/SQL statements against a database. The database must be up and runningbefore the calls are made, or else they will fail.

 

Terminating theApplication

AnOCI application should perform the following three steps before it terminates:

1.      Deletethe user session by calling OCISessionEnd() for each session.

2.      Deleteaccess to the data source(s) by calling OCIServerDetach() for each source.

3.      Explicitlydeallocate all handles by calling OCIHandleFree() for each handle.

4.      Deletethe environment handle, which deallocates all other handles associated with it.

Note: When a parent OCI handle is freed, anychild handles associated with it are freed automatically.

Thecalls to OCIServerDetach() and OCISessionEnd() are not mandatory, but are recommended.If the application terminates, and OCITransCommit() (transaction commit) hasnot been called, any preceding transactions are automatically rolled back.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值