基于Tuxedo的PRO*C开发问题,高手请入

bobui 2012-01-29 03:03:23

#ifndef _login_proc_pc_
#define _login_proc_pc_
#include <iostream>
#include <string>
#include <sqlca.h>
#include <atmi.h>
#include <userlog.h>
#include "include/PacketInterface.h"
#include "xmlhelper.h"

using namespace std;

#endif

EXEC SQL INCLUDE sqlca;
EXEC SQL BEGIN DECLARE SECTION;
struct DBMSG
{
const char* dbstr;
const char* dbuser;
const char* dbpwd;
}dbmsg;
char *sqltext=NULL;
char *username=NULL;
char *userpwd=NULL;
char *ipaddr=NULL;
int iLanguage;
int datacount=0;
EXEC SQL END DECLARE SECTION;

void readdbmsg();

int
#if defined(__STDC__) || defined(__cplusplus)
tpsvrinit(int argc,char* argv[])
#else
tpsvrinit(argc,argv)
int argc;
char** argv;
#endif
{
argc=argc;
argv=argv;

readdbmsg();

EXEC SQL WHENEVER SQLERROR DO sqlerror(sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);

/*connect database*/

EXEC SQL CONNECT :dbmsg.dbuser IDENTIFIED BY :dbmsg.dbpwd USING :dbmsg.dbstr;
if(sqlca.sqlcode==0)
{
userlog("connect database succness!");
}
else
{
userlog("connect database faid,code is %d",sqlca.sqlcode);
}
userlog("this application for testing proc login.");

return 0;
}

/*error processing*/
void sqlerror(int sqlcode,char * errmsg)
{
/*destroy username,userpwd,ipaddr*/
if(username!=NULL)
delete username;
if(userpwd!=NULL)
delete userpwd;
if(ipaddr!=NULL)
delete ipaddr;
cout<<"occur a error,sqlcode is "<<sqlcode<<",sql error message is:"<<errmsg<<endl;
EXEC SQL ROLLBACK WORK RELEASE;
}

void
#if defined(__STDC__) || defined(__cplusplus)
tpsvrdone(int argc,char* argv[])
#else
tpsvrdone(argc,argv)
int argc;
char** argv;
#endif
{
//EXEC SQL WHENEVER SQLERROR DO sqlerror(sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL COMMIT WORK RELEASE;

}

void readdbmsg()
{

xmlhelper helper("./database.xml");
ptree pt=helper.getnodechild("Config.DataSources.DataSource");
dbmsg.dbuser=helper.getnodevalue(pt,"UserName").c_str();
dbmsg.dbpwd =helper.getnodevalue(pt,"Password").c_str();
dbmsg.dbstr =helper.getnodevalue(pt,"Instance").c_str();
/*
dbmsg.dbuser="amsdbo";
dbmsg.dbpwd="181818";
dbmsg.dbstr="BOBUI";
*/
}

#ifdef __cplusplus
extern "C"
#endif
void
#if defined(__STDC__) || defined(__cplusplus)
Login(TPSVCINFO* info)
#else
Login(info)
TPSVCINFO *info;
#endif
{

/*get input values*/

int ID=Yss_Parse(info->data);
int usernamelen=Yss_GetValueLength(ID,"username")+1;
username=new char[usernamelen];
memset(username,0,usernamelen);
Yss_GetValue(ID,"username",username);

int userpwdlen=Yss_GetValueLength(ID,"userpwd")+1;
userpwd=new char[userpwdlen];
memset(userpwd,0,userpwdlen);
Yss_GetValue(ID,"userpwd",userpwd);

int ipaddrlen=Yss_GetValueLength(ID,"ipaddr")+1;
ipaddr=new char[ipaddrlen];
memset(ipaddr,0,ipaddrlen);
Yss_GetValue(ID,"ipaddr",ipaddr);

int ilanguagelen=Yss_GetValueLength(ID,"ilanguage")+1;
char* language=new char[ilanguagelen];
memset(language,0,ilanguagelen);
Yss_GetValue(ID,"ilanguage",language);
iLanguage=atoi(language);
delete language;

/*login business*/

if(username=="WZRiskSrv" && userpwd=="WZRiskSrv")
{
info->data="this user is 默认用户1";
}
else if(username=="Test" && userpwd=="Test")
{
info->data="this user is 默认用户2";
}
else
{

//string sqltextstr="select 1 from users where vc_usr='"+username+"' and (v_user_password='"+userpwd+"' or Password ='"+userpwd+"') and i_checkstate=1";
sprintf(sqltext,"select 1 from users where vc_usr='%s' and (v_user_password='%s' or Password ='%s') and i_checkstate=1",username,userpwd,userpwd) ;
//sqltext=sqltextstr.c_str();
//const char * csqltext=sqltext.c_str();
EXEC SQL PREPARE s FROM :sqltext;
EXEC SQL DECLARE cur_user CURSOR FOR s;
EXEC SQL OPEN cur_user;// USING :username,:userpwd,:userpwd;
while(true)
{
EXEC SQL FETCH cur_user into:datacount;
if(sqlca.sqlcode<0)
{
info->data="some error occur.";
break;
}
if(sqlca.sqlcode==SQLNOTFOUND)
{
break;
}
if(datacount>0)
{
info->data="this user is exist.";
break;
}
else
{
info->data="this user is not exist";
break;
}
}
EXEC SQL CLOSE cur_user;

/*EXECUTE LOGIN SQL*/
/*
EXEC SQL SELECT 1 INTO :datacount FROM users WHERE vc_usr=:username AND (v_user_password=:userpwd OR Password=:userpwd) AND i_checkstat=1;
if(datacount>0)
{
char * result="this user is exist.";
rqst->data=result;
}
else
{
char * result="this user is not exist.";
rqst->data=result;
}

}
*/
tpreturn(TPSUCCESS,0,info->data,0L,0);
}



请注意
#include "include/PacketInterface.h"
#include "xmlhelper.h"
这两个外部库不存在什么问题,已经在其他项目中成功使用。

...全文
83 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bobui 2012-01-30
  • 打赏
  • 举报
回复
问题找到了,编译环境问题。太郁闷了,搞了我一个星期。
mosaic 2012-01-29
  • 打赏
  • 举报
回复
这个专业了。又是oracle,又是tuxedo的。

报的错误是针对login.cc的,所以我觉得lz应该贴那个文件的内容。

另外代码太长了,能不能缩减到只留下有问题的部分?
bobui 2012-01-29
  • 打赏
  • 举报
回复
从login.pc编译到login.cc并无问题,从login.cc编译成login有错误:
错误1:
CMDTUX_CAT:4188: WARN: server built without the -s option cannot advertise services.
错误2:
login.cc:223: error: expected identifier before numeric constant
login.cc:223: error: expected unqualified-id before numeric constant
bobui 2012-01-29
  • 打赏
  • 举报
回复
编译文件sh.sh


#!/bin/bash

filetmp="login"
if [ -f ${filetmp}.cc ]; then
rm -fr ${filetmp}.cc
rm -fr ${filetmp}.lis
fi
if [ -f ${filetmp} ] ; then
rm -fr ${filetmp}
fi
proc ${filetmp}.pc userid=amsdbo/181818@BOBUI

buildserver -o ${filetmp} -f ${filetmp}.cc \
-f xmlhelper.cpp
-s Login -v -l"-L/usr/lib/oracle/11.2/client/lib -lclntsh -L./Lib -lPacketInterface -I/usr/include/oracle/11.2/client -I/home/oracle/tuxedo11gR1/include -I./"



24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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