How can make a Filter condition on TDatabase Class?

How can make a Filter condition on TDatabase Class?

Postby Sakis » Sun Dec 11, 2005 10:24 am

Hello to EveryOne

How can make a filter condition on TDatabase Class?

Any help would be apreciate.

Many Thanks
Regards
Dionisis
User avatar
Sakis
 
Posts: 42
Joined: Fri Oct 21, 2005 2:12 pm
Location: Athens

Postby Antonio Linares » Sun Dec 11, 2005 12:12 pm

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

Postby Sakis » Sun Dec 11, 2005 1:15 pm

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
Sakis
 
Posts: 42
Joined: Fri Oct 21, 2005 2:12 pm
Location: Athens

Postby Antonio Linares » Sun Dec 11, 2005 3:02 pm

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

Postby Sakis » Sun Dec 11, 2005 4:45 pm

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  Expand view
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
Sakis
 
Posts: 42
Joined: Fri Oct 21, 2005 2:12 pm
Location: Athens

Postby Antonio Linares » Sun Dec 11, 2005 6:27 pm

Dionisis,

You have to reload the database object from the codeblock:

Code: Select all  Expand view
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
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Sakis » Sun Dec 11, 2005 8:34 pm

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
Sakis
 
Posts: 42
Joined: Fri Oct 21, 2005 2:12 pm
Location: Athens

Postby Antonio Linares » Sun Dec 11, 2005 10:27 pm

Dionisis,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 65 guests