For Programmers: Free Programming Magazines  


Home > Archive > Clipper > March 2005 > Check if DB is empty









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Check if DB is empty
Pablo García

2005-03-25, 8:55 pm

Hi,

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

Thanks


Pablo García

2005-03-25, 8:55 pm

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
>



Johan Nel

2005-03-25, 8:55 pm

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



Ray Marron

2005-03-25, 8:55 pm

"Pablo García" <pgarcia@chasque.net> wrote in message
news:1148uuqftks0422@news.supernews.com...
[...]
[...][color=darkred]
> 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


Pablo García

2005-03-25, 8:55 pm

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



Rob Grattan

2005-03-26, 8:55 am

What about lastrec()? According to something I read, lastrec() supercedes
reccount()...

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


Bambang P

2005-03-26, 8:55 am

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
pete@nospam.demon.co.uk

2005-03-26, 8:55 am

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[color=darkred]
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."
Andi Jahja

2005-03-26, 8:55 pm

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[color=darkred]
Bambang P

2005-03-27, 3:55 am


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
pete@nospam.demon.co.uk

2005-03-27, 8:55 am

In article <c5lc41h1cguv9scl2h3b65tttsq3lb00dv@4ax.com>
bpranoto_nospam@hotpop.com "Bambang P" writes:

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


But doesn't eof() depend on the 'set deleted' setting?
[checks]
It seems to here; eof() only returns .t. when 'deleted' is ON.

Pete
--
"We have not inherited the earth from our ancestors,
we have borrowed it from our descendants."
pete@nospam.demon.co.uk

2005-03-27, 8:55 am

In article <d24kk2$msd$1@newsreader.mailgate.org>
somewhere@internet.com "Andi Jahja" writes:

> Slowly knock the file with your finger tips.
> If it sounds hollow, then it's empty.


Ah - of course! Why is it that I never think of the _obvious_
solution... ;-)

Pete
--
"We have not inherited the earth from our ancestors,
we have borrowed it from our descendants."
Nick Ramsay

2005-03-27, 8:55 am

On Sun, 27 Mar 2005 07:39:21 +0000 (UTC), pete@nospam.demon.co.uk
wrote:

>In article <c5lc41h1cguv9scl2h3b65tttsq3lb00dv@4ax.com>
> bpranoto_nospam@hotpop.com "Bambang P" writes:
>
>
>But doesn't eof() depend on the 'set deleted' setting?
>[checks]
>It seems to here; eof() only returns .t. when 'deleted' is ON.
>
>Pete


The only sure way would be to use HEADER()+1 as the base size of the
file, then subtract that from the filesize and if you have a positive
number, you have records.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com