1.服务端:
#include <stdio.h>
#include <ctype.h>
#include <atmi.h> /* TUXEDO Header File */
#include <userlog.h> /* TUXEDO Header File */
#include <ctype.h>
#include <atmi.h> /* TUXEDO Header File */
#include <userlog.h> /* TUXEDO Header File */
EXEC SQL INCLUDE sqlca;
tpsvrinit(int argc, char *argv[])
{
if (tpopen() == -1)
{
printf("connect to Informix error\n");
return -1;
}
printf("svrDelete connected to Informix\n");
return(0);
}
{
if (tpopen() == -1)
{
printf("connect to Informix error\n");
return -1;
}
printf("svrDelete connected to Informix\n");
return(0);
}
delete(TPSVCINFO *rqst)
{
EXEC SQL BEGIN DECLARE section;
int db_code;
char db_string[10];
EXEC SQL END DECLARE section;
db_code = atoi(rqst->data);
EXEC SQL delete from simple where id=:db_code;
if (sqlca.sqlcode != 0) /*检查是否出错 */
{
printf("insert error");
tpreturn(TPFAIL, 0, NULL, 0, 0);
}
{
EXEC SQL BEGIN DECLARE section;
int db_code;
char db_string[10];
EXEC SQL END DECLARE section;
db_code = atoi(rqst->data);
EXEC SQL delete from simple where id=:db_code;
if (sqlca.sqlcode != 0) /*检查是否出错 */
{
printf("insert error");
tpreturn(TPFAIL, 0, NULL, 0, 0);
}
tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);
}
void tpsvrdone()
{
if (tpclose() == -1)
{
printf("disconnect to Informix error\n");
return;
}
}
2.客户端:
#include <stdio.h>
#include "atmi.h" /* TUXEDO Header File */
#include "atmi.h" /* TUXEDO Header File */
main(int argc, char *argv[])
{
char *sendbuf, *rcvbuf;
long sendlen, rcvlen;
int ret;
long sendlen, rcvlen;
int ret;
if(argc != 2) {
(void) fprintf(stderr, "Usage: simpcl string\n");
exit(1);
}
(void) fprintf(stderr, "Usage: simpcl string\n");
exit(1);
}
/* Attach to System/T as a Client Process */
if (tpinit((TPINIT *) NULL) == -1) {
(void) fprintf(stderr, "Tpinit failed\n");
exit(1);
}
sendlen = strlen(argv[1]);
if (tpinit((TPINIT *) NULL) == -1) {
(void) fprintf(stderr, "Tpinit failed\n");
exit(1);
}
sendlen = strlen(argv[1]);
/* Allocate STRING buffers for the request and the reply */
if((sendbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {
(void) fprintf(stderr,"Error allocating send buffer\n");
tpterm();
exit(1);
}
(void) fprintf(stderr,"Error allocating send buffer\n");
tpterm();
exit(1);
}
if((rcvbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {
(void) fprintf(stderr,"Error allocating receive buffer\n");
tpfree(sendbuf);
tpterm();
exit(1);
}
(void) fprintf(stderr,"Error allocating receive buffer\n");
tpfree(sendbuf);
tpterm();
exit(1);
}
(void) strcpy(sendbuf, argv[1]);
/*
ret=tpbegin(10,0);
if (ret == -1)
{
(void) fprintf(stderr, "Can''t begin trans\n");
(void) fprintf(stderr, "Tperrno = %d\n", tperrno);
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
exit(1);
}
*/
/* Request the service delete, waiting for a reply */
ret = tpcall("delete", (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0);
/*
ret=tpbegin(10,0);
if (ret == -1)
{
(void) fprintf(stderr, "Can''t begin trans\n");
(void) fprintf(stderr, "Tperrno = %d\n", tperrno);
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
exit(1);
}
*/
/* Request the service delete, waiting for a reply */
ret = tpcall("delete", (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0);
if(ret == -1) {
(void) fprintf(stderr, "Can''t send request to service delete\n");
(void) fprintf(stderr, "Tperrno = %d, %s\n, ", tperrno, tpstrerror(tperrno));
tpfree(sendbuf);
tpfree(rcvbuf);
/*
tpabort(0);
*/
tpterm();
exit(1);
}
(void) fprintf(stderr, "Can''t send request to service delete\n");
(void) fprintf(stderr, "Tperrno = %d, %s\n, ", tperrno, tpstrerror(tperrno));
tpfree(sendbuf);
tpfree(rcvbuf);
/*
tpabort(0);
*/
tpterm();
exit(1);
}
/*
tpcommit(0);
*/
(void) fprintf(stdout, "Returned string is: %s\n", rcvbuf);
tpcommit(0);
*/
(void) fprintf(stdout, "Returned string is: %s\n", rcvbuf);
/* Free Buffers & Detach from System/T */
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
return(0);
}
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
return(0);
}