How can make a Filter condition on TDatabase Class?

Post Reply
User avatar
Sakis
Posts: 41
Joined: Fri Oct 21, 2005 2:12 pm
Location: Athens

How can make a Filter condition on TDatabase Class?

Post by Sakis »

Hello to EveryOne

How can make a filter condition on TDatabase Class?

Any help would be apreciate.

Many Thanks
Regards
Dionisis
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Sakis
Posts: 41
Joined: Fri Oct 21, 2005 2:12 pm
Location: Athens

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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() ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Sakis
Posts: 41
Joined: Fri Oct 21, 2005 2:12 pm
Location: Athens

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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")
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Sakis
Posts: 41
Joined: Fri Oct 21, 2005 2:12 pm
Location: Athens

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Dionisis,

You should use a temporary index created with a FOR clause. Its the best way.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply