TDatabase: Parameterized filters and ReFilter()

Post Reply
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

TDatabase: Parameterized filters and ReFilter()

Post by nageswaragunupudi »

SetFilter( cFilter, aParams )

Code: Select all | Expand


oDbf:SetFilter( "AGE >= ? .AND. AGE <= ?", { 30, 40 } )
// This sets filter AGE >= 30 .AND. AGE <= 40

// Later
oDbf:ReFilter( { 40, 50 } )
// changes the filter as AGE >= 40 .AND. AGE <= 50
 


SetFilter( cFilter, bParams )

Code: Select all | Expand


n1 := 30
n2 := 40
oDbf:SetFilter( "AGE >= ? .AND. AGE <= ?", { || { n1, n2 } } )
// This sets filter AGE >= 30 .AND. AGE <= 40

// Later
n1 := 40
n2 := 50
oDbf:ReFilter()
// changes the filter as AGE >= 40 .AND. AGE <= 50
 


The following sample uses the second method of using bParams (codeblock) to implement xbrowse with incremental filter on two fields.

Code: Select all | Expand

#include "fivewin.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oFont, oBrw, oGet1, oGet2, oDbf
   local cName := Space( 20 )
   local cCity := Space( 20 )

   SetGetColorFocus()

   oDbf  := TDataBase():Open( nil, "CUSTOMER", "DBFCDX", .t. )

   // Parameterized filter with codeblock
   oDbf:SetFilter( "UPPER(FIRST) = ? .AND. UPPER(CITY) = ?", ;
        { || { UPPER(ALLTRIM(cName)), UPPER(ALLTRIM(cCity)) } } )

   oDbf:GoTop()

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 700,400 PIXEL TRUEPIXEL FONT oFont

   @  22, 20 SAY "FILTER: Name: " SIZE 100,24 PIXEL OF oDlg

   @  20,150 GET oGet1 VAR cName SIZE 150,26 PIXEL OF oDlg ;
      ON CHANGE ( oGet1:Assign(), oDbf:ReFilter(), oDbf:GoTop(), oBrw:Refresh() )

   @  22,310 SAY "City: " SIZE 50,24 PIXEL OF oDlg RIGHT

   @  20,380 GET oGet2 VAR cCity SIZE 150,26 PIXEL OF oDlg ;
      ON CHANGE ( oGet2:Assign(), oDbf:ReFilter(), oDbf:GoTop(),oBrw:Refresh() )

   @  55, 20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oDbf ;
      COLUMNS "FIRST", "LAST", "CITY" ;
      CELL LINES NOBORDER FOOTERS

   WITH OBJECT oBrw
      :RecSelShowRecNo()
      :bClrSel := :bClrSelFocus
      :CreateFromCode()
   END

  ACTIVATE DIALOG oDlg CENTERED
  RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 7170
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 5 times

Re: TDatabase: Parameterized filters and ReFilter()

Post by Silvio.Falconi »

nice job
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
Posts: 7170
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 5 times

Re: TDatabase: Parameterized filters and ReFilter()

Post by Silvio.Falconi »

Nages,
I need to make a filter with different fields ie for example:


Code: Select all | Expand

         cFilter := "trim(Tipo) == '" + cTipo +;
                  "' .and. alltrim(str(giorni))== '" + alltrim(str(nGiorni)) +;
                  "' .and. idelemento== '"+cidelemento+;
                  "' .and. settore== '" +cSettore+;
                  "' .and. alltrim(idlistino)== '" +clistino+;
                  "' .and. alltrim(str(mese))== '" + alltrim(str(nmese)) +"'"

   oTariffePrezzi:= TDatabase():Open( nil,oApp:cDbfPath+"TARIFFE", "DBFCDX", .t. )
    oTariffePrezzi:setOrder(1)
    oTariffePrezzi:setFilter(cFilter)
    oTariffePrezzi:gotop()
 


is there another method more easy ?
because sometimes I risk making mistakes by omitting "'"
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: TDatabase: Parameterized filters and ReFilter()

Post by nageswaragunupudi »

cFilter := "TRIM(TIPO) == ? .AND. GIORNI == ? .AND. IDELEMENTO == ? .AND. " + ;
"SETTORE == ? .AND. ALLTRIM(IDLISTINO) == ? .AND. MESE == ?"

oDbf:SetFilter( cFilter, { cTipo, nGiorni, cidelemento, cSettore, clistino, nmese } )
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 7170
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 5 times

Re: TDatabase: Parameterized filters and ReFilter()

Post by Silvio.Falconi »

Gulp, nice !!!
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: TDatabase: Parameterized filters and ReFilter()

Post by nageswaragunupudi »

When you set filter with
oDbf:SetFilter( cFilter, aParams )
The method applier the aParams to cFilter and prepares the filter string to set the filter.
You can check the exact filter string with
? oDbf:DBFILTER()
and see if this is what you expected.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 7170
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 5 times

Re: TDatabase: Parameterized filters and ReFilter()

Post by Silvio.Falconi »

all this for the next package ?
when is go out ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: TDatabase: Parameterized filters and ReFilter()

Post by nageswaragunupudi »

It is already there in many past versions.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 7170
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 5 times

Re: TDatabase: Parameterized filters and ReFilter()

Post by Silvio.Falconi »

nageswaragunupudi wrote:It is already there in many past versions.


Nages,
I can converte also this block ?

Code: Select all | Expand


oPrenotazioni  := TDatabase():Open( nil, oApp():cDbfPath+"RESERVA",   "DBFCDX", .t. )
              oPrenotazioni:Exec( < ||
              SET FILTER TO AllTrim( FIELD->TYPE ) = AllTrim( cTipoElemento ) .and. VAL(FIELD->ROOMS_ID) = nElemento ;
                 .AND. ( dDataIniziale <= FIELD->CHECK_OUT .AND. dDataFinale >= FIELD->CHECK_IN )
             return nil
             > )
              oPrenotazioni:gotop()

 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: TDatabase: Parameterized filters and ReFilter()

Post by nageswaragunupudi »

yes
try
Regards

G. N. Rao.
Hyderabad, India
Post Reply