Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to know a table is empty ? 1

Status
Not open for further replies.

andreateh

Programmer
Jul 19, 2003
83
SG
How do i know that a table is empty ? "Empty" i mean here is no record in tha table or the table contain only deleted record. Does line below work ?

Code:
nRecno = IIF(NOT EOF("table") OR;
         BOF("table"),RECNO("table"),.F.)

IF TYPE("nRecNo") = "L"
     ?" no record"
ElSE
      ?"Contain Record"
endif
 
With SET DELETED ON, you can avoid a count with:

GO TOP
lnTop=RECNO()
GO BOTTOM
lnBot=RECNO()
?iif(lnTop=lnBot and DELETED()=.f. and EOF()=.f.,"I think it IS NOT EMPTY by top/bott compare","I think it is empty by top/bott compare")

Demostrated here:

Code:
clear
CREATE TABLE test (f1 c(1))
?"Table IS empty"
DO testempty

?""

FOR x = 1 TO 3
APPEND BLANK
DELETE
endfor
?"Table Has 3 deleted only"
DO testempty

?""

APPEND BLANK
APPEND BLANK
DELETE
?"Table Has 4 deleted and ONE NOT deleted"
DO testempty

PROCEDURE testempty
lcDeleted=SET("deleted")
SET DELETED ON

?iif(RECCOUNT()=0,"I think it is empty by RECCOUNT()","I think it IS NOT EMPTY by RECCOUNT()")

GO TOP 
lnTop=RECNO()
GO BOTTOM
lnBot=RECNO()
?iif(lnTop=lnBot and DELETED()=.f. and EOF()=.f.,"I think it IS NOT EMPTY by top/bott compare","I think it is empty by top/bott compare")
SET DELETED &lcDeleted
ENDPROC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top