?? i_sql.ec
字號:
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 + -