for循环取数据的时候,有时候会出现数据库“假死”的现象。请问有哪位大神能指点一下????

poppinH 2012-11-15 09:01:09
在用“4GL”语言开发。其实只是一个很简单的明细生成汇总表.一个月也就只有2万条数据而已.取出两万条数据,然后根据不同的汇总条件生成一张月末汇总表.但是在foreache循环中.经常会出现读数据读不出来.然后整个页面就卡死在那里,后台也没看到有表被锁住.重新再打开界面依然能继续重新运行. 间歇性还提示:database not selected yet之类的。
代码如下:整体过程
PREPARE p101_prepare FROM g_sql
IF STATUS THEN CALL cl_err('p101_pre',STATUS,1) EXIT PROGRAM END IF
DECLARE p101_cs CURSOR WITH HOLD FOR p101_prepare #SCROLL
LET g_log = 'N'
IF g_log = 'Y' THEN BEGIN WORK END IF
CALL p101_get_total() #计算数据总量
LET g_now = 1
FOREACH p101_cs INTO g_slf.*
IF STATUS THEN
CALL cl_err('p101(ckp#1):',SQLCA.sqlcode,1) LET g_success = 'N'
EXIT FOREACH
END IF
INITIALIZE g_kpg.* TO NULL
CALL p101_set_imd()
IF g_success='Y' THEN CALL p101_chk_01() END IF #检查
IF g_exist='N' THEN
IF g_success='Y' THEN CALL p101_ini_01() END IF
IF g_success='Y' THEN CALL p101_calc() END IF
IF g_success='Y' THEN CALL p101_ins() END IF
ELSE
IF g_success='Y' THEN CALL p101_calc2() END IF
IF g_success='Y' THEN CALL p101_upd() END IF
END IF
LET g_msg='TOTAL:',g_total,'-','NOW:',g_now,'-',g_slf.slf01,'-',g_slf.slf903
Message g_msg
LET g_now = g_now + 1
IF g_success = 'N' THEN EXIT FOREACH END IF
#Message "FOREACH", g_msg
END FOREACH
CLOSE p101_cs


检查过程:
FUNCTION p101_chk_01()
DEFINE l_azf01 LIKE azf_file.azf01
DEFINE l_cnt SMALLINT
DEFINE l_sql char(400)
LET g_exist='N'
LET g_rowid=NULL
DISPLAY g_slf.slf01,tm.yy,tm.mm,g_slf.slf903,g_slf.imd05,g_slf.slf902
LET l_sql="SELECT count(kpg01) FROM kpg_file",
" WHERE kpg02='",g_slf.slf01 CLIPPED,"' AND kpg04=",tm.yy,
" AND kpg05=",tm.mm," AND kpg15='",g_slf.slf903 CLIPPED,
"' AND kpg16='",g_slf.imd05 CLIPPED,"' AND kpg17='",g_slf.slf902 CLIPPED,"'"
DISPLAY l_sql
PREPARE p101_prepare_cnt FROM l_sql
DECLARE p101_pro_cnt_cs CURSOR FOR p101_prepare_cnt
OPEN p101_pro_cnt_cs
FETCH p101_pro_cnt_cs INTO l_cnt
CLOSE p101_pro_cnt_cs

IF cl_null(l_cnt) THEN LET l_cnt=0 END IF
IF l_cnt=0 THEN LET g_exist='N' RETURN END IF
IF l_cnt<>1 THEN
LET g_msg='p101_chk_01:',g_slf.slf01,'-',g_slf.slf903 USING '<<<<',
'-',g_plant CLIPPED,"(",l_cnt USING '<<<<',")"
CALL cl_err(g_msg,SQLCA.SQLCODE,1)
LET g_success='N'
RETURN
END IF
SELECT rowid,* INTO g_rowid,g_kpg.* FROM kpg_file
WHERE kpg02=g_slf.slf01 AND kpg04=tm.yy AND kpg05=tm.mm
AND kpg15=g_slf.slf903 AND kpg16=g_slf.imd05 AND kpg17=g_slf.slf902
IF STATUS THEN
LET g_msg='p101_chk_01:',g_slf.slf01,'-',g_slf.slf903 USING '<<<<',
'-',g_plant CLIPPED,"(",l_cnt USING '<<<<',")"
CALL cl_err(g_msg,SQLCA.SQLCODE,1)
LET g_success='N'
RETURN
END IF
LET g_exist='Y'
END FUNCTION

...全文
229 点赞 收藏 回复
写回复
回复

还没有回复,快来抢沙发~

发动态
发帖子
Informix
创建于2007-09-28

1054

社区成员

2867

社区内容

其他数据库开发 Informix
社区公告
暂无公告