【问题标题】:VFP8: Check if query returned a resultVFP8:检查查询是否返回结果
【发布时间】:2018-06-25 20:38:36
【问题描述】:

我正在导入一堆表,发现其中一些表存在数据错误。这些错误是几年前创建表时引入的。我想创建一个简单的警报来通知我应该手动检查表格。

以下工作,但它会弹出查询结果,这是我不想要的。

procedure checkForBadRecord
  select * ;
  from table_x ;
  where field_x = 'thing used to determine it's bad'

  if _tally > 0 then 
    messagebox("Check the table for errors!")
  endif
endproc 

有没有办法在不显示实际行的情况下检查表中是否有满足条件的行?

我正在使用 Visual FoxPro 8。

【问题讨论】:

    标签: visual-foxpro


    【解决方案1】:

    您可以在 WHERE 子句之后添加“INTO ARRAY dummyCursorName”:

       select * ;
          from table_x ;
          where field_x = 'thing used to determine it's bad' ;
          INTO ARRAY dummyCursorName
    

    _TALLY 仍会报告统计信息,并且无需处理烦人的浏览窗口。

    【讨论】:

      【解决方案2】:

      为了防止显示结果,只需为结果指定一个目标。 “进入数组”或“进入光标”就可以了。

      根据您当前的代码,您对返回的行不感兴趣,因此您可以简单地获取计数(代码中也有错字)。即:

      procedure checkForBadRecord
        local array laBadCount[1]
        select count(*) ;
        from table_x ;
        where field_x = "thing used to determine it's bad" ;
        into array laBadCount
        use in (select('table_x'))
      
        if laBadCount[1] > 0 then 
          messagebox("Check the table for errors!")
        endif
      endproc
      

      您可能不想编写这样的过程,而是希望编写此过程以用于更通用的用途:

        if checkForBadRecord('table_x', 'field_x', "thing used to determine it's bad") 
          messagebox("Check the table table_x for errors!")
        endif
      
      
      
      procedure checkForBadRecord(tcTableName, tcFieldToCheck, tuValueToCheck)
        local array laBadCount[1]
        select count(*) ;
        from &tcTableName ;
        where &tcFieldToCheck = m.tuValueToCheck ;
        into array laBadCount
        use in (select(m.tcTableName))
      
        return laBadCount[1] > 0
      endproc
      

      注意:您也可以使用“To Screen”来抑制结果并通过 _Tally 获取计数。即:

      procedure checkForBadRecord
        set console OFF
        select * ;
        from table_x ;
        where field_x = "thing used to determine it's bad" ;
        to SCREEN
        set console ON
        use in (select('table_x'))
      
        if _Tally > 0 then 
          messagebox("Check the table for errors!")
        endif
      endproc
      

      【讨论】:

        猜你喜欢
        • 2023-04-10
        • 1970-01-01
        • 2023-04-01
        • 2010-09-22
        • 2020-11-13
        • 2011-02-21
        • 2016-07-23
        • 2014-01-18
        相关资源
        最近更新 更多