📄 pbserver.c
字号:
/* Result Sets Interface */
#ifndef SQL_CRSR
# define SQL_CRSR
struct sql_cursor
{
unsigned int curocn;
void *ptr1;
void *ptr2;
unsigned long magic;
};
typedef struct sql_cursor sql_cursor;
typedef struct sql_cursor SQL_CURSOR;
#endif /* SQL_CRSR */
/* Thread Safety */
typedef void * sql_context;
typedef void * SQL_CONTEXT;
/* Object support */
struct sqltvn
{
unsigned char *tvnvsn;
unsigned short tvnvsnl;
unsigned char *tvnnm;
unsigned short tvnnml;
unsigned char *tvnsnm;
unsigned short tvnsnml;
};
typedef struct sqltvn sqltvn;
struct sqladts
{
unsigned int adtvsn;
unsigned short adtmode;
unsigned short adtnum;
sqltvn adttvn[1];
};
typedef struct sqladts sqladts;
static struct sqladts sqladt = {
1,1,0,
};
/* Binding to PL/SQL Records */
struct sqltdss
{
unsigned int tdsvsn;
unsigned short tdsnum;
unsigned char *tdsval[1];
};
typedef struct sqltdss sqltdss;
static struct sqltdss sqltds =
{
1,
0,
};
/* File name & Package Name */
struct sqlcxp
{
unsigned short fillen;
char filnam[13];
};
static const struct sqlcxp sqlfpn =
{
12,
"pbserver.cpp"
};
static unsigned long sqlctx = 311980;
static struct sqlexd {
unsigned int sqlvsn;
unsigned int arrsiz;
unsigned int iters;
unsigned int offset;
unsigned short selerr;
unsigned short sqlety;
unsigned int occurs;
const short *cud;
unsigned char *sqlest;
const char *stmt;
sqladts *sqladtp;
sqltdss *sqltdsp;
void **sqphsv;
unsigned int *sqphsl;
int *sqphss;
void **sqpind;
int *sqpins;
unsigned int *sqparm;
unsigned int **sqparc;
unsigned short *sqpadto;
unsigned short *sqptdso;
void *sqhstv[8];
unsigned int sqhstl[8];
int sqhsts[8];
void *sqindv[8];
int sqinds[8];
unsigned int sqharm[8];
unsigned int *sqharc[8];
unsigned short sqadto[8];
unsigned short sqtdso[8];
} sqlstm = {10,8};
/* SQLLIB Prototypes */
extern void sqlcxt (void **, unsigned long *,
struct sqlexd *, const struct sqlcxp *);
extern void sqlcx2t(void **, unsigned long *,
struct sqlexd *, const struct sqlcxp *);
extern void sqlbuft(void **, char *);
extern void sqlgs2t(void **, char *);
extern void sqlorat(void **, unsigned long *, void *);
/* Forms Interface */
static const int IAPSUCC = 0;
static const int IAPFAIL = 1403;
static const int IAPFTL = 535;
extern void sqliem(char *, int *);
static const char *sq0001 =
"select EMPNO ,ENAME ,JOB ,MGR ,to_char(HIREDATE,'yyyy/mm/dd hh24:mi:ss') ,S\
AL ,COMM ,DEPTNO from EMP ";
static const char *sq0005 =
"select EMPNO ,ENAME ,JOB ,MGR ,to_char(HIREDATE,'yyyy/mm/dd hh24:mi:ss') ,S\
AL ,COMM ,DEPTNO from EMP ";
static const char *sq0006 =
"select distinct deptno from EMP ";
typedef struct { unsigned short len; unsigned char arr[1]; } VARCHAR;
typedef struct { unsigned short len; unsigned char arr[1]; } varchar;
/* cud (compilation unit data) array */
static const short sqlcud0[] =
{10,4130,0,0,0,
5,0,0,1,113,0,521,215,0,0,0,0,0,1,0,
20,0,0,1,0,0,527,218,0,0,0,0,0,1,0,
35,0,0,1,0,0,525,234,0,0,8,0,0,1,0,2,3,0,0,2,5,0,0,2,5,0,0,2,3,0,0,2,5,0,0,2,4,
0,0,2,4,0,0,2,3,0,0,
82,0,0,1,0,0,527,243,0,0,0,0,0,1,0,
97,0,0,1,0,0,527,265,0,0,0,0,0,1,0,
112,0,0,1,0,0,527,271,0,0,0,0,0,1,0,
127,0,0,1,0,0,527,278,0,0,0,0,0,1,0,
142,0,0,1,0,0,527,285,0,0,0,0,0,1,0,
157,0,0,1,0,0,527,292,0,0,0,0,0,1,0,
172,0,0,1,0,0,527,299,0,0,0,0,0,1,0,
187,0,0,1,0,0,527,306,0,0,0,0,0,1,0,
202,0,0,1,0,0,527,313,0,0,0,0,0,1,0,
217,0,0,1,0,0,527,318,0,0,0,0,0,1,0,
232,0,0,2,85,0,518,350,0,0,5,5,0,1,0,1,3,0,0,1,5,0,0,2,3,0,0,2,3,0,0,2,97,0,0,
267,0,0,3,33,0,514,458,0,0,1,1,0,1,0,1,3,0,0,
286,0,0,4,135,0,515,465,0,0,8,8,0,1,0,1,3,0,0,1,5,0,0,1,5,0,0,1,3,0,0,1,5,0,0,
1,4,0,0,1,4,0,0,1,3,0,0,
333,0,0,5,113,0,521,518,0,0,0,0,0,1,0,
348,0,0,5,0,0,527,521,0,0,0,0,0,1,0,
363,0,0,5,0,0,525,537,0,0,8,0,0,1,0,2,3,0,0,2,5,0,0,2,5,0,0,2,3,0,0,2,5,0,0,2,
4,0,0,2,4,0,0,2,3,0,0,
410,0,0,5,0,0,527,546,0,0,0,0,0,1,0,
425,0,0,5,0,0,527,557,0,0,0,0,0,1,0,
440,0,0,5,0,0,527,563,0,0,0,0,0,1,0,
455,0,0,5,0,0,527,570,0,0,0,0,0,1,0,
470,0,0,5,0,0,527,577,0,0,0,0,0,1,0,
485,0,0,5,0,0,527,584,0,0,0,0,0,1,0,
500,0,0,5,0,0,527,591,0,0,0,0,0,1,0,
515,0,0,5,0,0,527,598,0,0,0,0,0,1,0,
530,0,0,5,0,0,527,605,0,0,0,0,0,1,0,
545,0,0,5,0,0,527,610,0,0,0,0,0,1,0,
560,0,0,6,44,0,521,662,0,0,0,0,0,1,0,
575,0,0,6,0,0,527,665,0,0,0,0,0,1,0,
590,0,0,6,0,0,525,672,0,0,1,0,0,1,0,2,3,0,0,
609,0,0,6,0,0,527,681,0,0,0,0,0,1,0,
624,0,0,7,49,0,516,691,0,0,2,1,0,1,0,2,5,0,0,1,3,0,0,
647,0,0,6,0,0,527,703,0,0,0,0,0,1,0,
662,0,0,6,0,0,527,708,0,0,0,0,0,1,0,
677,0,0,8,51,0,516,725,0,0,2,1,0,1,0,2,4,0,0,1,3,0,0,
};
#include <stdio.h>
#include <atmi.h>
#include <userlog.h>
#include <fml32.h>
#include "tbl_fml.h"
/* EXEC SQL INCLUDE sqlca;
*/
/*
* $Header: sqlca.h,v 1.3 1994/12/12 19:27:27 jbasu Exp $ sqlca.h
*/
/* Copyright (c) 1985,1986, 1998 by Oracle Corporation. */
/*
NAME
SQLCA : SQL Communications Area.
FUNCTION
Contains no code. Oracle fills in the SQLCA with status info
during the execution of a SQL stmt.
NOTES
**************************************************************
*** ***
*** This file is SOSD. Porters must change the data types ***
*** appropriately on their platform. See notes/pcport.doc ***
*** for more information. ***
*** ***
**************************************************************
If the symbol SQLCA_STORAGE_CLASS is defined, then the SQLCA
will be defined to have this storage class. For example:
#define SQLCA_STORAGE_CLASS extern
will define the SQLCA as an extern.
If the symbol SQLCA_INIT is defined, then the SQLCA will be
statically initialized. Although this is not necessary in order
to use the SQLCA, it is a good pgming practice not to have
unitialized variables. However, some C compilers/OS's don't
allow automatic variables to be init'd in this manner. Therefore,
if you are INCLUDE'ing the SQLCA in a place where it would be
an automatic AND your C compiler/OS doesn't allow this style
of initialization, then SQLCA_INIT should be left undefined --
all others can define SQLCA_INIT if they wish.
If the symbol SQLCA_NONE is defined, then the SQLCA variable will
not be defined at all. The symbol SQLCA_NONE should not be defined
in source modules that have embedded SQL. However, source modules
that have no embedded SQL, but need to manipulate a sqlca struct
passed in as a parameter, can set the SQLCA_NONE symbol to avoid
creation of an extraneous sqlca variable.
MODIFIED
lvbcheng 07/31/98 - long to int
jbasu 12/12/94 - Bug 217878: note this is an SOSD file
losborne 08/11/92 - No sqlca var if SQLCA_NONE macro set
Clare 12/06/84 - Ch SQLCA to not be an extern.
Clare 10/21/85 - Add initialization.
Bradbury 01/05/86 - Only initialize when SQLCA_INIT set
Clare 06/12/86 - Add SQLCA_STORAGE_CLASS option.
*/
#ifndef SQLCA
#define SQLCA 1
struct sqlca
{
/* ub1 */ char sqlcaid[8];
/* b4 */ int sqlabc;
/* b4 */ int sqlcode;
struct
{
/* ub2 */ unsigned short sqlerrml;
/* ub1 */ char sqlerrmc[70];
} sqlerrm;
/* ub1 */ char sqlerrp[8];
/* b4 */ int sqlerrd[6];
/* ub1 */ char sqlwarn[8];
/* ub1 */ char sqlext[8];
};
#ifndef SQLCA_NONE
#ifdef SQLCA_STORAGE_CLASS
SQLCA_STORAGE_CLASS struct sqlca sqlca
#else
struct sqlca sqlca
#endif
#ifdef SQLCA_INIT
= {
{'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '},
sizeof(struct sqlca),
0,
{ 0, {0}},
{'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
}
#endif
;
#endif
#endif
/* end SQLCA */
/*RELEASE_CURSOR=YES 使PROC 在执行后释放与嵌入SQL有关资源*/
/* EXEC ORACLE OPTION (RELEASE_CURSOR = YES); */
#define SQLNOTFOUND 1403 /*SELECT没取到数据*/
#define SQLNULL -1405 /*当取出的值是null时,sqlca.sqlcode = -1405*/
#define _DEBUG_ /*调试*/
/*如果在表中是字符型的变量(CHAR,VARCHAR,VARCHAR2,定义为CHAR,长度为表中的长度加1,
整型定义为LONG或INT,浮点型定义为DOUBLE或FLOAT,如果是特别大的数,如:NUMBER(15)可定义
为CHAR型,但要做改变)*/
/* EXEC SQL BEGIN DECLARE SECTION; */
/* varchar vc_user[20]; */
struct { unsigned short len; unsigned char arr[20]; } vc_user;
char c_user[30]="";
char c_passwd[30]="";
/*定义输入参数:*/
long al_empno=0;
long al_mgr=0;
long al_deptno=0;
char ac_ename[11]="";
char ac_job[10]="";
char ac_hiredate[20]="";
double af_sal=0;
double af_comm=0;
long l_errno=0;
long l_return=0;
char c_errtext[256]="";
char c_tmp[256]="";
char ac_nodeno[9]="";
char ac_begin_date[8]="";
char ac_end_date[8]="";
char c_code[3]="";
char c_content[15]="";
char c_amount[13]="";
char c_litter[13]="";
char c_nodename[61]="";
/*重新定义STRING变量,使其自动加上'\0',如果是CHAR形的则不能重新定义成STRING变量*/
/* EXEC SQL VAR ac_ename IS STRING(11); */
/* EXEC SQL VAR ac_job IS STRING(11); */
/* EXEC SQL VAR ac_hiredate IS STRING(11); */
/* EXEC SQL VAR c_tmp IS STRING(11); */
/* EXEC SQL VAR ac_nodeno IS STRING(9); */
/* EXEC SQL VAR ac_begin_date IS STRING(8); */
/* EXEC SQL VAR ac_end_date IS STRING(8); */
/* EXEC SQL VAR c_code IS STRING(3); */
/* EXEC SQL VAR c_content IS STRING(15); */
/* EXEC SQL VAR c_amount IS STRING(13); */
/* EXEC SQL VAR c_litter IS STRING(13); */
/* EXEC SQL VAR c_nodename IS STRING(61); */
/*定义指示器变量*/
/*short ind_empno=0;
short ind_mgr=0;
short ind_deptno=0;
short ind_ename=0;
short ind_job=0;
short ind_hiredate=0;
short ind_sal=0;
short ind_comm=0;
*/
/* EXEC SQL END DECLARE SECTION; */
/*出错返回*/
int tux_return(FBFR32 *sendbuf, char *szErrInfo,long sqlcode,char *szErrText)
{
FLDLEN32 len=0;
len=sizeof(szErrInfo);
Fchg32(sendbuf, ERRINFO, 0,szErrInfo, len);
len = sizeof(sqlcode);
Fchg32( sendbuf, SQLCODE, 0, (char *)&sqlcode, len);
len=sizeof(szErrText);
Fchg32(sendbuf, ERRTEXT, 0,szErrText, len);
tpreturn(TPFAIL, 0, (char *)sendbuf, 0L, 0);
return 0;
}
/*分配返回缓冲区并初始化*/
FBFR32* IniSendBuf(int iSize)
{
FBFR32 *sendbuf=NULL;
FLDLEN32 len=0;
sendbuf = (FBFR32 *)tpalloc( "FML32",NULL,iSize);
if(sendbuf==(FBFR32 *)NULL)
{
userlog("tpalloc() failure\n");
return NULL;
}
len = Fsizeof32(sendbuf);
(void)Finit32(sendbuf,len);
(void)Fchg32(sendbuf, ERRINFO, 0, "", (FLDLEN32)0);
(void)Fchg32(sendbuf, SQLCODE, 0, 0, (FLDLEN32)0);
(void)Fchg32(sendbuf, ERRTEXT, 0, "", (FLDLEN32)0);
return sendbuf;
}
/*
int tpsvrinit(argc, argv)
int argc;
char *argv[];
{
//连接数据库
strcpy(vc_user.arr,"scott/tiger");
vc_user.len=11;
exec sql connect :vc_user;
if(sqlca.sqlcode!=0)
{
tpreturn(TPFAIL, 0, 0, 0L, 0);
}
strcpy(vc_user.arr,"test_hs/boc_hs");
vc_user.len=14;
exec sql connect :vc_user;
if(sqlca.sqlcode!=0)
{
tpreturn(TPFAIL, 0, 0, 0L, 0);
}
return 0;
}
void tpsvrdone()
{
tpclose();
}
*/
int tpsvrinit(argc, argv)
int argc;
char *argv[];
{
if (tpopen() == -1) {
(void)userlog("tpsvrinit: failed to open database due to ");
switch (tperrno) {
case TPEOS:
//(void)userlog("tpopen failed, Unix error %d\n",Uunixerr);
break;
case TPERELEASE:
(void)userlog("tpopen failed, Incompatible release\n");
break;
default:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -