请问如何在动态语句中使用 load、 unload 功能
现在需要设计一个支持 load、unload 功能的函数,程序将需要处理数据传输到一个 prepare 语句中进行处理,但是程序却连连报错:int sql_run(str)
char *str;
{
strcpy(sqlstring,str);
EXEC SQL PREPARE s_comm FROM :sqlstring;
if (sqlca.sqlcode) {
errcall(ERROR, "%d", sqlca.sqlcode);
return (sqlca.sqlcode);
}
// 程序报201 错误,不知为何该语句无法处理 unload或load 语句
EXEC SQL EXECUTE s_comm;
//程序报410 错误,提示 prepare 句柄没有准备好。
return(sqlca.sqlcode);
}
sprintf(buff,"unload to /tmp/dfmx.txt select*from dfmx");
sql_run(buff);
// 程序不能执行该数据下载
sprintf(buff, "loadfrom/tmp/dfmx.txt insert into dfmx ");
sql_run(buff);
// 程序加载 0 条记录。
请问包含 load 、unload 语句应该如何传递给一个动态 esql/c 语句呢?
谢谢!!!!!
请问如何在动态语句中使用 load、 unload 功能
我在别人的程序中见到了动态语句使用 load 和 unload 的例子,但是我在借鉴这些程序的时候,程序可以编译通过,但是程序就是无法正确执行,请版主关注本问题,谢谢!!!!请问如何在动态语句中使用 load、 unload 功能
ec中SQL语句不支持unload,load吧,除非用system()或类似方法调用。
你所见的例子可以贴出来吗?
请问如何在动态语句中使用 load、 unload 功能
以下就是一个使用 load 功能的程序/*******************************************************
* 数据备份与恢复(backup_proc,rescovery_proc)
*
* 最后修改: 周国祥 2001/08/18
*******************************************************/
#include <stdio.h>;
#include <curses.h>;
#include <varargs.h>;
#include <sys/types.h>;
#include <sys/timeb.h>;
#include <time.h>;
#include "all.h"
#include "macro_def.h"
#include "tool.h"
$include "db_struct.h";
$include sqlca;
#define WD getenv ( "WORKDIR" )
#defineCOL_LEE 2
void error_handler ();
void warning_handler ();
void notfound_handler ();
/*
extern WINDOW *my_win;
*/
WINDOW *my_win;
EXEC SQL WHENEVER SQLERROR CALL error_handler;
EXEC SQL WHENEVER SQLWARNING CALL warning_handler;
EXEC SQL WHENEVER NOT FOUND CALL notfound_handler;
char backup_table = {
"cur_tran_ls",
"his_tran_ls",
"err_tran_ls",
"cur_settle_ls",
"his_settle_ls",
"saf_ls",
"cur_hand_ls",
"his_hand_ls",
"",
NULL,
};
int backup_ls ()
{
char buff;
int ret;
int i = 0;
while (backup_table != NULL && backup_table != '\0') {
#ifdef Wubin_mod_20020509
sprintf ( buff ,\
"dbaccess - - 2>;/dev/null 1>;/dev/null <<!\ndatabase %s;\nunload to \"%s/backup/%s\" select * from %s;\n!", getenv("DBNAME"), getenv("WORKDIR"), backup_table, backup_table );
ret = system ( buff );
if ( ret ) {
errcall ( ERROR , "Unable unload %s!", backup_table);
return -1;
}
#else
sprintf ( buff ,\
"unload to %s/backup/%s select * from %s ", getenv("WORKDIR"), backup_table, backup_table );
ret = sql_run(buff);
if (ret < 0) {
errcall ( ERROR , "Unable unload %s! failed![%d]", backup_table, ret);
return -1;
}
#endif
}
return 0;
}
int recovery_ls ()
{
char buff;
int ret;
int i = 0;
while (backup_table != NULL && backup_table != '\0') {
#ifdef Wubin_mod_20020509
sprintf ( buff ,\
"dbaccess - - 2>;/dev/null 1>;/dev/null <<!\ndatabase %s;\nload from \"%s/backup/%s\" insert into %s;\n!", getenv("DBNAME"), getenv("WORKDIR"), backup_table, backup_table);
ret=system ( buff );
if ( ret ) {
errcall ( ERROR , "Unable load %s!", backup_table );
return -1;
}
#else
sprintf ( buff ,\
"load from %s/backup/%s insert into %s ", getenv("WORKDIR"), backup_table, backup_table);
ret = sql_run(buff);
if (ret < 0) {
errcall ( ERROR , "Unable load %s! failed![%d]", backup_table, ret );
return -1;
}
#endif
}
return 0;
}
int backup_proc ()
{
char filename, tmp;
int ch, line, ret;
char cmd, fileout, backup_date;
tmp = backup_date = 0;
ch = ret = 0;
sprintf(filename, "/tmp/.backup_proc.%d", getpid());
scr_dump(filename);
DispBelow("数据备份处理");
clear_wline(stdscr, LINES-1);
my_win = newwin(19, 80, 3, 0);
mvwprintw(my_win, 0, 0, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
wrefresh(my_win);
line = COL_LEE;
if ( yorn(my_win, line++, " 是否进行数据备份处理?", "1.是", "0.否", 1, 0)) {
goto end;
}
strcpy(fileout, " 磁带 ");
ch = strlen(fileout) + 1;
strcpy(fileout + ch, " 硬盘 ");
ch += strlen(fileout + ch) + 1;
strcpy(fileout + ch, " 取消 ");
ch = multi_select(my_win, 1, " 请选择备份存储设备:", fileout, 3, 1, 0, 0);
if (ch == 2) {
goto end;
}
if (ch == 1) {
getdatef(backup_date,"");
mvwprintw(my_win, 2, 4, "请输入备份日期(YYYYMMDD): [%s]", backup_date);
if (in_item(my_win, "", 2, 31, backup_date, 8, NULL, NULL, 0, 0) != ENTER) {
goto end;
}
mvwprintw(my_win, 2, 4, " ");
strcpy(fileout, " 交易流水 ");
ch = strlen(fileout) + 1;
strcpy(fileout + ch, " 所有路由 ");
ch += strlen(fileout + ch) + 1;
strcpy(fileout + ch, " 基本资料 ");
ch += strlen(fileout + ch) + 1;
strcpy(fileout + ch, " 取消 ");
ch = multi_select(my_win, 1, " 请选择需要备份的数据:", fileout, 4, 3, 0, 0);
switch (ch) {
case 0:
strcpy(tmp, "TRAN_LS");
break;
case 1:
strcpy(tmp, "ROUTE");
break;
case 2:
strcpy(tmp, "INFOMATION");
break;
case 3:
goto end;
break;
default:
goto end;
break;
}
/* daylog(DEBUG, "正在生成备份数据, 备份日期: %s, 请稍候 ...", backup_date); */
mvwprintw(my_win, 4, 4, "正在生成备份数据, 请稍候 ...");
wrefresh(my_win);
ret = backup_db(tmp, backup_date);
if (ret == 0) {
sprintf ( cmd , "备份数据成功, 按任一键继续... [%s/backup/%s]", getenv("WORKDIR"), backup_date);
/* sprintf ( cmd , "备份数据成功, 按任一键继续..."); */
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
goto end;
} else {
errcall ( ERROR , "Unable backup ls !\n" );
sprintf ( cmd , "备份数据失败, 按任一键继续... [%s/backup/%s]", getenv("WORKDIR"), backup_date);
sprintf ( cmd , "备份数据失败, 按任一键继续...");
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
delwin(my_win);
scr_restore(filename);
unlink(filename);
return -1;
}
}
sprintf ( cmd , "rm -f %s/backup/*" , WD );
system ( cmd );
if ( backup_ls () < 0 ) {
errcall ( ERROR , "Unable backup ls !\n" );
sprintf ( cmd , "备份数据失败, 按任一键继续...");
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
delwin(my_win);
scr_restore(filename);
unlink(filename);
return -1;
}
if ( yorn(my_win, line++,
" 是否将数据倒入磁带?", "1.是", "0.否", 1, 0)) {
delwin(my_win);
scr_restore(filename);
unlink(filename);
return(0);
}
sprintf(cmd,
"tar cv8 2>;/dev/null 1>;/dev/null %s/etc %s/install %s/backup %s/box",
WD , WD , WD , WD );
if ( system ( cmd ) != 0 ) {
wrefresh( my_win );
sprintf ( cmd , "备份数据失败, 按任一键继续...");
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
} else {
sprintf ( cmd , "备份数据成功, 按任一键继续...");
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
}
end:
delwin(my_win);
scr_restore(filename);
unlink(filename);
return 0;
}
int recovery_proc ()
{
char filename, tmp, backup_date;
int ch, line, ret;
char cmd, fileout;
ret = 0; tmp = backup_date = 0;
ch = ret = 0;
sprintf(filename, "/tmp/.recovery_proc.%d", getpid());
scr_dump(filename);
DispBelow("数据恢复处理");
clear_wline(stdscr, LINES-1);
my_win = newwin(19, 80, 3, 0);
mvwprintw(my_win, 0, 0, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
wrefresh(my_win);
line = COL_LEE;
if (yorn(my_win, line++, " 注意: 如果恢复数据将覆盖当前数据库中的数据, 是否进行数据恢复?", "1.是", "0.否", 1, 0)) {
goto end;
}
strcpy(fileout, " 磁带 ");
ch = strlen(fileout) + 1;
strcpy(fileout + ch, " 硬盘 ");
ch += strlen(fileout + ch) + 1;
strcpy(fileout + ch, " 取消 ");
ch = multi_select(my_win, 1, " 请选择存储恢复数据的设备:", fileout, 3, 2, 0, 0);
if (ch == 2) {
goto end;
}
if (ch == 1) {
strcpy(backup_date," ");
mvwprintw(my_win, 2, 4, "请输入恢复数据日期(YYYYMMDD): [%s]", backup_date);
if (in_item(my_win, "", 2, 35, backup_date, 8, NULL, NULL, 0, 0) != ENTER) {
goto end;
}
sprintf(tmp, "cd %s/backup/%s >;/dev/null 2>;&1", getenv("WORKDIR"), backup_date);
ret = system(tmp);
if ( ret ) {
errcall ( ERROR , "Not found %s/backup/%s", getenv("WORKDIR"), backup_date);
sprintf ( cmd , "需要恢复的数据[%s/backup/%s]不存在", getenv("WORKDIR"), backup_date);
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
delwin(my_win);
scr_restore(filename);
unlink(filename);
return -1;
}
mvwprintw(my_win, 2, 4, " ");
strcpy(fileout, " 交易流水 ");
ch = strlen(fileout) + 1;
strcpy(fileout + ch, " 所有路由 ");
ch += strlen(fileout + ch) + 1;
strcpy(fileout + ch, " 基本资料 ");
ch += strlen(fileout + ch) + 1;
strcpy(fileout + ch, " 取消 ");
ch = multi_select(my_win, 1, " 请选择需要恢复的数据:", fileout, 4, 3, 0, 0);
if (ch == 3)
goto end;
if (yorn(my_win, line++, " 注意: 数据恢复将覆盖当前数据库中的数据, 是否进行数据恢复?", "1.是", "0.否", 1, 0)) {
goto end;
}
switch (ch) {
case 0:
strcpy(tmp, "TRAN_LS");
break;
case 1:
strcpy(tmp, "ROUTE");
break;
case 2:
strcpy(tmp, "INFOMATION");
break;
case 3:
goto end;
break;
default:
goto end;
break;
}
mvwprintw(my_win, 4, 4, "正在向数据库中恢复数据, 请稍候 ...");
wrefresh(my_win);
ret = recovery_db(tmp, backup_date);
if (ret == 0) {
sprintf ( cmd , "恢复数据成功, 按任一键继续...");
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
goto end;
} else {
errcall ( ERROR , "Unable recovery ls !\n" );
sprintf ( cmd , "恢复数据失败, 按任一键继续...");
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
delwin(my_win);
scr_restore(filename);
unlink(filename);
return -1;
}
}
if (yorn(my_win, line++, " 是否从磁带装入数据?", "1.是", "0.否", 1, 0))
goto end;
else {
sprintf ( cmd , "rm -f %s/backup/* >;/dev/null 2>;&1" , WD );
system ( cmd );
sprintf ( cmd , "tar xv8 >;/dev/null 2>;&1" );
ret = system ( cmd );
if ( ret ) {
errcall ( ERROR , "Execute error!(%s) ", cmd);
sprintf ( cmd , "读写磁带设备失败, 请确认磁带设备是否正常 按任一键继续...");
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
delwin(my_win);
scr_restore(filename);
unlink(filename);
return -1;
}
}
if ( recovery_ls () < 0 ) {
errcall ( ERROR , "Unable recovery ls !\n" );
sprintf ( cmd , "恢复数据失败, 按任一键继续...");
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
delwin(my_win);
scr_restore(filename);
unlink(filename);
return -1;
}
sprintf ( cmd , "恢复数据成功, 按任一键继续...");
mvwaddstr ( my_win , 17 , 4 , cmd );
wgetch ( my_win );
end:
delwin(my_win);
scr_restore(filename);
unlink(filename);
return 0;
}
/*================== WuBin 2001-9-8 15:33 ======Start==============
根据库表名备份数据到相应日期的目录
===========================2001-9-8 15:33=======End==============*/
int backup_db (char *table_name, char *backup_date)
{
$char buff, tmp;
int ret, i;
struct table_arry_st table_arry; /* 目标数组名 */
memset(table_arry, '\0', sizeof(table_arry));
i = ret = 0;
sprintf(buff, "mkdir %s/backup/%s >;/dev/null 2>;&1", getenv("WORKDIR"), backup_date);
system(buff);
sprintf(tmp, "%s/etc/backup_table", getenv("WORKDIR"));
ret = readtab2arry(tmp, table_name, table_arry);
if ( ret ) {
errcall ( ERROR , "Read %s Error! ", tmp);
return -1;
}
while (table_arry.table_name != 0 ) {
sprintf(buff, "rm -f %s/backup/%s/%s >;/dev/null 2>;&1", getenv("WORKDIR"), backup_date, table_arry.table_name);
system(buff);
i++;
}
i = 0;
while (table_arry.table_name != 0) {
memset(buff, 0, sizeof(buff));
#ifdef Wubin_mod_20020509
sprintf ( buff , "dbaccess - - 2>;/dev/null 1>;/dev/null <<!\ndatabase %s;\nunload to \"%s/backup/%s/%s\" select * from %s;\n!", getenv("DBNAME"), getenv("WORKDIR"), backup_date, table_arry.table_name, table_arry.table_name );
ret = system ( buff );
if ( ret ) {
errcall ( ERROR , "Unable unload %s! ", table_arry.table_name, ret);
return -1;
}
#else
sprintf ( buff , "unload to %s/backup/%s/%s select * from %s ", getenv("WORKDIR"), backup_date, table_arry.table_name, table_arry.table_name );
ret = sql_run(buff);
if (ret < 0) {
errcall(ERROR, "Unable unload %s! failed![%d]", table_arry.table_name, ret);
return -1;
}
#endif
i++;
}
return 0;
}
/*================== WuBin 2001-9-8 15:33 ======Start==============
根据库表名恢复数据从相应日期的目录
===========================2001-9-8 15:33=======End==============*/
int recovery_db (char *table_name, char *backup_date)
{
char buff, tmp;
int ret, i;
struct table_arry_st rc_table_arry; /* 目标数组名 */
memset(rc_table_arry, '\0', sizeof(rc_table_arry));
i = ret = 0;
sprintf(buff, "cd %s/backup/%s >;/dev/null 2>;&1", getenv("WORKDIR"), backup_date);
ret = system(buff);
if ( ret ) {
errcall ( ERROR , "Not found %s", buff);
return -1;
}
sprintf(tmp, "%s/etc/backup_table", getenv("WORKDIR"));
ret = readtab2arry(tmp, table_name, rc_table_arry);
if ( ret ) {
errcall ( ERROR , "Read %s Error!", tmp);
return -1;
}
while (rc_table_arry.table_name != 0 ) {
sprintf(buff, "ls %s/backup/%s/%s >;/dev/null 2>;&1", getenv("WORKDIR"), backup_date, rc_table_arry.table_name);
ret = system(buff);
if ( ret ) {
errcall ( ERROR , "Read %s Error!", rc_table_arry.table_name);
return -1;
}
i++;
}
i = 0;
while (rc_table_arry.table_name != 0) {
#ifdef Wubin_mod_20020509
sprintf ( buff , "dbaccess - - 2>;/dev/null 1>;/dev/null <<!\ndatabase %s;\ndelete from %s;\n!", getenv("DBNAME"), rc_table_arry.table_name );
ret = system ( buff );
if ( ret ) {
errcall ( ERROR , "Unable delete %s !", rc_table_arry.table_name, ret);
return -1;
}
#else
sprintf ( buff , "delete from %s;\n!", rc_table_arry.table_name );
ret = sql_run(buff);
if (ret < 0) {
errcall ( ERROR , "Unable delete %s failed![%d]", rc_table_arry.table_name, ret);
return -1;
}
#endif
#ifdef Wubin_mod_20020509
sprintf ( buff , "dbaccess - - 2>;/dev/null 1>;/dev/null <<!\ndatabase %s;\nload from \"%s/backup/%s/%s\" insert into %s;\n!", getenv("DBNAME"), getenv("WORKDIR"), backup_date, rc_table_arry.table_name, rc_table_arry.table_name );
ret = system ( buff );
if ( ret ) {
errcall ( ERROR , "Unable load %s !", rc_table_arry.table_name, ret);
return -1;
}
#else
sprintf ( buff , "dload from %s/backup/%s/%s insert into %s ", getenv("WORKDIR"), backup_date, rc_table_arry.table_name, rc_table_arry.table_name );
ret = sql_run(buff);
if (ret < 0) {
errcall ( ERROR , "Unable load %s failed![%d]", rc_table_arry.table_name, ret);
return -1;
}
#endif
i++;
}
return 0;
}
以下是 sql_run 功能的实现
/**************************************************************
* 功能: 数据库处理公共函数 public.ec
* 最后修改日期:
*
* 周国祥 2002/04/09 从dbprg/public.ec中分离过来
**************************************************************/
#include <stdio.h>;
#include <curses.h>;
#include "mytools.h"
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 sqlstring;
$include "db_struct.h";
int sql_run(str)
char *str;
{
strcpy(sqlstring,str);
EXEC SQL PREPARE s_comm FROM :sqlstring;
if (sqlca.sqlcode) {
errcall(ERROR, "%d", sqlca.sqlcode);
return (sqlca.sqlcode);
}
EXEC SQL EXECUTE s_comm;
return(sqlca.sqlcode);
}
int query_count(str)
char *str;
{
$int counts;
$short indi;
strcpy(sqlstring,str);
EXEC SQL PREPARE q_comm_1 FROM :sqlstring;
if (sqlca.sqlcode) {
errcall(ERROR, "PREPARE [%s] failed (%d)",
sqlstring, sqlca.sqlcode);
return -1;
}
EXEC SQL DECLARE query_cur CURSOR FOR q_comm_1;
if (sqlca.sqlcode) {
errcall(ERROR, "DECLARE [%s] failed (%d)",
sqlstring, sqlca.sqlcode);
return -1;
}
EXEC SQL OPEN query_cur;
if (sqlca.sqlcode) {
errcall(ERROR, "OPEN [%s] failed (%d)",
sqlstring, sqlca.sqlcode);
return -1;
}
EXEC SQL FETCH query_cur INTO :counts:indi;
if (sqlca.sqlcode && sqlca.sqlcode == 100) {
errcall(ERROR, "FETCH failed (%d)",
sqlca.sqlcode);
return -1;
}
if ((indi == -1) || sqlca.sqlcode) counts = 0;
EXEC SQL CLOSE query_cur;
return(counts);
}
long calc_long(str)
char *str;
{
$long total;
$short indi;
strcpy(sqlstring,str);
EXEC SQL PREPARE q_comm_2 FROM :sqlstring;
EXEC SQL DECLARE calcl_cur CURSOR FOR q_comm_2;
EXEC SQL OPEN calcl_cur;
EXEC SQL FETCH calcl_cur INTO :total:indi;
if ((indi == -1) || sqlca.sqlcode) total = 0;
EXEC SQL CLOSE calcl_cur;
return(total);
}
double calc_double(str)
char *str;
{
$double total;
$short indi;
strcpy(sqlstring,str);
EXEC SQL PREPARE q_comm_3 FROM :sqlstring;
EXEC SQL DECLARE calcd_cur CURSOR FOR q_comm_3;
EXEC SQL OPEN calcd_cur;
EXEC SQL FETCH calcd_cur INTO :total:indi;
if ((indi == -1) || sqlca.sqlcode) total = 0;
EXEC SQL CLOSE calcd_cur;
return(total);
}
int get_title(char *title_name)
{
$char center_name;
$short indi;
$char bankid, hostid;
title_name = 0;
EXEC SQL SELECT bank_id, host_id
INTO :bankid, :hostid
FROM sys_param;
if (sqlca.sqlcode)
return(sqlca.sqlcode);
DelSpace(bankid);
DelSpace(hostid);
EXEC SQL SELECT bank_name
INTO :center_name
FROM bank_info
WHERE bank_id = :bankid and host_id = :hostid;
if (!sqlca.sqlcode)
strcpy(title_name, center_name);
return(sqlca.sqlcode);
}
/*
* 获取bankid之IP地址
*/
int get_ipaddr( id_in, hid_in, ip_in )
char id_in, hid_in, ip_in;
{
$char id, ip;
int len;
memcpy(id, id_in, 12);
memcpy(ip, ip_in, 21);
EXEC SQL DECLARE addr_cur CURSOR FOR
SELECT tran_ip_addr1
FROM bank_base
WHERE bank_id = :id;
EXEC SQL OPEN addr_cur;
EXEC SQL FETCH addr_cur INTO :ip;
if (sqlca.sqlcode)
return(sqlca.sqlcode);
DelSpace(ip);
strcpy(ip_in, ip);
return (0);
}
int get_master(card, t)
char *card;
$parameter S_card_acct *t;
{
$char m_card_no;
sprintf(m_card_no,"%12.12s?00?",card);
/*================== WuBin 2001-4-9 21:02 ======Start==============
EXEC SQL SELECT T41_card_no, T41_c_amt, T41_auth_cnt, T41_auth_amt,
T41_auth_total, T41_balance, T41_deposit_cnt,
T41_deposit_amt
INTO :t->;T41_master_card_no, :t->;T41_c_amt, :t->;T41_auth_cnt,
:t->;T41_auth_amt, :t->;T41_auth_total, :t->;T41_balance,
:t->;T41_deposit_cnt, :t->;T41_deposit_amt
FROM card_acct
WHERE T41_card_no MATCHES :m_card_no;
===========================2001-4-9 21:02=======End==============*/
EXEC SQL SELECT card_no, card_amt, auth_cnt, auth_amt,
auth_total, balance, deposit_cnt,
deposit_amt
INTO :t->;card_no, :t->;card_amt, :t->;auth_cnt,
:t->;auth_amt, :t->;auth_total, :t->;balance,
:t->;deposit_cnt, :t->;deposit_amt
FROM card_acct
WHERE card_no MATCHES :m_card_no;
return(sqlca.sqlcode);
}
int get_master_cardno(char *card, char *master)
{
$char card_no,master_cardno,acc;
strcpy(card_no,card);
memcpy(acc,card_no,12);
acc='\0';
/*================== WuBin 2001-4-9 21:14 ======Start==============
EXEC SQL SELECT MAX(T41_card_no) INTO :master_cardno
FROM card_t
WHERE T41_card_no =:acc AND
T41_card_no="00";
===========================2001-4-9 21:14=======End==============*/
EXEC SQL SELECT MAX(card_no) INTO :master_cardno
FROM card_acct
WHERE card_no =:acc AND
card_no="00";
memcpy(master,master_cardno,19);
if(SQLCODE)errcall(ERROR,"get_master_cardno error! [%d]",SQLCODE);
return(sqlca.sqlcode);
}
/* 获取主卡帐户状态 */
int get_master_accstat(char *card, char *stat)
{
$char a_stat,master;
char card_no;
int ret;
strcpy(card_no,card);
ret=get_master_cardno(card_no,master);
if(ret) return(ret);
/*================== WuBin 2001-4-9 21:16 ======Start==============
EXEC SQL SELECT T41_a_stat INTO :a_stat
FROM card_acct
WHERE T41_card_no = :master;
===========================2001-4-9 21:16=======End==============*/
EXEC SQL SELECT master_stat INTO :a_stat
FROM card_acct
WHERE card_no = :master;
memcpy(stat,a_stat,1);
if(SQLCODE<0)errcall(ERROR,"get_master_accstat error! [%d]",SQLCODE);
return(sqlca.sqlcode);
}
int get_master_accno(char *card, char *no)
{
$char acc_no,master;
char card_no;
int ret;
strcpy(card_no,card);
ret=get_master_cardno(card_no,master);
if(ret) return(ret);
/*================== WuBin 2001-4-9 21:17 ======Start==============
EXEC SQL SELECT T41_acc_no INTO :acc_no
FROM card_acct
WHERE T41_card_no = :master;
===========================2001-4-9 21:17=======End==============*/
EXEC SQL SELECT acct_no INTO :acc_no
FROM card_acct
WHERE card_no = :master;
memcpy(no,acc_no,12); /* 帐户号现只用12位 */
if(SQLCODE)errcall(ERROR,"get_master_accno error! [%d]",SQLCODE);
return(sqlca.sqlcode);
}
/*
* 根据商户号获取签约行行号及主机号
*/
int get_sign_bank(merchantid, bankid, hostid)
char *merchantid, *bankid, *hostid;
{
$char merchant_id, bank_id, host_id;
strcpy(merchant_id, merchantid);
DelSpace(merchant_id);
$select sign_bank_id, sign_host_id
into $bank_id, $host_id
from merchant_base
where merchant_id = $merchant_id;
if (SQLCODE) {
errcall(ERROR, "get_sign_bank(%s) select eerror(%d)!", merchant_id, SQLCODE);
bankid = '\0';
hostid = '\0';
return(-1);
}
DelSpace(bank_id);
DelSpace(host_id);
strcpy(bankid, bank_id);
strcpy(hostid, host_id);
return(0);
}
/*
* 根据货币代码获取货币的中文名称 ADD Wubin
*/
int get_ccy_name(char *id, char *name)
{
$char ccy_id, cn_name;
cn_name = 0;
strcpy(ccy_id, id);
EXEC SQL SELECT ccy_name INTO :cn_name FROM ccy_type WHERE ccy_type = :ccy_id;
if (sqlca.sqlcode == 0) {
rm_tail_space(cn_name);
strcpy(name, cn_name);
}
return(sqlca.sqlcode);
}
$ifdef wyz020509_mod;
$else;
/*
int creat_prt_dir(bankid)
char bankid;
{
$char sqlstr;
$char tmp_bankid;
char filename;
sprintf(sqlstr, "SELECT bank_id from bank_info \
where adm_bank_id = \'%s\' \
or bank_id = \'%s\'",
bankid, bankid);
EXEC SQL PREPARE sel_bank_id FROM :sqlstr;
if( SQLCODE<0 ) {
errcall(ERROR, "PREPARE FAILED[%ld][%s]", SQLCODE, sqlstr);
return -1;
}
EXEC SQL DECLARE cur_sel_bank CURSOR WITH HOLD FOR sel_bank_id;
if( SQLCODE<0 ) {
errcall(ERROR, "DECLARE FAILED[%ld][%s]", SQLCODE, sqlstr);
return -1;
}
EXEC SQL OPEN cur_sel_bank;
if( SQLCODE<0 ) {
errcall(ERROR, "OPEN FAILED[%ld]", SQLCODE);
return -1;
}
while(1) {
EXEC SQL FETCH cur_sel_bank INTO :tmp_bankid;
if (SQLCODE < 0) {
errcall(ERROR, "FETCH FAILED(%d)", SQLCODE);
return -1;
}
else if (SQLCODE == 100)
break;
DelSpace(tmp_bankid);
sprintf(filename, "prt/%s", tmp_bankid);
if (create_tmp_file(filename) < 0) {
errcall(ERROR, "create_tmp_file(%s) failed", filename);
}
}
return 0;
}
*/
$endif;
上面的程序原理我也清楚,这些程序就是在我的 informix online 5.0 环境下没法执行。
请问如何在动态语句中使用 load、 unload 功能
这和你说的是两码事。这是用shell实现load/unload,你是EC中是不可能用prepare实现的。
请问如何在动态语句中使用 load、 unload 功能
#ifdef Wubin_mod_20020509
sprintf ( buff ,\
"dbaccess - - 2>;/dev/null 1>;/dev/null <<!\ndatabase %s;\nload from \"%s/backup/%s\" insert into %s;\n!", getenv("DBNAME"), getenv("WORKDIR"), backup_table, backup_table);
ret=system ( buff );
if ( ret ) {
errcall ( ERROR , "Unable load %s!", backup_table );
return -1;
}
#else
sprintf ( buff ,\
"load from %s/backup/%s insert into %s ", getenv("WORKDIR"), backup_table, backup_table);
ret = sql_run(buff);
if (ret < 0) {
errcall ( ERROR , "Unable load %s! failed![%d]", backup_table, ret );
return -1;
}
#endif
实际上我说的是上面的第二种条件编译的情况,你看在源程序中使用的 load from ..... 程序,然后它调用了 sql_run 进行装配执行,为何这样的程序在我的运行环境中就无法执行了??
请问如何在动态语句中使用 load、 unload 功能
哥们,你看看程序里明明在使用unload或者是unload的时候用的是system(buff) 呀?只用在用insert或delete的时候才用sql_run(buff) 的所以在ec里是不支持load和unload的:(请问如何在动态语句中使用 load、 unload 功能
sprintf ( buff ,\"load from %s/backup/%s insert into %s ", getenv("WORKDIR"), backup_table, backup_table);
ret = sql_run(buff);
你看清楚,我说的是以上语句的执行,这是一个 load 语句,程序就是在调用 sql_run 在执行吗!!!
请问如何在动态语句中使用 load、 unload 功能
TO: ljmmail.我只能对你说三个字:
I 服了U. TO: ljmmail.{:3_205:}
咱能不.....
页:
[1]