⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i_sql.ec

📁 在SCO UNIX制定界面程序 可根据文件配制菜单,而不必修改源程序,非常方便
💻 EC
📖 第 1 页 / 共 3 页
字号:
EXEC SQL INCLUDE sqlda;
EXEC SQL INCLUDE sqltypes;
EXEC SQL INCLUDE sqlca;

EXEC SQL WHENEVER SQLERROR CALL error_handler;
EXEC SQL WHENEVER SQLWARNING CALL warning_handler;
EXEC SQL WHENEVER NOT FOUND CALL notfound_handler;

$char *sql_str;
$char cnt_sql_str[1024];
$char ent_sql_str[1024];
$char sql_ls_str[4096];
char	re_query = 0;

#define DSTRSZ  40
#define ITEMS	256

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "macro_def.h"
$include "db_struct.h";
#include "errmesg_macro.h"
#include "pub_form.h"	/* current */
#include "mytools.h"
#include "menu.h"
#include "public.h"
#include "msgsys.h"
#include "tool.h"
#include "new_monitor.h"

#include "sys_role.h"
#include "cen_oper.h"
#include "card_type.h"
#include "audit.h"
#include "dayacct.h"


$S_hand_ls hand_ls;
$S_tran_ls m_tranls;


int	do_query  = 0;  /* 等于1处于查询状态 */
int	do_insert = 0;  /* 等于1处于插入状态 */
int	do_update = 0;  /* 等于1处于修改状态 */
int	do_delete = 0;  /* 等于1处于删除状态 */
int	his_query = 0;  /* 等于1处于查询状态 */
int     use_cursor_1;
		/* 通过比较 G_cen_bankid和G_bankid 确定 默认为省行柜员 */


$extern char G_oper_no[];
$extern char loper[7];

WINDOW *sql_win, *qgd_win, *hand_win;
S_tran_ls *tranls_ptr;


struct sqlda *udesc;
struct screen_st scr;
char rowid[20], *mstr, tip[80];
int special = 0;

static char *buffer = NULL;
static int que_row, all_rows;
static int use_cursor, init = 0;
static char scr_dump_filename[128];

static long compute_size();
extern int get_short_power(), get_long_power();
extern double calc_double();


/*******
说明:	界面数据库函数通过what_table()锁定表名,
	读出窗口各个域的值和对应域名和表名组合查询, 修改, 插入, 删除串
*******/

int	disp_table_screen(item_no)
int	item_no;
{
	long	q_size = 0;
	struct field_st *f_ptr;

	if (what_table(item_no, &scr) == -1)
		return(-1);

/************
	sprintf(scr_dump_filename, "/tmp/.table.%d", getpid());
	scr_dump(scr_dump_filename);
*************/

	sql_win = newwin(17, 80, 3, 0);
	wrefresh(sql_win);

	set_prompt(PROMPT_ON);
	clear_screen(sql_win);
	clear_fields(scr.fields);
	if (disp_screen(sql_win, &scr) < 0) {
		delwin(sql_win);
		return(-1);
	}
	h_prompt(20, 0, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━", 0, 0);
	h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);

	f_ptr = scr.fields;
	strcpy(tip, SMenuItem[item_no].sName + 2);
	h_prompt(LINES-1, 1, tip, 0, 0);
	DispBelow(tip);

	q_size = 0;
	while (1) {
	    if (!(MV_FORM(f_ptr->option) || MV_EXCEL(f_ptr->option)))
		q_size += strlen(f_ptr->field_name) + f_ptr->f_width + 50;
	    if (MV_END(f_ptr->option)) break;
	    f_ptr++;
	}
	q_size += 50;
	if ((sql_str = (char *)malloc(q_size)) == NULL) {
	    beep();
	    h_prompt(LINES-1, 1, "内存不足,按任意键继续... ", 1, 2);
	    return(-1);
	}

	f_ptr = scr.fields;
	q_size = 0;
	while (1) {
	    q_size += f_ptr->f_width + 10;
	    if (MV_END(f_ptr->option)) break;
	    f_ptr++;
	}
	if ((mstr = (char *)malloc(q_size)) == NULL) {
	    beep();
	    h_prompt(LINES-1, 1, "内存不足,按任意键继续... ", 1, 2);
	    return(-1);
	}

	use_cursor = do_query =  do_update =  do_insert =  do_delete = 0;
}

int	sql_query(item_no)
int	item_no;
{
	int i;
	long pos;
	char tmp[200];
	struct sqlvar_struct *col;

	re_query = 0;

	do_query = 1;
	clear_wline(sql_win, 16);
	clear_fields(scr.fields);

	if (disp_screen(sql_win, &scr) < 0) {
		do_query = 0;
		return(-1);
	}

	h_prompt(LINES-1, 1, "                      CTRL-W : 帮助   CTRL-U : 放弃当前操作                   ", 0, 0);
	h_prompt(LINES-1, 1, "请输入查询条件      ", 0, 2);
	if ( get_screen( sql_win, &scr, 0 ) == -1 ) {
		clear_fields( scr.fields );
		disp_screen( sql_win, &scr );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		do_query = 0;
		return(-1);
	}
	clear_wline(sql_win, 16);
	h_prompt(LINES-1, 1, "                                                                              ", 0, 0);
	if ( make_que_str( &scr, sql_str, scr.tablename, 1 ) ) {
		beep();
		h_prompt( LINES-1, 1, "构造查询串失败,按任意键继续... ", 1, 2 );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		do_query = 0;
		return(-1);
	}

	strcpy(cnt_sql_str, sql_str);

	if ( (all_rows = query_count(sql_str)) == 0 ) {
		h_winprompt( sql_win, 16, 1, "没有满足条件的记录... ", 0, 0 );
		do_query = 0;
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		return(-1);
	}

	if ( make_que_str( &scr, sql_str, scr.tablename, 0 ) ) {
		beep();
		h_prompt( LINES-1, 1, "构造查询串失败,按任意键继续... ", 1, 2 );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		do_query = 0;
		return( -1 );
	}

	strcpy(ent_sql_str, sql_str);

	/* 预处理 select 语句 */

	EXEC SQL PREPARE usqlobj FROM $sql_str;
	if ( SQLCODE ) {
		errcall(ERROR, "Prepare Query Error : SQLCODE[%d] SQLERRD[%d]",
			SQLCODE, sqlca.sqlerrd[1]);
		beep();
		h_prompt( LINES-1, 1, "查询失败,按任意键继续... ", 1, 2 );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		do_query = 0;
		return( -1 );
	}

	EXEC SQL DESCRIBE usqlobj INTO udesc;
	if ( SQLCODE ) {
		errcall(ERROR, "Describe Error : SQLCODE[%d] SQLERRD[%d]",
			SQLCODE, sqlca.sqlerrd[1]);
		beep();
		h_prompt( LINES-1, 1, "查询失败,按任意键继续... ", 1, 2 );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		do_query = 0;
		return( -1 );
	}

	pos = compute_size( udesc );
	if (buffer) free(buffer);
	buffer = (char *)malloc( pos );
	if ( buffer == NULL ) {
		beep();
		h_prompt( LINES-1, 1, "内存不足,按任意键继续... ", 1, 2 );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		do_query = 0;
		return( -1 );
	}

	/* 给每个 sqlda 结构 udesc 赋地址 */

	pos = 0;
	for ( col = udesc->sqlvar, i = 0; i < udesc->sqld; col++, i++ ) {
		pos = rtypalign( pos, col->sqltype );
		col->sqldata = buffer + pos;
		pos += col->sqllen;
		if ( col->sqltype != CDECIMALTYPE ) pos++;
	}

	/* Fetch 每一记录行, 把各类型的数据转换成ASCII格式 */

	EXEC SQL DECLARE usqlcurs SCROLL CURSOR FOR usqlobj ;
	EXEC SQL OPEN usqlcurs;

	if ( SQLCODE ) {
		errcall(ERROR, "Query Open Error : SQLCODE[%d] SQLERRD[%d]",
			SQLCODE, sqlca.sqlerrd[1]);
		beep();
		h_prompt( LINES-1, 1, "查询失败,按任意键继续... ", 1, 2 );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		do_query = 0;
		return( -1 );
	}

	EXEC SQL FETCH usqlcurs USING DESCRIPTOR udesc;
	if ( SQLCODE != 0 ) {
		errcall(ERROR, "Fetch Error : SQLCODE[%d] SQLERRD[%d]",
			SQLCODE, sqlca.sqlerrd[1]);
		beep();
		h_prompt( LINES-1, 1, "查询失败,按任意键继续... ", 1, 2 );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		EXEC SQL CLOSE usqlcurs;
		do_query = 0;
		return( -1 );
	}
	use_cursor = 1;

	get_data_from_sqlda(udesc, rowid, &scr);

	que_row = 1;
	sprintf(tmp, "第 %d/%d 条记录", que_row, all_rows);
	h_winprompt(sql_win, 16, 1, tmp, 0, 0);
	h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
	h_prompt(LINES-1, 1, tip, 0, 0);

	disp_fields( sql_win, scr.fields );
	return( 0 );
}

int	sql_requery(item_no, cur_row)
int	item_no, cur_row;
{
	int i;
	long pos;
	char tmp[200];
	struct sqlvar_struct *col;
	$int	tmp_row;

	if (re_query)
		EXEC SQL CLOSE usqlcurs2;

	if ( (all_rows = query_count(cnt_sql_str)) == 0 ) {
		return(-1);
	}

	/* 预处理 select 语句 */
	EXEC SQL PREPARE usqlobj2 FROM $ent_sql_str;
	if ( SQLCODE ) {
		return( -1 );
	}

	EXEC SQL DESCRIBE usqlobj2 INTO udesc;
	if ( SQLCODE ) {
		return( -1 );
	}

	pos = compute_size( udesc );
	if (buffer) free(buffer);
	buffer = (char *)malloc( pos );
	if ( buffer == NULL ) {
		return( -1 );
	}

	/* 给每个 sqlda 结构 udesc 赋地址 */
	pos = 0;
	for ( col = udesc->sqlvar, i = 0; i < udesc->sqld; col++, i++ ) {
		pos = rtypalign( pos, col->sqltype );
		col->sqldata = buffer + pos;
		pos += col->sqllen;
		if ( col->sqltype != CDECIMALTYPE ) pos++;
	}

	/* Fetch 每一记录行, 把各类型的数据转换成ASCII格式 */

	EXEC SQL DECLARE usqlcurs2 SCROLL CURSOR FOR usqlobj2 ;
	EXEC SQL OPEN usqlcurs2;
	if ( SQLCODE ) {
		return( -1 );
	}

	if (cur_row > all_rows)
		cur_row = all_rows;
	tmp_row = cur_row;

	EXEC SQL FETCH absolute $tmp_row usqlcurs2 USING DESCRIPTOR udesc;
	if ( SQLCODE != 0 ) {
		EXEC SQL CLOSE usqlcurs2;
		return( -1 );
	}
	use_cursor = 1;

	get_data_from_sqlda(udesc, rowid, &scr);

	re_query = 1;
	que_row = tmp_row;
	sprintf(tmp, "第 %d/%d 条记录", que_row, all_rows);
	h_winprompt(sql_win, 16, 1, tmp, 0, 0);
	h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
	h_prompt(LINES-1, 1, tip, 0, 0);

	disp_fields( sql_win, scr.fields );
	return( 0 );
}


int	sql_next(item_no)
int	item_no;
{
	char tmp[200];

	clear_wline(sql_win, 16);
	if (!do_query) {
		beep();
		h_winprompt(sql_win, 16, 1, "请先查询... ", 0, 0);
		return(-1);
	}

	if (que_row == all_rows) {
		beep();
		h_winprompt(sql_win, 16, 1, "已到最后一条记录... ", 0, 0);
		return(0);
	}

	if (re_query)
		EXEC SQL FETCH NEXT usqlcurs2 USING DESCRIPTOR udesc;
	else
		EXEC SQL FETCH NEXT usqlcurs USING DESCRIPTOR udesc;
	if ( SQLCODE != 0 ) {
		errcall(ERROR, "Fetch Next Error : SQLCODE[%d] SQLERRD[%d]",
			SQLCODE, sqlca.sqlerrd[1]);
		beep();
		h_prompt(LINES-1, 1, "                                                                              ", 0, 0);
		h_prompt(LINES-1, 1, "查询失败,按任意键继续... ", 1, 2);
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		EXEC SQL CLOSE usqlcurs;
		if (re_query)
			EXEC SQL CLOSE usqlcurs2;
		re_query = 0;
		use_cursor = 0;
		do_query = 0;
		return(-1);
	}

	get_data_from_sqlda( udesc, rowid, &scr );

	que_row++;
	sprintf(tmp, "第 %d/%d 条记录", que_row, all_rows);
	h_winprompt(sql_win, 16, 1, tmp, 0, 0);

	disp_fields(sql_win, scr.fields);
	return(0);
}

int	sql_previous(item_no)
int	item_no;
{
	char tmp[200];

	clear_wline( sql_win, 16 );
	if ( !do_query ) {
		beep();
		h_winprompt( sql_win, 16, 1, "请先查询... ", 0, 0 );
		return( -1 );
	}
	if (que_row == 1) {
		beep();
		h_winprompt( sql_win, 16, 1, "已到第一条记录... ", 0, 0 );
		return( 0 );
	}

	if (re_query)
		EXEC SQL FETCH PREVIOUS usqlcurs2 USING DESCRIPTOR udesc;
	else
		EXEC SQL FETCH PREVIOUS usqlcurs USING DESCRIPTOR udesc;
	if ( SQLCODE != 0 ) {
		errcall(ERROR, "Fetch Prev Error : SQLCODE[%d] SQLERRD[%d]",
			SQLCODE, sqlca.sqlerrd[1]);
		beep();
		h_prompt( LINES-1, 1, "                                                                              ", 0, 0);
		h_prompt( LINES-1, 1, "查询失败,按任意键继续... ", 1, 2 );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		EXEC SQL CLOSE usqlcurs;
		if (re_query)
			EXEC SQL CLOSE usqlcurs2;
		re_query = 0;
		use_cursor = 0;
		do_query = 0;
		return( -1 );
	}

	get_data_from_sqlda( udesc, rowid, &scr );

	que_row--;
	sprintf( tmp, "第 %d/%d 条记录", que_row, all_rows );
	h_winprompt( sql_win, 16, 1, tmp, 0, 0 );

	disp_fields( sql_win, scr.fields );
	return( 0 );
}

int	sql_first(item_no)
int	item_no;
{
	char tmp[200];

	clear_wline( sql_win, 16 );
	if ( !do_query ) {
		beep();
		h_winprompt( sql_win, 16, 1, "请先查询... ", 0, 0 );
		return( -1 );
	}

	if (que_row == 1) {
		beep();
		h_winprompt( sql_win, 16, 1, "已到第一条记录... ", 0, 0 );
		return( 0 );
	}

	if (re_query)
		EXEC SQL FETCH FIRST usqlcurs2 USING DESCRIPTOR udesc ;
	else
		EXEC SQL FETCH FIRST usqlcurs USING DESCRIPTOR udesc ;
	if ( SQLCODE ) {
		errcall(ERROR, "Fetch First Error : SQLCODE[%d] SQLERRD[%d]",
			SQLCODE, sqlca.sqlerrd[1]);
		beep();
		h_prompt( LINES-1, 1, "                                                                              ", 0, 0);
		h_prompt( LINES-1, 1, "查询失败,按任意键继续... ", 1, 2 );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		if (re_query)
			EXEC SQL CLOSE usqlcurs2;
		re_query = 0;
		EXEC SQL CLOSE usqlcurs;
		use_cursor = 0;
		do_query = 0;
		return( -1 );
	}

	get_data_from_sqlda( udesc, rowid, &scr );

	que_row = 1;
	sprintf( tmp, "第 %d/%d 条记录", que_row, all_rows );
	h_winprompt( sql_win, 16, 1, tmp, 0, 0 );

	disp_fields( sql_win, scr.fields );
	return( 0 );
}

int	sql_last(item_no)
int	item_no;
{
	char tmp[200];

	clear_wline( sql_win, 16 );
	if ( !do_query ) {
		beep();
		h_winprompt( sql_win, 16, 1, "请先查询... ", 0, 0 );
		return( -1 );
	}

	if (que_row == all_rows) {
		beep();
		h_winprompt(sql_win, 16, 1, "已到最后一条记录... ", 0, 0);
		return(0);
	}

	if (re_query)
		EXEC SQL FETCH LAST usqlcurs2 USING DESCRIPTOR udesc;
	else
		EXEC SQL FETCH LAST usqlcurs USING DESCRIPTOR udesc;
	if ( SQLCODE ) {
		errcall(ERROR, "Fetch Last Error : SQLCODE[%d] SQLERRD[%d]",
			SQLCODE, sqlca.sqlerrd[1]);
		beep();
		h_prompt( LINES-1, 1, "                                                                              ", 0, 0);
		h_prompt( LINES-1, 1, "查询失败,按任意键继续... ", 1, 2 );
		h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
		h_prompt(LINES-1, 1, tip, 0, 0);
		if (re_query)
			EXEC SQL CLOSE usqlcurs2;
		re_query = 0;
		EXEC SQL CLOSE usqlcurs;
		use_cursor = 0;
		do_query = 0;
		return( -1 );
	}

	get_data_from_sqlda( udesc, rowid, &scr );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -