ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:48.98KB ,
资源ID:17817162      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/17817162.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(ProCC+++编程Word格式.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

ProCC+++编程Word格式.docx

1、2.1、Pro*C/C+ 预编译环境当您安装 Oracle 数据库产品的时候,Pro*C/C+的预编译环境缺省就为我们安装好了,我们这里以安装 Oracle 10G 版本为例. 在 Oracle_Home的 Bin 目录下, 您可以找到预编译程序 proc.exe, 这个就是用来预编译您有在C/C+代码中嵌入SQL的文件的. 该编译程序用到了 Oracle_Home下的precomppublic 目录中的 .h 头文件, 在正真编译生成可执行文件时又会用到 precomplib 的一个 .lib 库文件. 我们进入 command 窗口,看看 proc 编译命名的参数:Pro*C/C+编译命令

2、参数(10G)C:oracleproduct10.2.0db_2BINprocPro*C/C+: Release 10.2.0.1.0 - Production on Mon Feb 23 16:22:29 2009Copyright (c) 1982, 2005, Oracle. All rights reserved.System default option values taken from: C:oracleproduct10.2.0db_2precompadminpcscfg.cfgOption Name Current Value Description-auto_connect

3、 no Allow automatic connection to ops$ accountchar_map charz Mapping of character arrays and stringsclose_on_commit no Close all cursors on COMMITcmax 100 CMAX Value for connection poolcmin 2 CMIN Value for connection poolcincr 1 CINCR Value for connection poolctimeout 0 CTIMEOUT Value for connectio

4、n poolcnowait 0 CNOWAIT Value for connection poolcode cpp The type of code to be generatedcomp_charset multi_byte The character set type the C compiler supportsconfig default Override system configuration file with anothercpool no Support connection poolingcpp_suffix cc Override the default C+ filen

5、ame suffixdbms native v6/v7/v8 compatibility modedef_sqlcode no Generate #define SQLCODE sqlca.sqlcode macrodefine *none* Define a preprocessor symbolduration transaction Set pin duration for objects in the cachedynamic oracle Specify Oracle or ANSI Dynamic SQL Semanticserrors yes Whether error mess

6、ages are sent to the terminalerrtype *none* Name of the list file for intype file errorsevents no Support publish-subscribe event notificationsfips none FIPS flagging of ANSI noncompliant usageheader *none* Specify file extension for Precompiled Headershold_cursor no Control holding of cursors in th

7、e cursor cacheiname *none* The name of the input fileinclude *none* Directory paths for included filesintype *none* The name of the input file for type informationlines no Add #line directives to the generated codelname *none* Override default list file nameltype short The amount of data generated i

8、n the list filemaxliteral 1024 Maximum length of a generated string literalmaxopencursors 10 Maximum number of cached open cursorsmode oracle Code conformance to Oracle or ANSI rulesnative_types no Support for native float/doublenls_char *none* Specify National Language character variablesnls_local

9、no Control how NLS character semantics are doneobjects yes Support object typesoname *none* The name of the output fileoraca no Control the use of the ORACApagelen 80 The page length of the list fileparse none Control which non-SQL code is parsedprefetch 1 Number of rows pre-fetched at cursor OPEN t

10、imerelease_cursor no Control release of cursors from cursor cacheselect_error yes Control flagging of select errorssqlcheck SEMANTICS Amount of compile-time SQL checkingsys_include *none* Directory where system header files are foundthreads no Indicates a multi-threaded applicationtype_code oracle U

11、se Oracle or ANSI type codes for Dynamic SQLunsafe_null no Allow a NULL fetch without indicator variableuserid *none* A username/password dbname connect stringutf16_charset nchar_charset The character set form used by UTF16 variablesvarchar no Allow the use of implicit varchar structuresversion rece

12、nt Which version of an object is to be returnedwin32_threads no Support windows default local threadingPCC-F-02135, CMD-LINE: User asked for help这些命令参数选项,除了直接在命令行参数中指定外,您也可以通过 precompadminpsccfg.cfg 文件中进行指定, 下面是一个样例:ltype=shortcode=cppcpp_suffix=ccparse=noneSQLCHECK=SEMANTICS这里我们介绍其中的三个参数: code=cpp

13、这个参数表明我们通过 proc 预编译命令产生的代码文件是符合 C+ 规范的,如果您是在标准C环境中使用, 那么您可以指定 code=ansi_c cpp_suffix=cc 这个参数让 proc 命令产生的文件以 .cc 作为文件扩展名 SQLCHECK=SEMANTICS 这个参数用于指示在预编译的时候是否要检查嵌入的SQL的语法,您可以设置 NONE 表示不检查(10G中中已经不再支持这个值了,至少设置为 SYNTAX), SEMANTICS 表示检查语义(也就是检查数据库表名,列名是否存在等)2.2、GCC 编译器在 Windows 环境中, 您可以选择使用微软的 VC 编译器, 或者

14、 Bland公司的 BC 编译器. 我们这里使用 GCC 1) 编译器, GCC 编译器的安装可以直接从 http:/gcc.gnu.org 这里下载, 最新提供一个在Windows下快速安装的工具程序.这里我们采用了 Dev-CPP 的开发环境, 这个开发环境中包含了 GCC, 下载地址见 三、开始编写第一个Pro*C+代码3.1、第一个Pro*C+代码本文中涉及到的 C+ 知识不做过多介绍,已经超出了本文范围. 编写一个 Oracle 登陆程序(我们这里使用 C+ 代码, 当然您也可以使用 标准C 代码): 1: using namespace std; 2: #include 3: #i

15、nclude sqlca.h / SQL Comunication Area 4: 5: EXEC SQL BEGIN DECLARE SECTION; 6: char *uid = scott/tigerorcl10g; 7: EXEC SQL END DECLARE SECTION; 8: 9: int main()10: 11: EXEC SQL CONNECT :uid;12: if (sqlca.sqlcode != 0)13: coutsqlca.sqlerrm.sqlerrmcset ORACLE_HOME=C:oracleproduct10.2.0db_2set path=%O

16、RACLE_HOME%bincd procprocdir /bmyfirst.pcproc myfirst.pc Release 10.2.0.1.0 - Production on Wed Feb 25 13:58:52 2009myfirst.ccmyfirst.lis以上已经与编译成功,我们可以看到新产生了 myfirst.cc 文件, 这个文件就是将嵌入的SQL指令预编译成为标准的ORACLE库函数调用后的文件.您可以查看该文件内容. 3.3、GCC 编译在进行预编译产生正常的C+代码文件后, 接下来, 我们只需要用 C+ 编译器编译这个 .cc 文件即可得到我们的可执行文件. 我们首

17、先需要设置一下 Path, 以便找到我们的编译器, 我的 gcc 编译器在 c:Dev-Cppbin 目录下, 由于这里使用的是 C+ 的编程, 所以我使用 g+ 编译命令 set path=C:Dev-Cppbin;%path%g+ myfirst.ccmyfirst.cc:145:19: sqlca.h: No such file or directory In function int main():167: error: sqlca undeclared (first use this function) (Each undeclared identifier is reported

18、only once for each function it appears in.)这里出错了,因为 sqlca 这个结构变量没有找到, 实际上是没有找到 sqlca.h 这个头文件, 这个头文件在 %ORACLE_HOME%precomppublic 目录下, 因此我们通过命令行指定这个位置:g+ myfirst.cc -I %ORACLE_HOME%precomppublicDOCUME1nyforLOCALS1Temp/ccgLbaaa.o(.text+0x2b9): undefined reference to sqlcxtcollect2: ld returned 1 exit s

19、tatus依然有错误,提示找不到 sqlcxt 的引用, 这个是在链接的时候发生的错误, 链接时需要一个Oracle库文件, 这个库文件位置在 %ORACLE_HOME%precomplib目录中,文件名为: orasql10.lib, Oracle 9i 的文件名为 orasql9.lib 我们指定库文件路径及库文件后重新编译:g+ myfirst.cc -I %ORACLE_HOME%precomppublic -L %ORACLE_HOME%precompLIB -l orasql10a.exe至此, 我们成功生成了一个可执行文件 a.exe , 这个文件可以用来测试登陆. 3.4、最后

20、测试当我们生成好了可执行文件后, 我们开始测试, aSuccess.当我们把 Oracle Listener 停掉后再行测试 ORA-12170: TNS:Connect timeout occurred四、复杂一些的Pro*C/C+代码4.1、代码部分这里我们直接在代码中编写注释, 以阐释Pro*C/C+中的一些基本指令的用法 using namespace std;#include #include /引入 SQL 通讯区/以下申明一个宿主变量,这是一个全局的变量,这个变量在C代码中和正常的变量一样使用,/在嵌入SQL语句中,在变量名前追加冒号:来引用该变量.EXEC SQL BEGIN

21、DECLARE SECTION; /只有包含在这之间申明的变量才能用于嵌入SQL代码中 char *uid = scott/tiger/192.168.8.35:1522/orcl10EXEC SQL END DECLARE SECTION;/这里申明了一个函数,后面会做说明,代码实现在最后void sql_error();int main()/*这条指令指示嵌入SQL执行发生错误的时候(不包含NO_DATA_FOUND例外)转向执行的C函数 这个指令还有其它一些语法: EXEC SQL WHENEVER SQLERROR CONTINUE; 继续执行下一条语句 EXEC SQL WHENEV

22、ER SQLERROR STOP; 停止应用程序的执行 EXEC SQL WHENEVER SQLERROR GOTO label; 跳转到指定的标号处运行 初始状态为 CONTINUE */ EXEC SQL WHENEVER SQLERROR DO sql_error();这条指令连接数据库, 常用的连接方法有两种: 一是将用户名和密码存放在两个宿主变量中, 采用 IDENTIFIED BY 子句: EXEC SQL CONNECT :username IDENTIFIED BY :password ; 一是将用户名和密码按照“username/password”方式(在用户名和密码中用反

23、斜线做分隔的字符串)存放在一个宿主变量中:usernameandpwd;Database Connected. /下面这条指令是执行一条本机动态SQL语句,语法和PL/SQL中类似 EXEC SQL EXECUTE IMMEDIATE drop table t_emp /前面代码当SQL执行发生错误时设置的CONTINUE,我们在下一条语句检查执行结果 if (sqlca.sqlcode = 0) / sqlcode 为 0 表示执行成功.Table T_EMP droped. /以下是嵌入的普通的DDL语句,执行完后我们没有检测 sqlca.sqlcode , /是因为前面我们设置了出错时进

24、行捕获并执行 sql_error() 函数 /我们在 sql_error 函数中进行错误处理. EXEC SQL create table t_emp as select empno,ename,sal from emp where 1 = 0;Table T_EMP created. /*下面在 main 函数内申明SQL宿主变量,这里的就是局部变量了,只能用在函数 main 内部以下申明了一些数组变量,供我们用来存储查询语句返回的多行数据,在 PL/SQL 中我们也曾使用bulk collect into 子句来批量 fetch 数据;当然我们也可以不定义数组,而定义单个变量,这样每次就只能获取一条数据. int empno5; /存放 EMPNO 字段 char ename511; /*存放 ENAME 字段,因为在 C 中字符串是要以 0 结尾的,所以比我们

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1