Page 1 of 1
How can make a Filter condition on TDatabase Class?
Posted: Sun Dec 11, 2005 10:24 am
by Sakis
Hello to EveryOne
How can make a filter condition on TDatabase Class?
Any help would be apreciate.
Many Thanks
Regards
Dionisis
Posted: Sun Dec 11, 2005 12:12 pm
by Antonio Linares
Dionisis,
You may implement and try this new Class TDataBase Method SetFilter():
METHOD SetFilter( bCondition, cCondition ) INLINE If( bCondition != nil, ( ::nArea )->dbSetFilter( bCondition, cCondition ), ( ::nArea )->dbClearFilter() )
Example:
oDbf:SetFilter( { || oDbf:Load(), oDbf:Age > 20 }, "Age > 20" )
Posted: Sun Dec 11, 2005 1:15 pm
by Sakis
Hello Antonio
Unfortunately this new method dosen't Works. I get a compiler error
Parse Error At ( (shownig the (::nArea)->)
Any Suggestion to overcome this ?
Compiler xHarbour Commercial October 2005 release
FWH 2.7
Many Thanks
Dionisis
Posted: Sun Dec 11, 2005 3:02 pm
by Antonio Linares
Dionisis,
Ops, my mistake, sorry
This should be the right code:
METHOD SetFilter( bCondition, cCondition ) INLINE If( bCondition != nil, ( ::nArea )->( dbSetFilter( bCondition, cCondition ) ), ( ::nArea )->( dbClearFilter() ) )
Posted: Sun Dec 11, 2005 4:45 pm
by Sakis
Hi again Antonio.
The code pass from the compiler but when implemented on a real database i get a mass.
As an example i have one database named Transacs.dbf that contain a field named MDAY and is of type date . When assigning a filter like
Code: Select all
odbINSTALL:SetFilter({||Month(odbInstall:MDAY)=Month(Date())},;
"Month(odbInstall:Mday)=Month(Date())")
MsgInfo (STR(odbInstall:Reccount())+" Records Fouds")
I get the number of 10 records. The record number of the whole database, without filtering.
What i make wrong!!!
Many thanks for your patience.
Regards
Dionisis
Posted: Sun Dec 11, 2005 6:27 pm
by Antonio Linares
Dionisis,
You have to reload the database object from the codeblock:
Code: Select all
odbINSTALL:SetFilter({||odbINSTALL:Load(), Month(odbInstall:MDAY)=Month(Date())},;
"Month(odbInstall:Mday)=Month(Date())")
MsgInfo (STR(odbInstall:Reccount())+" Records Fouds")
Posted: Sun Dec 11, 2005 8:34 pm
by Sakis
Antonio
This method works but it is usefull with Browsers and not to namipulate directly the aBuffer or to count the length of a filetered database.
What i mean is that after applying the method SetFilter(). The lenght of database not varies. I get the same Reccout() with or without the SetFilter() method. Nothing happens the only defference i noticed is when i call the Browse() function it displays the correct portion of filtered database.
Those are my observations for the SetFilter() method. I giveup and look for another approach.I know that is difficult but i hope to deal with this difficult situation.
Regards and goodnight
Dionisis
Posted: Sun Dec 11, 2005 10:27 pm
by Antonio Linares
Dionisis,
You should use a temporary index created with a FOR clause. Its the best way.