QueryRun的Reset()方法解释

今天写代码的时候遇到一个问题,在一个过程中用户需要多次输入查询条件,这样同一个QueryRun对象qr需要用到多次,但在第一次prompt后,后面的qr.Next()死活都不执行查询,qr的结果也就不会更新了,翻阅QueryRun的帮助文档,想找到个方法用一下,QueryRun所有的方法中reset方法比较接近俺的想像,鼠标点了下去,鼻子差点气歪,这个函数的解释空空如也,服了.不过试了一下,结果正如自己想像的那样,代码如下:
None.gif static   void  qrTest(Args _args)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif        QueryRun qr;
InBlock.gif        Query q;
InBlock.gif        CustTable cust;
InBlock.gif        ;
InBlock.gif        q 
= new Query();
InBlock.gif        q.addDataSource(tableNum(custtable));
InBlock.gif
InBlock.gif        qr 
= new QueryRun(q);
InBlock.gif        
InBlock.gif        
//First prompt
InBlock.gif
        if(qr.prompt())
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif           
while(qr.next())
ExpandedSubBlockStart.gifContractedSubBlock.gif           
dot.gif{
InBlock.gif                cust 
= qr.get(tableNum(custTable));
InBlock.gif                print cust.AccountNum;
ExpandedSubBlockEnd.gif           }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
//Second prompt
InBlock.gif
         qr.reset();
InBlock.gif         
if(qr.prompt())
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif              
while(qr.next())
ExpandedSubBlockStart.gifContractedSubBlock.gif               
dot.gif{
InBlock.gif                    cust 
= qr.get(tableNum(custTable));
InBlock.gif                    print cust.AccountNum;
ExpandedSubBlockEnd.gif               }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        pause;
InBlock.gif
ExpandedBlockEnd.gif}

重点也就在//second prompt后面的那句qr.reset()了.
试着将该函数解释如下:
Reset():
将QueryRun对象qr的查询结果清零,游标(或者称为数据指针)指向初始位置,这样保证在下次运行qr.Next()时,重新执行SQL查询,获取新的数据集,在查询完毕后,游标指向返回结果集的第一条记录.
如果想让一个QueryRun对象执行多次数据库查询,必须让让游标指向初始位置,这样qr在下次执行next()函数的时候才会知道要执行一次新的查询以便更新结果集,否则qr将不再执行新的查询动作.

转载于:https://www.cnblogs.com/Farseer1215/archive/2006/09/20/509546.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值