三、服务端的程序:test.cp
功能:根据客户端传的EMPNO到表EMP中取ENAME的值,并把它返回给客户端
#include <atmi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sybhesql.h>
#include <sybtesql.h>
EXEC SQL INCLUDE sqlca;
EXEC SQL BEGIN DECLARE SECTION;
long al_empno=0;
char ac_ename[11]="";
EXEC SQL END DECLARE SECTION;
TEST(TPSVCINFO *rqst)
{
/*接收客户端来的数据*/
al_empno = (FBFR32 *)rqst->data;
EXEC SQL select ename into :ac_ename from EMP where empno=:al_empno;
if(sqlca.sqlcode!=0)
{
userlog("select from EMP failure,sqlca.sqlcode=%ldn",sqlca.sqlcode);
tpreturn( TPFAIL, 0, rqst->data, 0, 0 );
}
/*把取出的结果返回给客户端*/
strcpy(rqst->data,ac_ename);
tpreturn( TPSUCCESS, 0, rqst->data, 0, 0 );
}
四、编写客户端程序: testcli.c
功能:调用TUXEDO服务端的服务TEST,取EMPNO=1000所对应的ENAME的值,并显示出来
#include <stdio.h>
#include "atmi.h"
main(argc, argv)
{
long reqlen=1024;
char *reqbuf;
/* 与TUXEDO服务端建立连接 */
if (tpinit((TPINIT *) NULL) == -1)
{
(void) fprintf(stderr, "Tpinit failedn");
exit(1);
}
/* 分配发送缓冲区*/
reqbuf = (char *)tpalloc("STRING",NULL,reqlen);
if ( reqbuf == (char *)NULL)
{
printf("tpalloc failedn");
tpterm();
}
strcpy(reqbuf,"1000");
/*调用TUXEDO的服务TEST*/
if (tpcall("TEST", (char *)reqbuf, 0L, (char **)&reqbuf, (long *)&reqlen, 0< 0 )
{
printf("tpcall failed,tperrno=%ld,tperrtext=%sn",tperrno,tpstrerror(tperrno));
tpfree(reqbuf);
tpterm();
exit(1);
}
printf("name=%sn",reqbuf);
tpfree(reqbuf);
tpterm();
return(0);
}
五、编译服务端程序
1.用INFORMIX的esql把test.pc 文件预编译成test.c文件
/usr/tuxedo/simpdb/esql -c test.pc -I$INFORMIXDIR/incl/esql
2.用buildserver把test.c编译成可执行文件,注意-r 后带的INFORMIX-DSHC与RM文件中的一致。
/usr/tuxedo/simpdb/buildserver -o simpserv -f simpserver.c -r INFORMIX-DSHC -s TEST
六、编译客户端程序
/usr/tuxedo/simpdb/buildclient -o testcli -f testcli.c
七、用tmboot启动TUXEDO,应能看到所有的SERVER都启动成功.这时,我们的服务端程序test 会自动与INFORMIX数据库建立连接,并一直保持这个连接,直到TUXEDO系统或INFORMIX数据库关闭.所以在我们的程序test.cp中看不到与数据库连接的语句,因为现在与数据库的连接由TUXEDO自动管理.
/usr/tuxedo/simpdb/ tmboot -y
exec TMS_INFORMIX -A :
process id=1072 ... Started.
exec TMS_INFORMIX -A :
process id=528 ... Started.
exec test -A :
process id=876 ... Started.
八、运行客户端程序,应能看到服务端返回的结果
/usr/tuxedo/simpdb/ testcli
name=bill
到此,整个配置过程就大功告成了.INFORMIX的其他版本的配置及在其他操作系统上的配置基本与本文所述差不多,差别主要在RM文件中所连的库文件可能会不样.使用esql -libs 命令得到应用所需的数据库动态连接库.再加上INFORMIX支持XA的库libinfxxa.a,注意在INFORMIX9.13之后,libinfxxa.a 的名字变了,不支持多线程的为libifxa.a,支持多线程的为libthxa.a。
如在环境为:AIX 4.3.3, Tuxedo7.1, Informix Dynamic Server 9.21, Esql/C 9.51 中RM为:
INFORMIX-ONLINE:infx_xa_switch:$/lib/esql/libifxa.a -L$/lib -L$/lib/esql -lifsql -lifasf -lifgen -lifos -lifgls -lnetstub -lc_r -ldl -ltli_r -lm_r $/lib/esql/checkapi.o -lifglx
在环境为:AIX 4.3.3, Tuxedo6.5, Informix7.3中RM为:
INFORMIX-OnLine:infx_xa_switch:$/lib/esql/libinfxxa.a -L$/lib -L$/lib/esql -lixsqlshr -lixasfshr -lixgenshr -lixosshr -lixglsshr $/lib/esql/checkapi.o -lixglx
如果TMS_INFORMIX启动不成功,查看ULOG文件,根据ULOG文件的信息进行排错.
关于AIX操作系统下系统接口程序移植问题的报告
[开发环境]
操作系统AIX4.3.3、中间件TUXEDO6.5、数据库INFORMIX ESQL 7.24.UC8、开发语言ESQL/C
[环境变量]
#INFORMIX
export INFORMIXDIR=/usr/users/informix
export INFORMIXSERVER=online100
export ONCONFIG=onconfig.100
export TERM=vt100
export TERMCAP=$INFORMIXDIR/etc/termcap
export
export
export PATH=$PATH:$INFORMIXDIR/bin:$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:$HOME/tools/bin:.
#TUXEDO
export TUXDIR=/usr/users/tuxedo
export PATH=$PATH:$TUXDIR/bin:$PATH
COBCPY=:$TUXDIR/cobinclude; export COBCPY
BOPT="-C ANS85 -C ALIGN=8 -C NOIBMCOMP -C TRUNC=ANSI -C OSEXT=cbl"; export COBOPT
PATH=$PATH:$INFORMIXDIR/bin:/usr/ibmcxx/bin
export PATH
export LIBPATH=$TUXDIR/lib:$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:/lib:/usr/lib:
$INFORMIXDIR/incl/esql:$LIBPATH
OSTYPE=AIX;export OSTYPE
[编译文件]
#城综网与业务系统接口的makefile文件
LIBDEP = $(HOME)/lib/SubTrx.a $(HOME)/lib/libmiddleware.a $(HOME)/lib/libsbsapi.a
LINKLIB =-L/usr/users/informix/lib/esql -L/usr/users/informix/lib -lc -lm -ll
OBJ = cs_trans.o pub.o
BINPATH=$(HOME)/bin
CFLAGS= -EDmCltSys -c
CCOPT= -qchars=signed -qcpluscmt -DHIGHFIRST -bstatic
all: $(BINPATH)/cs_trans
$(BINPATH)/cs_trans: $(OBJ)
buildclient -w -o $(HOME)/bin/cs_trans -f "$(OBJ) $(LIBDEP) $(LINKLIB)"
rm -f cs_trans.o
rm -f pub.o
cs_trans.o: cs_trans.ec
esql -I$(HOME)/inc -I$(TUXDIR)/include $(CFLAGS) $(CCOPT) cs_trans.ec
rm -f cs_trans.c
pub.o: pub.ec
[标准输出]
esql -I/usr/DATAS/zqywsrc/inc -I/usr/users/tuxedo/include -EDmCltSys -c -qchars=signed -qcpluscmt -DHIGHFIRST -bstatic cs_trans.ec
rm -f cs_trans.c
esql -I/usr/DATAS/zqywsrc/inc/ -EDmCltSys -c -qchars=signed ?qcpluscmt -DHIGHFIRST -bstatic pub.ec
rm -f pub.c
buildclient -w -o /usr/DATAS/zqywsrc/bin/cs_trans -f "cs_trans.o pub.o
/usr/DATAS/zqywsrc/lib/SubTrx.a /usr/DATAS/zqywsrc/lib/libmiddleware.a /usr/DATAS/zqywsrc/lib/libsbsapi.a -L/usr/users/informix/lib/esql -L/usr/users/informix/lib -lc -lm -ll"
[错误输出]
"cs_trans.ec", line 315.69: 1506-280 (W) Function argument assignment between types "unsigned long*" and "int*" is not allowed.
"pub.ec", line 386.13: 1506-068 (W) Operation between types "signed char*" and "int" is not allowed.
ld: 0711-317 ERROR: Undefined symbol: ._iqdbase
ld: 0711-317 ERROR: Undefined symbol: SQLCODE
ld: 0711-317 ERROR: Undefined symbol: ._iqstmnt
ld: 0711-317 ERROR: Undefined symbol: ._iqdbclose
ld: 0711-317 ERROR: Undefined symbol: ._iqslct
ld: 0711-317 ERROR: Undefined symbol: .sqldetach
ld: 0711-317 ERROR: Undefined symbol: ._iqnprep
ld: 0711-317 ERROR: Undefined symbol: sqlca
ld: 0711-317 ERROR: Undefined symbol: ._iqlocate_cursor
ld: 0711-317 ERROR: Undefined symbol: ._iqdescribe
ld: 0711-317 ERROR: Undefined symbol: .rtypmsize
ld: 0711-317 ERROR: Undefined symbol: .rtypalign
ld: 0711-317 ERROR: Undefined symbol: ._iqcddcl
ld: 0711-317 ERROR: Undefined symbol: ._iqdcopen
ld: 0711-317 ERROR: Undefined symbol: ._iqcftch
ld: 0711-317 ERROR: Undefined symbol: .dectoasc
ld: 0711-317 ERROR: Undefined symbol: .rdatestr
ld: 0711-317 ERROR: Undefined symbol: .stleng
ld: 0711-317 ERROR: Undefined symbol: ._iqclose
ld: 0711-317 ERROR: Undefined symbol: ._iqfree
ld: 0711-317 ERROR: Undefined symbol: ._iqexecute
ld: 0711-317 ERROR: Undefined symbol: .rdefmtdate
ld: 0711-317 ERROR: Undefined symbol: ._iqbeginwork
ld: 0711-317 ERROR: Undefined symbol: ._iqcdcl
ld: 0711-317 ERROR: Undefined symbol: ._iqcommit
ld: 0711-317 ERROR: Undefined symbol: .rfmtdate
ld: 0711-317 ERROR: Undefined symbol: ._iqrollback
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
CMDTUX_CAT:512: ERROR: Cannot execute C compiler cc -I$TUXDIR/include -o /usr/DATAS/zqywsrc/bin/cs_trans -L$/lib cs_trans.o pub.o /usr/DATAS/zqywsrc/lib/SubTrx.a /usr/DATAS/zqywsrc/lib/libmiddleware.a /usr/DATAS/zqywsrc/lib/libsbsapi.a -L/usr/users/informix/lib/esql -L/usr/users/informix/lib -lc -lm -ll -lwsc -lbuft -lwsc -lnws -lnwi -lnws -lfml -lfml32 -lgp
make: 1254-004 The error code from the last command is 8.