Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Check if DB is empty
Hi,

Is there any function to check if a DBF file has no records?

Thanks



Report this thread to moderator Post Follow-up to this message
Old Post
Pablo García
03-26-05 01:55 AM


Re: Check if DB is empty
Nevermind, 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
>



Report this thread to moderator Post Follow-up to this message
Old Post
Pablo García
03-26-05 01:55 AM


Re: Check if DB is empty
Pablo,

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
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Johan Nel
03-26-05 01:55 AM


Re: Check if DB is empty
"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



Report this thread to moderator Post Follow-up to this message
Old Post
Ray Marron
03-26-05 01:55 AM


Re: Check if DB is empty
Thanks, 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
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Pablo García
03-26-05 01:55 AM


Re: Check if DB is empty
What about lastrec()?  According to something I read, lastrec() supercedes
reccount()...

--
Rob Grattan
R&D Software Pty. Ltd.



Report this thread to moderator Post Follow-up to this message
Old Post
Rob Grattan
03-26-05 01:55 PM


Re: Check if DB is empty
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Bambang P
03-26-05 01:55 PM


Re: Check if DB is empty
In 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."

Report this thread to moderator Post Follow-up to this message
Old Post
pete@nospam.demon.co.uk
03-26-05 01:55 PM


Re: Check if DB is empty
Slowly 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 

Report this thread to moderator Post Follow-up to this message
Old Post
Andi Jahja
03-27-05 01:55 AM


Re: Check if DB is empty
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Bambang P
03-27-05 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Clipper archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:55 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.