linux C/C++ proc 连接oracle 求教

Joseph_ 2014-09-29 09:56:35
#include"stdio.h"
#include"stdlib.h"
#include"global.h"
#include"errno.h"
EXEC SQL INCLUDE sqlca;
EXEC SQL BEGIN DECLARE SECTION;
varchar sql_userid[32];
varchar sql_passwd[32];
varchar sql_dbname[32];
EXEC SQL END DECLARE SECTION;
char *tolower(char *s);
char *toupper(char *s);
char acErrMsg[256];
int g_pub_tx;
int g_td_mst;
int tpalloc ;
int _tmget_tperrno_addr;
int tpstrerror;
int userlog;
int tpreturn;
int tpsprio;
int tpacall;
int tpfree;
int func;
int user_call_back;
int special_server;
int tp_name;
int Fadd32;
int _Fget_Ferror_addr32;
int tpsubscribe;
int tppost;
int user_poll_call;
int tpunadvertise ;
int tpunsubscribe;
int Pre_Server_Call;
int tpadvertise;
int tp_backcallname;
int tpcall;
int Bit_Arr;
int Pub_leng;
int Pu_Val;
int Pub_Buf;
int Old_Pu_Val;
int Old_Pub_Buf;
int PuVal_num ;
int Rec_Bitp ;

struct tbl_respcd_c{
char rowid[20];
long id;
char class[65];
char in_code[31];
char in_val[257];
char out_code[31];
char out_val[257];
char val_desc[129];
};

void db_connect(){
char *du_ora_id;
char *du_ora_pwd;


du_ora_id = (char *)getenv("DB_USER");
du_ora_pwd = (char *)getenv("DB_PASSWD");
if(du_ora_id!=NULL){
strcpy(sql_userid.arr,du_ora_id);
tolower(sql_userid.arr);
sql_userid.len=strlen(sql_userid.arr);
}else{
strcpy(sql_userid.arr,"sc");
sql_userid.len=strlen(sql_userid.arr);
}
strcpy(sql_dbname.arr,"Develop");
if(du_ora_pwd!=NULL){
strcpy(sql_passwd.arr,du_ora_pwd);
tolower(sql_passwd.arr);
sql_passwd.len=strlen(sql_passwd.arr);
}else{
strcpy(sql_passwd.arr,"sc");
sql_passwd.len=strlen(sql_passwd.arr);
}
printf("%s,%s,%s\n",sql_userid.arr,sql_passwd.arr,sql_dbname.arr);


//EXEC SQL connect :sql_userid IDENTIFIED BY :sql_passwd using :sql_dbname;
//EXEC SQL CONNECT :sql_userid IDENTIFIED BY :sql_passwd USING :sql_dbname;
//EXEC SQL connect :sql_userid IDENTIFIED BY :sql_passwd;

/*
EXEC SQL WHENEVER SQLERROR STOP; //隐式异常处理
EXEC SQL CONNECT :sql_userid
IDENTIFIED BY :sql_userid USING :sql_dbname;
*/
if(sqlca.sqlcode != 0){
printf("\n Connect Database Error, code = %d",sqlca.sqlcode);
exit(1);
}
EXEC SQL alter session set optimizer_goal = all_rows;
}
char *tolower(char *s){
int len=strlen(s);
int i;
for(i=0;i<len;i++){
if(s[i]>='A' && s[i]<='Z'){
s[i]=s[i]-'A'+'a';
}
}
return(s);
}
char *toupper(char *s){
int len=strlen(s);
int i;
for(i=0;i<len;i++){
if(s[i]>='a' && s[i]<='z'){
s[i]=s[i]-'a'+'A';
}
}
return(s);
}
char *zip_space(char *s){
int i,j;
int len=strlen(s);
i=j=0;
while(s[i]!='\0'){
if(s[i]==' ' ||s[i]=='\t' ||s[i]==0x0a ||s[i]==0x0d){
i++;
}else if(s[i]=='#'){
break;
}else{
s[j]=s[i];
i++;
j++;
}
}
while(j<len){
s[j]='\0';
j++;
}
return(s);
}
int put_mystery( char *str, char *mystery ){
memcpy(mystery,"111",3);
return(0);
}
int pub_reg_rec_file(char *str){
printf("%s,%d,%s\n",__FILE__,__LINE__,str);
return(0);
}
int dd_mst_con(){
return(0);
}
int in_mst_con(){
return(0);
}
int ln_lo_con(){
return(0);
}
int ln_mst_con(){
return(0);
}
int mdm_ac_rel_con(){
return(0);
}
int td_mst_con(){
return(0);
}
static mtest(char *tx_code,char *in_sub_tx)
{
struct tbl_respcd_c stRespcd;
char val[128]="\0";
char code[128]="\0";

int ret = Tbl_respcd_Sel(&stRespcd, "class = '%s' and in_code = '%s'", "scup", "A0");
if (ret)
{

printf("%s(),Tbl_respcd_map_Sel class[%s] in_val=[%s]",__func__,"scup","A0");
return 1;
}
strcpy(val, stRespcd.out_val);
strcpy(code, stRespcd.out_code);
printf(" out[%s] desc[%s]" ,code, val);
/*
while(1)
{
RespCode=Tx_sub_rel_Fet_Sel(&sub_rel,RtCode);
if ( RespCode )
{
strcpy ( RtCode , "0000" );
break;
}

if( sub_rel.out_ind[0]=='9' ) //不启用
continue;

printf("[%s]--------[%s]",sub_rel.in_data,sub_rel.out_data );

}
*/
return 0;
}
int main(){

char buf[5];
memset(buf,'\0',sizeof(buf));
db_connect();
mtest("2202","SQ01");
mtest("2202","D003");
mtest("2202","D003");
mtest("1111","D003");
mtest("1111","D003");
mtest("1111","D003");
mtest("1111","D003");
mtest("2202","D003");
mtest("2202","SQ99");
mtest("2202","SQ01");
mtest("2202","D003");

return(0);
}


测试代码如上 通过项目工程的makefile编译完成,运行是core掉
core的位置:“//EXEC SQL connect :sql_userid IDENTIFIED BY :sql_passwd using :sql_dbname;
//EXEC SQL CONNECT :sql_userid IDENTIFIED BY :sql_passwd USING :sql_dbname;
//EXEC SQL connect :sql_userid IDENTIFIED BY :sql_passwd;

/*
EXEC SQL WHENEVER SQLERROR STOP; //隐式异常处理
EXEC SQL CONNECT :sql_userid
IDENTIFIED BY :sql_userid USING :sql_dbname;
*/”
这部分不管怎么连接 都会core掉
问题:
1、麻烦哪个大牛帮忙看一下 多谢了。
2、另外我通过这个测试程序看,没有产生sql句柄,我之前没用proc oracle,不知道怎么连接多个DB 然后怎么区分勒。之前用mysql时候 连接要一个DB都会有一个句柄 根据句柄操作就好了,这个怎么办呢!
...全文
278 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Joseph_ 2014-09-29
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
进程意外退出会在当前目录下产生‘core’文件或形如‘core.数字’的文件比如‘core.1234’ 使用命令 gdb 运行程序名 core或core.数字 进入gdb然后使用bt命令 可以查看进程意外退出前函数调用的堆栈,内容为从上到下列出对应从里层到外层的函数调用历史。 如果进程意外退出不产生core文件,参考“ulimit -c core文件最大块大小”命令
#0 0x007256c6 in __strlen_sse2_bsf () from /lib/i686/nosegneg/libc.so.6 #1 0x08048c97 in tolower (s=0x4e <Address 0x4e out of bounds>) at mtest.pc:117 #2 0x41994696 in nlpatolower () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #3 0x41995954 in nlpagtcase () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #4 0x4199581a in nlpaputval () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #5 0x4199568a in nlpainzert () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #6 0x4042f007 in nlpaparse () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #7 0x4042ed43 in nlpardfile () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #8 0x4042e856 in nlpains () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #9 0x4042e695 in nlpainso () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #10 0x402e1dca in nlstdlp_load_psource () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #11 0x4197e875 in nlstdggo () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #12 0x4197e67b in nlstdgg () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #13 0x40398562 in nigini2 () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #14 0x40754f9c in kpeDbgGetNPDGlobal () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #15 0x40754ec8 in kpeDbgTLSInit () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #16 0x41a5898f in kpummTLSGET1 () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #17 0x4075503a in kpeDbgProcessInit () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #18 0x40753590 in kpummpin () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #19 0x40293f88 in kpupin () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #20 0x40262f28 in OCIInitialize () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #21 0x4023b1c5 in sqgctx () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #22 0x41954344 in sqgrct () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #23 0x419527b1 in sqlcmex () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #24 0x419525cc in sqlcxt () from /home/oracle/product/11.2/lib/libclntsh.so.11.1 #25 0x08048b9c in db_connect () at mtest.pc:109 #26 0x0804903a in main () at mtest.pc:222 我不debug 怎么知道在哪里core的勒。上面说的109行 我已经修改!~ 反正就是EXEC SQL connect :sql_userid IDENTIFIED BY :sql_passwd using :sql_dbname; core
赵4老师 2014-09-29
  • 打赏
  • 举报
回复
进程意外退出会在当前目录下产生‘core’文件或形如‘core.数字’的文件比如‘core.1234’ 使用命令 gdb 运行程序名 core或core.数字 进入gdb然后使用bt命令 可以查看进程意外退出前函数调用的堆栈,内容为从上到下列出对应从里层到外层的函数调用历史。 如果进程意外退出不产生core文件,参考“ulimit -c core文件最大块大小”命令
robertbo 2014-09-29
  • 打赏
  • 举报
回复
我也是刚接触proc链接oracle,主要参考这个网页里的资料,楼主看一下有没有帮助 http://bbs.chinaunix.net/thread-9155-1-1.html

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧