没有合适的资源?快使用搜索试试~ 我知道了~
首页Oracle Pro*C/C++ Precompiler 指南
"这篇文档是Oracle Corporation发布的Pro*C/C++ Precompiler Programmer's Guide,版本9.0.1,主要介绍了如何在SQL SERVER和ORACLE等数据库中使用C和C++进行预编译的过程。该指南由多位作者共同完成,并包含了Oracle Corporation的版权信息和使用限制。"
在数据库开发中,预编译器是一个重要的工具,它主要用于提高应用程序与数据库交互的效率。Pro*C/C++ Precompiler是Oracle提供的一种工具,它允许开发者用C或C++语言编写包含SQL语句的源代码,然后在编译阶段将这些SQL语句转换成数据库能够理解的形式。
预编译的主要步骤包括:
1. **语法解析**:预编译器首先对源代码中的SQL语句进行语法解析,确保它们符合SQL标准。
2. **嵌入式SQL处理**:识别并处理C或C++代码中的嵌入式SQL语句,将它们转化为数据库调用的形式。
3. **类型检查**:验证SQL语句中的变量类型与C/C++代码中的变量类型匹配。
4. **生成C/C++代码**:预编译器生成包含数据库调用的C/C++代码,这些代码可以在运行时直接与数据库进行交互。
5. **链接数据库库**:最终生成的C/C++代码需要链接到Oracle的数据库库,以便在运行时执行SQL操作。
通过预编译,开发者可以利用C或C++的强大功能和性能,同时享受SQL的便利性。这种方式特别适合大规模、高性能的数据库应用,因为它减少了运行时解析SQL语句的时间,提高了整体性能。
在使用Pro*C/C++ Precompiler时,开发者需要注意以下几点:
- **错误处理**:预编译器会生成处理SQL错误的代码,开发者需要适当地处理这些异常情况。
- **动态SQL**:对于在运行时才能确定的SQL语句,预编译器提供了动态SQL的机制。
- **连接管理**:管理数据库连接,包括打开、关闭和重用连接。
- **事务控制**:预编译的代码可以支持SQL的事务管理语句,如BEGIN、COMMIT和ROLLBACK。
使用Pro*C/C++ Precompiler的开发者还需要了解Oracle的API,如Oracle Call Interface (OCI),它提供了更底层的数据库访问能力。预编译器生成的代码通常与特定的数据库版本兼容,因此在升级数据库时可能需要重新预编译。
最后,文档中提到的内容可能随时间更新,遇到任何问题或发现文档错误时,应当及时向Oracle Corporation反馈。同时,使用预编译器需遵守Oracle的许可协议,禁止逆向工程、反汇编或反编译程序。
Pro*C/C++ Precompiler是Oracle提供的一个强大的工具,它帮助开发者在C和C++环境中高效地集成和执行SQL语句,是开发数据库驱动的应用程序时不可或缺的一部分。通过预编译,开发者能够编写出更高效、更健壮的数据库应用程序。
xvi
DECLARE .................................................................................................................................. 13-20
OPEN.......................................................................................................................................... 13-20
FETCH........................................................................................................................................ 13-21
CLOSE ........................................................................................................................................ 13-21
Example Program: Dynamic SQL Method 3 ........................................................................ 13-21
Using Method 4............................................................................................................................... 13-25
Need for the SQLDA............................................................................................................... 13-26
The DESCRIBE Statement........................................................................................................ 13-26
What is a SQLDA?.................................................................................................................... 13-27
Implementing Oracle Method 4.............................................................................................. 13-28
Restriction.................................................................................................................................. 13-29
Using the DECLARE STATEMENT Statement......................................................................... 13-29
Using Host Arrays.................................................................................................................... 13-29
Using PL/SQL .................................................................................................................................. 13-30
With Method 1........................................................................................................................... 13-30
With Method 2........................................................................................................................... 13-30
With Method 3........................................................................................................................... 13-31
With Oracle Method 4.............................................................................................................. 13-31
14 ANSI Dynamic SQL
Basics of ANSI Dynamic SQL........................................................................................................ 14-2
Precompiler Options .................................................................................................................. 14-2
Overview of ANSI SQL Statements.............................................................................................. 14-3
Example Code ............................................................................................................................. 14-6
Oracle Extensions.............................................................................................................................. 14-7
Reference Semantics................................................................................................................... 14-8
Using Arrays for Bulk Operations............................................................................................ 14-9
Support for Arrays of Structs.................................................................................................. 14-11
Support for Object Types......................................................................................................... 14-11
ANSI Dynamic SQL Precompiler Options................................................................................ 14-12
Full Syntax of the Dynamic SQL Statements............................................................................ 14-13
ALLOCATE DESCRIPTOR..................................................................................................... 14-13
DEALLOCATE DESCRIPTOR................................................................................................ 14-14
GET DESCRIPTOR................................................................................................................... 14-15
SET DESCRIPTOR.................................................................................................................... 14-19
xvii
Use of PREPARE....................................................................................................................... 14-23
DESCRIBE INPUT.................................................................................................................... 14-23
DESCRIBE OUTPUT................................................................................................................ 14-24
EXECUTE................................................................................................................................... 14-25
Use of EXECUTE IMMEDIATE.............................................................................................. 14-26
Use of DYNAMIC DECLARE CURSOR............................................................................... 14-27
OPEN Cursor ............................................................................................................................ 14-27
FETCH........................................................................................................................................ 14-28
CLOSE a Dynamic Cursor....................................................................................................... 14-29
Differences From Oracle Dynamic Method 4....................................................................... 14-30
Restrictions ................................................................................................................................ 14-30
Example Programs.......................................................................................................................... 14-31
ansidyn1.pc................................................................................................................................ 14-31
ansidyn2.pc................................................................................................................................ 14-39
15 Oracle Dynamic SQL: Method 4
Meeting the Special Requirements of Method 4........................................................................ 15-2
What Makes Method 4 Special?................................................................................................ 15-2
What Information Does Oracle Need? .................................................................................... 15-2
Where Is the Information Stored?............................................................................................ 15-3
How is the SQLDA Referenced? .............................................................................................. 15-3
How is the Information Obtained? .......................................................................................... 15-4
Understanding the SQLDA ............................................................................................................ 15-4
Purpose of the SQLDA............................................................................................................... 15-4
Multiple SQLDAs....................................................................................................................... 15-5
Declaring a SQLDA.................................................................................................................... 15-5
Allocating a SQLDA................................................................................................................... 15-6
Using the SQLDA Variables........................................................................................................... 15-7
The N Variable ............................................................................................................................ 15-7
The V Variable............................................................................................................................. 15-8
The L Variable ............................................................................................................................. 15-8
The T Variable............................................................................................................................. 15-9
The I Variable............................................................................................................................ 15-10
The F Variable ........................................................................................................................... 15-11
The S Variable ........................................................................................................................... 15-11
xviii
The M Variable.......................................................................................................................... 15-11
The C Variable........................................................................................................................... 15-11
The X Variable........................................................................................................................... 15-11
The Y Variable........................................................................................................................... 15-12
The Z Variable........................................................................................................................... 15-12
Some Preliminaries......................................................................................................................... 15-12
Converting Data........................................................................................................................ 15-12
Coercing Datatypes .................................................................................................................. 15-15
Handling NULL/Not NULL Datatypes ............................................................................... 15-18
The Basic Steps................................................................................................................................ 15-19
A Closer Look at Each Step........................................................................................................... 15-20
Declare a Host String................................................................................................................ 15-21
Declare the SQLDAs................................................................................................................. 15-21
Allocate Storage Space for the Descriptors........................................................................... 15-22
Set the Maximum Number to DESCRIBE............................................................................. 15-22
Put the Query Text in the Host String ................................................................................... 15-25
PREPARE the Query from the Host String........................................................................... 15-25
DECLARE a Cursor.................................................................................................................. 15-25
DESCRIBE the Bind Variables ................................................................................................ 15-25
Reset Number of Placeholders................................................................................................ 15-28
Get Values and Allocate Storage for Bind Variables........................................................... 15-28
OPEN the Cursor...................................................................................................................... 15-30
DESCRIBE the Select List......................................................................................................... 15-30
Reset Number of Select-List Items ......................................................................................... 15-32
Reset Length/Datatype of Each Select-list Item................................................................... 15-32
FETCH Rows from the Active Set.......................................................................................... 15-35
Get and Process Select-List Values......................................................................................... 15-35
Deallocate Storage .................................................................................................................... 15-37
CLOSE the Cursor .................................................................................................................... 15-37
Using Host Arrays.................................................................................................................... 15-38
sample12.pc ............................................................................................................................... 15-40
Example Program: Dynamic SQL Method 4.............................................................................. 15-41
16 Large Objects (LOBs)
What are LOBs?................................................................................................................................. 16-2
xix
Internal LOBs .............................................................................................................................. 16-2
External LOBs.............................................................................................................................. 16-2
Security for BFILEs..................................................................................................................... 16-2
LOBs versus LONG and LONG RAW .................................................................................... 16-3
LOB Locators............................................................................................................................... 16-3
Temporary LOBs......................................................................................................................... 16-3
LOB Buffering Subsystem ......................................................................................................... 16-4
How to Use LOBs in Your Program............................................................................................... 16-5
Three Ways to Access LOBs...................................................................................................... 16-5
LOB Locators in Your Application........................................................................................... 16-7
Initializing a LOB........................................................................................................................ 16-8
Rules for LOB Statements............................................................................................................. 16-10
For All LOB Statements ........................................................................................................... 16-10
For the LOB Buffering Subsystem.......................................................................................... 16-11
For Host Variables.................................................................................................................... 16-12
LOB Statements............................................................................................................................... 16-13
APPEND .................................................................................................................................... 16-13
ASSIGN...................................................................................................................................... 16-14
CLOSE........................................................................................................................................ 16-15
COPY.......................................................................................................................................... 16-15
CREATE TEMPORARY........................................................................................................... 16-16
DISABLE BUFFERING ............................................................................................................ 16-17
ENABLE BUFFERING............................................................................................................. 16-18
ERASE ........................................................................................................................................ 16-18
FILE CLOSE ALL...................................................................................................................... 16-19
FILE SET..................................................................................................................................... 16-20
FLUSH BUFFER........................................................................................................................ 16-20
FREE TEMPORARY................................................................................................................. 16-21
LOAD FROM FILE................................................................................................................... 16-22
OPEN.......................................................................................................................................... 16-23
READ.......................................................................................................................................... 16-24
TRIM........................................................................................................................................... 16-26
WRITE........................................................................................................................................ 16-26
DESCRIBE.................................................................................................................................. 16-28
LOBs and the Navigational Interface ......................................................................................... 16-31
xx
Transient Objects....................................................................................................................... 16-31
Persistent Objects...................................................................................................................... 16-31
Navigational Interface Example............................................................................................. 16-31
LOB Program Examples................................................................................................................. 16-33
READ a BLOB, Write a File Example..................................................................................... 16-33
Read a File, WRITE a BLOB Example.................................................................................... 16-35
lobdemo1.pc .............................................................................................................................. 16-37
17 Objects
Introduction to Objects.................................................................................................................... 17-2
Object Types ................................................................................................................................ 17-2
REFs to Object Types.................................................................................................................. 17-2
Type Inheritance ......................................................................................................................... 17-3
Using Object Types in Pro*C/C++................................................................................................. 17-4
NULL Indicators......................................................................................................................... 17-4
The Object Cache.............................................................................................................................. 17-5
Persistent Versus Transient Copies of Objects ....................................................................... 17-5
Associative Interface ........................................................................................................................ 17-5
When to Use the Associative Interface.................................................................................... 17-6
ALLOCATE ................................................................................................................................. 17-6
FREE.............................................................................................................................................. 17-7
CACHE FREE ALL..................................................................................................................... 17-7
Accessing Objects Using the Associative Interface................................................................ 17-7
Navigational Interface...................................................................................................................... 17-9
When to Use the Navigational Interface ............................................................................... 17-10
Rules Used in the Navigational Statements.......................................................................... 17-11
OBJECT CREATE...................................................................................................................... 17-11
OBJECT DEREF......................................................................................................................... 17-12
OBJECT RELEASE.................................................................................................................... 17-13
OBJECT DELETE ...................................................................................................................... 17-13
OBJECT UPDATE..................................................................................................................... 17-14
OBJECT FLUSH ........................................................................................................................ 17-14
Navigational Access to Objects............................................................................................... 17-14
Converting Object Attributes and C Types ............................................................................... 17-17
OBJECT SET............................................................................................................................... 17-17
剩余965页未读,继续阅读
402 浏览量
2020-07-12 上传
2020-06-23 上传
2016-06-07 上传
rotimi
- 粉丝: 3
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 平尾装配工作平台运输支撑系统设计与应用
- MAX-MIN Ant System:用MATLAB解决旅行商问题
- Flutter状态管理新秀:sealed_flutter_bloc包整合seal_unions
- Pong²开源游戏:双人对战图形化的经典竞技体验
- jQuery spriteAnimator插件:创建精灵动画的利器
- 广播媒体对象传输方法与设备的技术分析
- MATLAB HDF5数据提取工具:深层结构化数据处理
- 适用于arm64的Valgrind交叉编译包发布
- 基于canvas和Java后端的小程序“飞翔的小鸟”完整示例
- 全面升级STM32F7 Discovery LCD BSP驱动程序
- React Router v4 入门教程与示例代码解析
- 下载OpenCV各版本安装包,全面覆盖2.4至4.5
- 手写笔画分割技术的新突破:智能分割方法与装置
- 基于Koplowitz & Bruckstein算法的MATLAB周长估计方法
- Modbus4j-3.0.3版本免费下载指南
- PoqetPresenter:Sharp Zaurus上的开源OpenOffice演示查看器
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功