Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, Is there any function to check if a DBF file has no records? Thanks
Post Follow-up to this messageNevermind, I did it like this: use .... if bof()==eof() ... return endif It's working (at least for now) "Pablo García" <pgarcia@chasque.net> escribió en el mensaje news:1148u2oaqlpv536@news.supernews.com... > Hi, > > Is there any function to check if a DBF file has no records? > > Thanks >
Post Follow-up to this messagePablo, If you are using DbServer classes, DbServer:RecCount If you are using workareas and functional form of database manipulation Alias->( RecCount() ). HTH, -- Johan Nel Pretoria, South Africa. "Pablo García" <pgarcia@chasque.net> wrote in message news:1148u2oaqlpv536@news.supernews.com... > Hi, > > Is there any function to check if a DBF file has no records? > > Thanks > >
Post Follow-up to this message"Pablo García" <pgarcia@chasque.net> wrote in message news:1148uuqftks0422@news.supernews.com... [...] [...] > Nevermind, I did it like this: > > use .... > if bof()==eof() > .... > return > endif > > It's working (at least for now) It's only working because you have most likely only tested against an empty database. If you're anywhere other than bof or eof in a database with one or more records, both will return False, yet still be equal and your code will incorrectly indicate an empty database. A database is empty if the record count is zero - don't try to be clever about it, just use lastrec(). -- Ray Marron
Post Follow-up to this messageThanks, you were right. Finally I used: If reccount()==0 .. return endif "Ray Marron" <me@privacy.net> escribió en el mensaje news:3ajfciF6c1geqU1@individual.net... > "Pablo García" <pgarcia@chasque.net> wrote in message > news:1148uuqftks0422@news.supernews.com... > [...] > [...] > > It's only working because you have most likely only tested against an > empty > database. If you're anywhere other than bof or eof in a database with one > or more records, both will return False, yet still be equal and your code > will incorrectly indicate an empty database. A database is empty if the > record count is zero - don't try to be clever about it, just use > lastrec(). > > -- > Ray Marron > >
Post Follow-up to this messageWhat about lastrec()? According to something I read, lastrec() supercedes reccount()... -- Rob Grattan R&D Software Pty. Ltd.
Post Follow-up to this messageOn Fri, 25 Mar 2005 21:07:54 -0300, "Pablo García" <pgarcia@chasque.net> wrote: >Thanks, you were right. > >Finally I used: > >If reccount()==0 > ... > return >endif > ... and what happened if the dbf does have some records but all deleted? -- Bambang P http://bpranoto.tripod.com
Post Follow-up to this messageIn article <4h3a41ds5gspau9gmdmaihbdd3d0phq6kq@4ax.com> bpranoto_nospam@hotpop.com "Bambang P" writes: > On Fri, 25 Mar 2005 21:07:54 -0300, "Pablo García" > <pgarcia@chasque.net> wrote: > > > ... and what happened if the dbf does have some records but all > deleted? Hi Bambang, It rather depends on whether one wants to account for them, such records can after all be undeleted. I can't think of a quick way of checking for the condition you say, but something like this should work (apologies for the S87 syntax): FUNCTION is_emptyDBF PARAMETER dbfname PRIVATE savearea, numrecs, numdel savearea = SELECT() SELECT 0 USE (dbfname) EXCLUSIVE numrecs = LASTREC() numdel = 0 IF numrecs > 0 *-- this is likely to be S-L-O-W --* COUNT TO numdel FOR deleted() ENDIF CLOSE SELECT (savearea) RETURN (numrecs - numdel == 0) Even that is incomplete as it doesn't take into account any conditional index; I think the OP will have to write the function themself, perhaps using the workarea/alias as a parameter... Pete -- "We have not inherited the earth from our ancestors, we have borrowed it from our descendants."
Post Follow-up to this messageSlowly knock the file with your finger tips. If it sounds hollow, then it's empty. Andi PS: Sorry.. I just quoted someone's answer years ago ;-) << "Pablo García" <pgarcia@chasque.net> wrote: Hi, Is there any function to check if a DBF file has no records? Thanks
Post Follow-up to this messageOn Sat, 26 Mar 2005 08:58:42 +0000 (UTC), pete@nospam.demon.co.uk wrote: > >Hi Bambang, >It rather depends on whether one wants to account for them, such >records can after all be undeleted. I can't think of a quick way >of checking for the condition you say, but something like this >should work (apologies for the S87 syntax): > Hi Pete, If the OP doesn't want take into account deleted records he can simply: use HISDATA if Eof() ........ to check if his data contains deleted record: use HISDATA if Eof() and Reccount() <> 0 ? "There are some records but all are deleted" -- Bambang P http://bpranoto.tripod.com
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.