VFP8:检查查询是否返回结果
VFP8: Check if query returned a result
我正在导入一堆 table 并发现其中一些有数据错误。这些错误是在几年前创建 table 时引入的。我想创建一个简单的警报来通知我应该手动检查 table.
下面的工作正常,但是它弹出了我不想要的查询结果。
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
有没有办法在不显示实际行的情况下检查 table 是否有满足条件的行?
我正在使用 Visual FoxPro 8。
您可以在 WHERE 子句后添加 "INTO ARRAY dummyCursorName":
select * ;
from table_x ;
where field_x = 'thing used to determine it's bad' ;
INTO ARRAY dummyCursorName
_TALLY 仍会报告统计信息,无需处理烦人的浏览 window。
要防止显示结果,只需为结果指定一个目标。 "into array" 或 "into cursor" 都可以。
根据您当前的代码,您对返回的行不感兴趣,因此您可以简单地获取计数(代码中也有拼写错误)。即:
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
我正在导入一堆 table 并发现其中一些有数据错误。这些错误是在几年前创建 table 时引入的。我想创建一个简单的警报来通知我应该手动检查 table.
下面的工作正常,但是它弹出了我不想要的查询结果。
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
有没有办法在不显示实际行的情况下检查 table 是否有满足条件的行?
我正在使用 Visual FoxPro 8。
您可以在 WHERE 子句后添加 "INTO ARRAY dummyCursorName":
select * ;
from table_x ;
where field_x = 'thing used to determine it's bad' ;
INTO ARRAY dummyCursorName
_TALLY 仍会报告统计信息,无需处理烦人的浏览 window。
要防止显示结果,只需为结果指定一个目标。 "into array" 或 "into cursor" 都可以。
根据您当前的代码,您对返回的行不感兴趣,因此您可以简单地获取计数(代码中也有拼写错误)。即:
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