没有合适的资源?快使用搜索试试~ 我知道了~
首页Oracle C/C++接口详解:12c Release 1开发者指南
Oracle C/C++调用接口是Oracle数据库12c Release 1 (12.1)中的一个重要部分,它为开发人员提供了一种在C和C++程序中与Oracle数据库进行高效交互的桥梁。Oracle Call Interface (OCI) 是Oracle官方推荐的用于C和C++语言的应用程序编程接口,允许开发者利用标准的C/C++语法来访问Oracle数据库的各种功能,如存储过程、数据操作、事务处理等。
该指南详细介绍了如何使用Oracle Call Interface进行数据库连接、数据操作、错误处理以及性能优化等方面的技术。它不仅包含了基础概念,如预编译SQL语句(PL/SQL)、结果集处理和数据类型转换,还深入探讨了高级主题,如异步IO、内存管理、线程安全性和安全性设置。
编写Oracle C/C++应用程序时,程序员需要熟悉以下关键知识点:
1. **环境准备**:安装Oracle数据库客户端库,配置动态链接库路径和环境变量,确保头文件和链接器能够找到必要的库函数。
2. **连接数据库**:通过oci.h头文件中的函数,如ociEnvCreate()和ociConnectionCreate(),建立与Oracle数据库的连接。
3. **执行SQL语句**:使用ociStmtPrepare()和ociStmtExecute()执行预编译的SQL(PL/SQL)代码,或者ociCall()执行存储过程。
4. **处理结果集**:通过ociResultFetch()获取查询结果,ociBind*()方法绑定参数,ociErrorHandle()用于处理错误和警告。
5. **事务管理**:理解如何使用ociCommit()和ociRollback()进行事务控制,确保数据一致性。
6. **内存管理**:了解Oracle Call Interface的内存分配策略,以及如何正确释放资源以避免内存泄漏。
7. **并发和线程安全**:掌握ociAttrSet()和ociAttrGet()等函数,设置和检查对象的并发属性,确保在多线程环境下操作的正确性。
8. **错误处理和调试**:学习如何使用ociErrorGet()获取错误信息,以及如何使用ociDebugLog()记录调试信息。
9. **性能优化**:了解Oracle Call Interface的优化选项,如使用BULK COLLECT操作符提高数据传输效率。
Oracle Call Interface文档由多位Oracle专家共同编写,包括Rod Ward、Jack Melnick等,他们从不同角度提供了丰富的实践经验和技术指导。这份指南不仅是初学者学习Oracle数据库编程的入门资料,也是经验丰富的开发人员进行高级编程和性能调优的重要参考。随着Oracle技术的不断发展,这份文档也会不断更新,以适应新的需求和功能。
xvi
Failover Callback Example ............................................................................................................ 9-30
Handling OCI_FO_ERROR ........................................................................................................... 9-31
HA Event Notification.......................................................................................................................... 9-33
OCIEvent Handle............................................................................................................................ 9-34
OCI Failover for Connection and Session Pools......................................................................... 9-34
OCI Failover for Independent Connections................................................................................ 9-35
Event Callback................................................................................................................................. 9-35
Custom Pooling: Tagged Server Handles.................................................................................... 9-36
Determining Transparent Application Failover (TAF) Capabilities........................................ 9-37
OCI and Transaction Guard................................................................................................................ 9-37
Developing Applications that Use Transaction Guard ............................................................. 9-38
Typical Transaction Guard Usage......................................................................................... 9-38
Transaction Guard Examples................................................................................................. 9-39
OCI and Streams Advanced Queuing............................................................................................... 9-44
OCI Streams Advanced Queuing Functions............................................................................... 9-45
OCI Streams Advanced Queuing Descriptors............................................................................ 9-45
Streams Advanced Queuing in OCI Versus PL/SQL................................................................ 9-46
Buffered Messaging ........................................................................................................................ 9-49
Publish-Subscribe Notification in OCI ............................................................................................ 9-50
Publish-Subscribe Registration Functions in OCI...................................................................... 9-52
Publish-Subscribe Register Directly to the Database.......................................................... 9-52
Open Registration for Publish-Subscribe ............................................................................. 9-55
Using OCI to Open Register with LDAP.............................................................................. 9-55
Setting QOS, Timeout Interval, Namespace, Client Address, and Port Number .......... 9-57
OCI Functions Used to Manage Publish-Subscribe Notification...................................... 9-57
Notification Callback in OCI ......................................................................................................... 9-58
Notification Procedure ................................................................................................................... 9-60
Publish-Subscribe Direct Registration Example......................................................................... 9-61
Publish-Subscribe LDAP Registration Example......................................................................... 9-66
10 More OCI Advanced Topics
Continuous Query Notification.......................................................................................................... 10-1
About Continuous Query Notification........................................................................................ 10-1
Database Startup and Shutdown ....................................................................................................... 10-2
About OCI Database Startup and Shutdown.............................................................................. 10-2
Examples of Startup and Shutdown in OCI................................................................................ 10-3
Implicit Fetching of ROWIDs............................................................................................................. 10-5
About Implicit Fetching of ROWIDs............................................................................................ 10-5
Example of Implicit Fetching of ROWIDs................................................................................... 10-7
OCI Support for Implicit Results....................................................................................................... 10-8
Client Result Cache............................................................................................................................. 10-10
Client Statement Cache Auto-Tuning............................................................................................. 10-11
About Auto-Tuning Client Statement Cache............................................................................ 10-11
Benefit of Auto-Tuning Client Statement Cache ...................................................................... 10-12
Client Statement Cache Auto-Tuning Parameters ................................................................... 10-12
<statement_cache>................................................................................................................. 10-12
<auto_tune>............................................................................................................................ 10-12
xvii
<enable>true</enable>................................................................................................. 10-12
<ram_threshold> ............................................................................................................ 10-12
<memory_target>........................................................................................................... 10-13
Comparison of the Connection Specific Auto-Tuning Parameters ................................ 10-13
Usage Examples of Client Statement Cache Auto Tuning...................................................... 10-14
Enabling and Disabling OCI Client Auto-Tuning.................................................................... 10-15
Usage Guidelines for Auto-Tuning Client Statement Cache.................................................. 10-15
OCI Client-Side Deployment Parameters Using oraaccess.xml ................................................ 10-16
About oraaccess.xml..................................................................................................................... 10-16
About Client-Side Deployment Parameters Specified in oraaccess.xml............................... 10-16
High Level Structure of oraaccess.xml....................................................................................... 10-16
Specifying Global Parameters in oraaccess.xml ....................................................................... 10-17
Specifying Defaults for Connection Parameters....................................................................... 10-19
Overriding Connection Parameters at the Connection-String Level..................................... 10-21
File (oraaccess.xml) Properties.................................................................................................... 10-25
Fault Diagnosability in OCI.............................................................................................................. 10-25
About Fault Diagnosability in OCI............................................................................................. 10-26
ADR Base Location ....................................................................................................................... 10-26
Using ADRCI................................................................................................................................. 10-27
Controlling ADR Creation and Disabling Fault Diagnosability Using sqlnet.ora .............. 10-29
Client and Server Operating with Different Versions of Time Zone Files ............................. 10-30
Support for Pluggable Databases..................................................................................................... 10-31
Restrictions on OCI API Calls with Multitenant Container Databases (CDB) in General. 10-31
Restrictions on OCI Calls with ALTER SESSION SET CONTAINER................................... 10-31
Using the XStream Interface ............................................................................................................. 10-33
XStream Out................................................................................................................................... 10-33
LCR Streams ........................................................................................................................... 10-33
The Processed Low Position and Restart Considerations................................................ 10-34
XStream In...................................................................................................................................... 10-34
Processed Low Position and Restart Ability...................................................................... 10-34
Stream Position....................................................................................................................... 10-35
Security of XStreams..................................................................................................................... 10-35
11 OCI Object-Relational Programming
OCI Object Overview........................................................................................................................... 11-1
Working with Objects in OCI............................................................................................................. 11-2
Basic Object Program Structure .................................................................................................... 11-2
Persistent Objects, Transient Objects, and Values..................................................................... 11-3
Persistent Objects ..................................................................................................................... 11-3
Transient Objects...................................................................................................................... 11-4
Values ........................................................................................................................................ 11-4
Developing an OCI Object Application ........................................................................................... 11-5
Representing Objects in C Applications ...................................................................................... 11-5
Initializing the Environment and the Object Cache................................................................... 11-6
Making Database Connections...................................................................................................... 11-7
Retrieving an Object Reference from the Server ........................................................................ 11-7
Pinning an Object............................................................................................................................ 11-8
xviii
Array Pin................................................................................................................................... 11-9
Manipulating Object Attributes.................................................................................................... 11-9
Marking Objects and Flushing Changes.................................................................................... 11-10
Fetching Embedded Objects........................................................................................................ 11-11
Object Meta-Attributes................................................................................................................. 11-12
Persistent Object Meta-Attributes........................................................................................ 11-12
Additional Attribute Functions ........................................................................................... 11-14
Transient Object Meta-Attributes........................................................................................ 11-14
Complex Object Retrieval ............................................................................................................ 11-15
Prefetching Objects ................................................................................................................ 11-16
Implementing Complex Object Retrieval in OCI .............................................................. 11-17
COR Prefetching............................................................................................................................ 11-18
COR Interface ......................................................................................................................... 11-18
Example of COR..................................................................................................................... 11-18
OCI Versus SQL Access to Objects ............................................................................................ 11-20
Pin Count and Unpinning............................................................................................................ 11-21
NULL Indicator Structure............................................................................................................ 11-21
Creating Objects ............................................................................................................................ 11-23
Attribute Values of New Objects......................................................................................... 11-24
Freeing and Copying Objects ...................................................................................................... 11-25
Object Reference and Type Reference........................................................................................ 11-25
Create Objects Based on Object Views and Object Tables with Primary-Key-Based OIDs 11-25
Error Handling in Object Applications...................................................................................... 11-26
Type Inheritance.................................................................................................................................. 11-27
Substitutability............................................................................................................................... 11-27
NOT INSTANTIABLE Types and Methods.............................................................................. 11-28
OCI Support for Type Inheritance.............................................................................................. 11-28
OCIDescribeAny() ................................................................................................................. 11-29
Bind and Define Functions................................................................................................... 11-29
OCIObjectGetTypeRef()........................................................................................................ 11-29
OCIObjectCopy().................................................................................................................... 11-29
OCICollAssignElem()............................................................................................................ 11-29
OCICollAppend()................................................................................................................... 11-29
OCICollGetElem().................................................................................................................. 11-30
OTT Support for Type Inheritance............................................................................................. 11-30
Type Evolution..................................................................................................................................... 11-30
12 Object-Relational Data Types in OCI
Overview of OCI Functions for Objects........................................................................................... 12-1
Mapping Oracle Data Types to C....................................................................................................... 12-2
OCI Type Mapping Methodology................................................................................................ 12-3
Manipulating C Data Types with OCI.............................................................................................. 12-3
Precision of Oracle Number Operations...................................................................................... 12-4
Date (OCIDate) ...................................................................................................................................... 12-5
Date Example................................................................................................................................... 12-5
Datetime and Interval (OCIDateTime, OCIInterval)..................................................................... 12-6
Datetime Functions......................................................................................................................... 12-7
xix
Datetime Example........................................................................................................................... 12-8
Interval Functions ........................................................................................................................... 12-8
Number (OCINumber)......................................................................................................................... 12-9
OCINumber Examples ................................................................................................................. 12-10
Fixed or Variable-Length String (OCIString)................................................................................ 12-12
String Functions............................................................................................................................. 12-12
String Example .............................................................................................................................. 12-12
Raw (OCIRaw) ..................................................................................................................................... 12-13
Raw Functions ............................................................................................................................... 12-13
Raw Example ................................................................................................................................. 12-13
Collections (OCITable, OCIArray, OCIColl, OCIIter) ................................................................ 12-14
Generic Collection Functions....................................................................................................... 12-14
Collection Data Manipulation Functions................................................................................... 12-14
Collection Scanning Functions.................................................................................................... 12-15
Varray/Collection Iterator Example .......................................................................................... 12-15
Nested Table Manipulation Functions....................................................................................... 12-16
Nested Table Element Ordering.......................................................................................... 12-17
Nested Table Locators .................................................................................................................. 12-17
Multilevel Collection Types.............................................................................................................. 12-17
Multilevel Collection Type Example.......................................................................................... 12-18
REF (OCIRef) ....................................................................................................................................... 12-18
REF Manipulation Functions....................................................................................................... 12-19
REF Example.................................................................................................................................. 12-19
Object Type Information Storage and Access ............................................................................... 12-20
Descriptor Objects......................................................................................................................... 12-20
AnyType, AnyData, and AnyDataSet Interfaces .......................................................................... 12-20
Type Interfaces .............................................................................................................................. 12-21
Creating a Parameter Descriptor for OCIType Calls........................................................ 12-21
Obtaining the OCIType for Persistent Types .................................................................... 12-22
Type Access Calls................................................................................................................... 12-23
Extensions to OCIDescribeAny()......................................................................................... 12-23
OCIAnyData Interfaces................................................................................................................ 12-23
NCHAR Typecodes for OCIAnyData Functions ..................................................................... 12-24
OCIAnyDataSet Interfaces........................................................................................................... 12-24
Binding Named Data Types..............................................................................................................
12-25
Named Data Type Binds.............................................................................................................. 12-25
Binding REFs................................................................................................................................. 12-25
Information for Named Data Type and REF Binds ................................................................. 12-26
Information Regarding Array Binds .......................................................................................... 12-26
Defining Named Data Types ............................................................................................................ 12-26
Defining Named Data Type Output Variables......................................................................... 12-26
Defining REF Output Variables .................................................................................................. 12-27
Information for Named Data Type and REF Defines, and PL/SQL OUT Binds................. 12-27
Information About Array Defines....................................................................................... 12-28
Binding and Defining Oracle C Data Types.................................................................................. 12-28
Bind and Define Examples........................................................................................................... 12-29
Salary Update Examples .............................................................................................................. 12-31
xx
Method 1 - Fetch, Convert, Assign...................................................................................... 12-32
Method 2 - Fetch and Assign................................................................................................ 12-32
Method 3 - Direct Fetch......................................................................................................... 12-32
Summary and Notes.............................................................................................................. 12-33
SQLT_NTY Bind and Define Examples ......................................................................................... 12-33
SQLT_NTY Bind Example ........................................................................................................... 12-33
SQLT_NTY Define Example........................................................................................................ 12-34
13 Direct Path Load Interface
Direct Path Loading Overview ........................................................................................................... 13-1
Data Types Supported for Direct Path Loading......................................................................... 13-3
Direct Path Handles........................................................................................................................ 13-4
Direct Path Context.................................................................................................................. 13-4
OCI Direct Path Function Context......................................................................................... 13-4
Direct Path Column Array and Direct Path Function Column Array ............................. 13-5
Direct Path Stream ................................................................................................................... 13-6
Direct Path Interface Functions..................................................................................................... 13-6
Limitations and Restrictions of the Direct Path Load Interface ............................................... 13-7
Direct Path Load Examples for Scalar Columns......................................................................... 13-7
Data Structures Used in Direct Path Loading Example ..................................................... 13-7
Outline of an Example of a Direct Path Load for Scalar Columns ................................... 13-9
Using a Date Cache in Direct Path Loading of Dates in OCI ................................................. 13-12
OCI_ATTR_DIRPATH_DCACHE_SIZE............................................................................ 13-13
OCI_ATTR_DIRPATH_DCACHE_NUM .......................................................................... 13-13
OCI_ATTR_DIRPATH_DCACHE_MISSES....................................................................... 13-13
OCI_ATTR_DIRPATH_DCACHE_HITS ........................................................................... 13-14
OCI_ATTR_DIRPATH_DCACHE_DISABLE ................................................................... 13-14
Direct Path Loading of Object Types .............................................................................................. 13-14
Direct Path Loading of Nested Tables ....................................................................................... 13-14
Describing a Nested Table Column and Its Nested Table ............................................... 13-15
Direct Path Loading of Column Objects.................................................................................... 13-15
Describing a Column Object................................................................................................. 13-15
Allocating the Array Column for the Column Object...................................................... 13-17
Loading Column Object Data into the Column Array..................................................... 13-17
OCI_DIRPATH_COL_ERROR............................................................................................. 13-17
Direct Path Loading of SQL String Columns............................................................................ 13-18
Describing a SQL String Column ........................................................................................ 13-18
Allocating the Column Array for SQL String Columns................................................... 13-19
Loading the SQL String Data into the Column Array...................................................... 13-20
Direct Path Loading of REF Columns........................................................................................ 13-20
Describing the REF Column................................................................................................. 13-20
Allocating the Column Array for a REF Column.............................................................. 13-23
Loading the REF Data into the Column Array.................................................................. 13-23
Direct Path Loading of NOT FINAL Object and REF Columns............................................. 13-24
Inheritance Hierarchy............................................................................................................ 13-24
Describing a Fixed, Derived Type to Be Loaded............................................................... 13-25
Allocating the Column Array............................................................................................... 13-25
剩余1497页未读,继续阅读
2023-09-07 上传
2023-02-06 上传
2023-04-27 上传
2023-10-26 上传
2023-06-14 上传
2023-07-03 上传
iqw17532
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 深入浅出:自定义 Grunt 任务的实践指南
- 网络物理突变工具的多点路径规划实现与分析
- multifeed: 实现多作者间的超核心共享与同步技术
- C++商品交易系统实习项目详细要求
- macOS系统Python模块whl包安装教程
- 掌握fullstackJS:构建React框架与快速开发应用
- React-Purify: 实现React组件纯净方法的工具介绍
- deck.js:构建现代HTML演示的JavaScript库
- nunn:现代C++17实现的机器学习库开源项目
- Python安装包 Acquisition-4.12-cp35-cp35m-win_amd64.whl.zip 使用说明
- Amaranthus-tuberculatus基因组分析脚本集
- Ubuntu 12.04下Realtek RTL8821AE驱动的向后移植指南
- 掌握Jest环境下的最新jsdom功能
- CAGI Toolkit:开源Asterisk PBX的AGI应用开发
- MyDropDemo: 体验QGraphicsView的拖放功能
- 远程FPGA平台上的Quartus II17.1 LCD色块闪烁现象解析
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功