Oracle数据库开发(二).Linux下配置使用ProC
2007-06-07 21:50
393 查看
Oralce数据库开发(二).Linux下配置使用ProC
20070606
草木瓜
一、提要
上文简单介绍了Windows下ProC配置开发,这次我们使用Linux平台再次配置Oracle ProC开
发环境(RedHat Linux 9 + Oracle 92)。
《ORACLE数据库开发(一).Windows下配置使用ProC》和《ORACLE数据库开发(二).Linux下配置使用ProC》
这两篇文章的目的只是做一些基础介绍,至于Oracle ProC编译参数以及Linux下的ProC Makefile
相关内容,将再后续文章逐步引入。
一言以弊之,先易后难。
二、数据库环境
与Windows下十分类似,首先确认安装了组件,Oracle - Application Development -
Pro C-C++ 。安装后会在$ORACLE_HOME/bin生成相应可执行文件,在$ORACLE_HOME/precomp/demo/proc
下也会生成一些makefile文件和示例。
三、示例文件
main.pc
---------------------------------------------------------
#include "sqlca.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void sql_error(char *msg)
{
printf("/n%s %s/n", msg,(char *)sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK RELEASE;
exit(0);
}
int main() {
EXEC SQL INCLUDE sqlca;
EXEC ORACLE OPTION (RELEASE_CURSOR = YES);
EXEC SQL WHENEVER SQLERROR DO sql_error(" <ERROR> ");
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR oraCN[30];
EXEC SQL END DECLARE SECTION;
strcpy(oraCN.arr,"system/manager@linuxdb");
oraCN.len = strlen(oraCN.arr);
oraCN.arr[oraCN.len]='/0';
EXEC SQL CONNECT :oraCN;
printf("/n [OK Connected!] ");
return 0;
}
代码其实是Windows的原版。
四、编译运行
无需修改任何参数文件,即安装后直接创建main.pc,执行如下命令:
$ proc parse=none iname=main.pc
Pro*C/C++: Release 9.2.0.4.0 - Production on Thu Jun 7 14:17:05 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
System default option values taken from: /home/ora/ora9/oracle/precomp/admin/pcscfg.cfg
$ gcc -g -o main main.c -I/home/ora/ora9/oracle/precomp/public -L/home/ora/ora9/oracle/lib -lclntsh
$ ./main
<ERROR> ORA-12541: TNS:no listener
成功编译运行,这里也可以使用《ProC动态SQL示例(第1,2,3种方法)》一文中的示例,
将//注释全部替换为空,即可编译。
http://blog.csdn.net/liwei_cmg/archive/2006/05/29/759963.aspx
不过会有告警提示:
/tmp/ccC7E6qe.o(.text+0xea): In function `db_connect':
/home/ora/develop/src/db.c:385: the `gets' function is dangerous and should not be used.
这个是由于使用了gets函数所致,见gets的man手册:
BUGS
Never use gets(). Because it is impossible to tell without knowing the
data in advance how many characters gets() will read, and because
gets() will continue to store characters past the end of the buffer, it
is extremely dangerous to use. It has been used to break computer
security. Use fgets() instead.
It is not advisable to mix calls to input functions from the stdio
library with low - level calls to read() for the file descriptor asso-
ciated with the input stream; the results will be undefined and very
probably not what you want.
要解决这个问题,可以使用scanf函数替换gets,获取屏幕输入。如 scanf("%s",cmd)。
20070606
草木瓜
一、提要
上文简单介绍了Windows下ProC配置开发,这次我们使用Linux平台再次配置Oracle ProC开
发环境(RedHat Linux 9 + Oracle 92)。
《ORACLE数据库开发(一).Windows下配置使用ProC》和《ORACLE数据库开发(二).Linux下配置使用ProC》
这两篇文章的目的只是做一些基础介绍,至于Oracle ProC编译参数以及Linux下的ProC Makefile
相关内容,将再后续文章逐步引入。
一言以弊之,先易后难。
二、数据库环境
与Windows下十分类似,首先确认安装了组件,Oracle - Application Development -
Pro C-C++ 。安装后会在$ORACLE_HOME/bin生成相应可执行文件,在$ORACLE_HOME/precomp/demo/proc
下也会生成一些makefile文件和示例。
三、示例文件
main.pc
---------------------------------------------------------
#include "sqlca.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void sql_error(char *msg)
{
printf("/n%s %s/n", msg,(char *)sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK RELEASE;
exit(0);
}
int main() {
EXEC SQL INCLUDE sqlca;
EXEC ORACLE OPTION (RELEASE_CURSOR = YES);
EXEC SQL WHENEVER SQLERROR DO sql_error(" <ERROR> ");
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR oraCN[30];
EXEC SQL END DECLARE SECTION;
strcpy(oraCN.arr,"system/manager@linuxdb");
oraCN.len = strlen(oraCN.arr);
oraCN.arr[oraCN.len]='/0';
EXEC SQL CONNECT :oraCN;
printf("/n [OK Connected!] ");
return 0;
}
代码其实是Windows的原版。
四、编译运行
无需修改任何参数文件,即安装后直接创建main.pc,执行如下命令:
$ proc parse=none iname=main.pc
Pro*C/C++: Release 9.2.0.4.0 - Production on Thu Jun 7 14:17:05 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
System default option values taken from: /home/ora/ora9/oracle/precomp/admin/pcscfg.cfg
$ gcc -g -o main main.c -I/home/ora/ora9/oracle/precomp/public -L/home/ora/ora9/oracle/lib -lclntsh
$ ./main
<ERROR> ORA-12541: TNS:no listener
成功编译运行,这里也可以使用《ProC动态SQL示例(第1,2,3种方法)》一文中的示例,
将//注释全部替换为空,即可编译。
http://blog.csdn.net/liwei_cmg/archive/2006/05/29/759963.aspx
不过会有告警提示:
/tmp/ccC7E6qe.o(.text+0xea): In function `db_connect':
/home/ora/develop/src/db.c:385: the `gets' function is dangerous and should not be used.
这个是由于使用了gets函数所致,见gets的man手册:
BUGS
Never use gets(). Because it is impossible to tell without knowing the
data in advance how many characters gets() will read, and because
gets() will continue to store characters past the end of the buffer, it
is extremely dangerous to use. It has been used to break computer
security. Use fgets() instead.
It is not advisable to mix calls to input functions from the stdio
library with low - level calls to read() for the file descriptor asso-
ciated with the input stream; the results will be undefined and very
probably not what you want.
要解决这个问题,可以使用scanf函数替换gets,获取屏幕输入。如 scanf("%s",cmd)。
相关文章推荐
- Oracle数据库开发(二) Linux下配置使用ProC
- Oralce数据库开发(二).Linux下配置使用ProC
- 112、Oralce数据库开发(二).Linux下配置使用ProC
- Oracle数据库开发(二) Linux下配置使用ProC
- linux_ok6410配置usb摄像头ZC3XX并在网页使用流媒体显示
- Apache 配置------FastCGI方式使用PHP(包含:linux下编译安装fmod_fcgid,配置apache以支持FastCGI)
- 韩顺平Linux笔记(十四)——SSH安装、配置和使用
- linux 负载均衡配置 keepalive lvs 使用nginx转发 CentOS7 搭建LVS+keepalived负载均衡
- linux之vim配置及使用示例
- linux共享库位置配置(LD_LIBRARY_PATH环境变量 或者 更改/etc/ld.so.conf 或者 使用-R选项)
- Linux下采用二进制源码安装mysql,并配置使用mysqld命令启动服务
- Oracle在Linux下使用异步IO配置
- Redis/SSDB+Twemproxy的配置与使用(Mac/Linux平台)
- Linux环境VNC服务安装、配置与使用
- Linux(centos)下SVN服务器的搭建及简单配置和使用
- 【VNC】Linux环境VNC服务安装、配置与使用
- 如何使用linux ifconfig命令配置网卡
- [Linux]解决使用mdev时“cannot create /proc/sys/kernel/hotplug: nonexistent directory”错误
- [Linux]配置Logwatch使用第三方smtp发送电子邮件
- 整理的linux下ntop启动、安装、配置、使用!