Filter Building

Filter Building

Postby Ehab Samir Aziz » Tue Mar 14, 2006 12:26 pm

I am using set filter to too much and with huge DataBases it slow the machine . It there a better method than set filter ?
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Re: Filter Building

Postby Enrico Maria Giordano » Tue Mar 14, 2006 12:41 pm

Try scopes (OrdScope() function).

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Ehab Samir Aziz » Tue Mar 14, 2006 1:12 pm

in class Txbrowse The filter scope does not work . What is the wrong with those statements :


select 1
USE METE
go top
set filter to 1->me_serial="9855564"
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby R.F. » Tue Mar 14, 2006 1:33 pm

If you are used to Filters the best way is to use the ADS LOCAL server. The SET FILTER under ADS is hundred of times faster than the standard (x)Harbour filter
Saludos
R.F.
R.F.
 
Posts: 840
Joined: Thu Oct 13, 2005 7:05 pm

Postby RAMESHBABU » Thu Mar 16, 2006 3:57 am

Hi RF

In continuation to the subject topic, Please clarify :

1) If I use ADS LOCAL server, can I use the traditional SET FILTER TO
command or the ADS filter function ?

2) And if I use SET FILTER TO, will ADS understand it and filter the
records using its own functioinality ?

Please recommend the suitable function in ADS.

Regards

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby R.F. » Thu Mar 16, 2006 3:40 pm

ADS Local (free) and remote servers have the AOF Feature (Advantage Optimized Filters).

AOF are based in the traditional DBSETFILTER() function, you just have to follow certain rules when building the filter.

1) You have to load RDDADS and include the ADS DLLS
2) You have to write the filter expression in TEXTUAL form
3) You have to use DBSETFILTER() function instead of SET FILTER command.

How it works:

ADS has a build-in feature that processes the defined filters as they were SQL Queries, this means that the ADS server, not the app, resolves the filter and send you back a tiny ammount of data instead of the filtered database as Harbour does.

You only have to give the filter expresion as a TEXT, for example:

Incorrect:

Code: Select all  Expand view
x:= 25
SET FILTER TO AGE >= x
DBGOTOP()


The previos example is incorrect because "x" is a value that cannot be resolved by the ADS server, since the ADS server doesn´t know how much is "x" and cannot go inside your app memory area an "look" for the X value.

However, if you do the text instead of the value:

Code: Select all  Expand view
x:= 25
cFilter := "AGE >="+STR(x)
bFilter := "{||"+cFilter+¨}"
DBSETFILTER(&bFilter,cFilter)
DBGOTOP()


Then you will have an AOF which is thousands of times faster than the standar filter, no matter how big you database is.

I have tried this over 1000000 records and is damn fast !!!!!
Saludos
R.F.
R.F.
 
Posts: 840
Joined: Thu Oct 13, 2005 7:05 pm

Postby Ehab Samir Aziz » Sat Mar 18, 2006 8:14 pm

I tried this but with error :

select 4
USE METE
x:= '9855564'
cFilter := "(4->me_serial) == "+x
bFilter := "{||"+cFilter+"}"
DBSETFILTER(&bFilter,cFilter)
DBGOTOP()
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby R.F. » Sun Mar 19, 2006 2:49 am

Don't use "alias" in the filter expresion (4->)
Saludos
R.F.
R.F.
 
Posts: 840
Joined: Thu Oct 13, 2005 7:05 pm

Postby RAMESHBABU » Sun Mar 19, 2006 4:12 am

Mr.Ehab Samir Aziz

Don't use alias within brackets

cFilter := "(4->me_serial == )"+x


As RF said in this topic above, the alias can't be resolved by ADS
Server, since ADS can't look into our application memory area.

Hence use the expression as under. My expressions with alias as under
are working fine in filters.

cFilter := "4->me_serial == "+x


Mr.RF

Thank you very much for your guidance in using DbSetFilter() in combination with ADS.

If you are used to Filters the best way is to use the ADS LOCAL server. The SET FILTER under ADS is hundred of times faster than the standard (x)Harbour filter


When I tested it over 1200000 records, I found it faster not more than 7 times only, but not 100 times!.

Regards,

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Ehab Samir Aziz » Sun Mar 19, 2006 4:45 pm

Code: Select all  Expand view
select 4
USE METE
x:= "9855564"
cFilter := "4->me_serial = "+x
bFilter := "{||"+cFilter+"}"
DBSETFILTER(&bFilter,cFilter)
DBGOTOP()


This was my code which got argument error (=)

At the beginning That code
Code: Select all  Expand view
static oWnd
static coname
static custDlg
static oFWnd,oFld1

extern AdsKeyCount, AdsGetRelKeyPos, AdsSetRelKeyPos

#command SET SERVER LOCAL   => AdsSetServerType ( 1 )
#command SET SERVER REMOTE  => AdsSetServerType ( 2 )

#command SET FILETYPE TO <x:NTX,CDX,ADT>                              ;
      => AdsSetFileType( if( upper( <(x)> ) == "NTX", 1,              ;
                         if( upper( <(x)> ) == "CDX", 2, 3 ) ) )

STATIC cState := ""

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

function Main()
local oBrush, oBar, oBmp


   /*REQUEST DBFCDX
   rddsetdefault( "DBFCDX" )*/

   REQUEST ADS

   rddRegister( "ADS", 1 )
   rddsetdefault( "ADS" )

   SET SERVER LOCAL
   SET FILETYPE TO CDX

select 1
USE cust

INDEX ON upper(cust->cu_acct) TO cust
INDEX ON upper(cust->cu_name) TO cust1
INDEX ON upper(cust->cu_coun) TO cust2
INDEX ON upper(cust->cu_city) TO cust3
INDEX ON upper(cust->cu_gove) TO cust4
INDEX ON upper(cust->cu_stre) TO cust5
INDEX ON upper(cust->cu_phon) TO cust6
INDEX ON upper(cust->cu_fax ) TO cust7
INDEX ON upper(cust->cu_mobi) TO cust8
INDEX ON upper(cust->cu_man ) TO cust9
INDEX ON upper(cust->cu_appr) TO cust10
SET INDEX TO cust

select 2
USE cont
INDEX ON cont->CT_CU_ACCT+dtoc(cont->ct_strd) TO cont
INDEX ON cont->CT_CU_name TO cont1
INDEX ON dtoc(cont->ct_strd) TO cont2
INDEX ON dtoc(cont->ct_endd) TO cont3
INDEX ON cont->CT_machno TO cont4
INDEX ON cont->CT_mamc TO cont5
INDEX ON cont->ct_paymet TO cont6
INDEX ON cont->ct_payamt TO cont7
INDEX ON cont->ct_currenc TO cont8
INDEX ON cont->ct_excmet TO cont9
INDEX ON cont->ct_excamt TO cont10
INDEX ON cont->ct_minvol TO cont11
SET INDEX TO cont






select 3
use mach
index on mach->MC_CU_ACCT to mach
index on UPPER(mach->MC_ct_ctna) to mach1
index on UPPER(mach->MC_model) to mach2
index on UPPER(mach->MC_TYPE)+UPPER(mach->MC_model) to mach3
index on UPPER(mach->MC_serial) to mach4
index on UPPER(mach->MC_meres) to mach5
index on UPPER(mach->MC_brn) to mach6

select 4
select 4
use mete
index on mete->ME_serial to mete
index on str(mete->year) + str(mete->month) to mete1
index on mete->me_date to mete2

select 5
use coun

select 6
use city

select 7
use gove

SET 3DLOOK ON                         // Microsoft 3D Look

*   DEFINE BRUSH oBrush STYLE TILED       // FiveWin new predefined Brushes
*colors iniColor("windowText"),iniColor("appWorkSpace");
*colors iniColor("graytext"),iniColor("appWorkSpace");

   DEFINE WINDOW oWnd FROM 4, 4 TO 25, 75 ;
      colors CLR_BLACK,CLR_LIGHTGRAY;
      TITLE "Xerox Application for Outsourcing Works" ;
      MENU BuildMenu()
   DEFINE BITMAP oBmp RESOURCE "Background"

set century on
set date format to "DD/MM/YYYY"
   SET 3DLOOK ON                         // Microsoft 3D Look
//      ON RESIZE oBmp:Center()


   SET MESSAGE OF oWnd TO FWVERSION + ", " + FWCOPYRIGHT CENTERED TIME DATE

   oWnd:bPainted = { | hDC | BmpTiled( hDC, oWnd, oBmp ) }

   ACTIVATE WINDOW oWnd MAXIMIZED


return nil

[/quote]
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby R.F. » Sun Mar 19, 2006 5:56 pm

Don't use ALIAS for creating indexes, ADS cannot recognize them
Saludos
R.F.
R.F.
 
Posts: 840
Joined: Thu Oct 13, 2005 7:05 pm

Postby Ehab Samir Aziz » Sun Mar 19, 2006 8:31 pm

Code: Select all  Expand view
select 4
USE METE
x:= "9855564"
cFilter := "me_serial = "+x
bFilter := "{||"+cFilter+"}"
DBSETFILTER(&bFilter,cFilter)
DBGOTOP()


That is also does not work Argument error (=)
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby RAMESHBABU » Tue Mar 21, 2006 2:06 pm

Hi Ehab

This is the working sample for your prblem.

******

#include "FiveWin.ch"
#include "ads.ch"

FUNCTION main()

REQUEST _ADS
rddRegister( "ADS", 1 )
rddsetdefault( "ADS" )
AdsSetDeleted(.T.)
SET SERVER LOCAL
SET FILETYPE TO CDX


select 4
USE METE

x := "'9855564'"

cFilter := "me_serial = "+ x

bFilter = "{||"+cFilter+"}"

DBSETFILTER(&bFilter,cFilter)
DBGOTOP()

BROWSE()

RETURN nil

**********

Note the use of single quotes within Double quotes of x value assignment.
Else the value of `x' is converted as as a number in macro evaluation i.e.
&bFilter and generates a run time error, bacuase of two different data types comparision in filter condition.


Regards,

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Ehab Samir Aziz » Tue Mar 21, 2006 5:52 pm

it is work fine with your example but with footer function it is not
Code: Select all  Expand view
STATIC FUNCTION Footers( oWnd )
*--------------------------
   local oChild, oBrw
   local nFor
   local bFilter := ""
   local cFilter := ""
   local x := ""

REQUEST ADS
rddRegister( "ADS", 1 )
rddsetdefault( "ADS" )
AdsSetDeleted(.T.)
SET SERVER LOCAL
SET FILETYPE TO CDX

select 4
USE METE

x := "'9855564'"

cFilter := "me_serial = "+ x

bFilter = "{||"+cFilter+"}"

DBSETFILTER(&bFilter,cFilter)
DBGOTOP()




   DEFINE WINDOW oChild FROM 4, 4 TO 25, 75 ;
   TITLE "Meter Works"

   oBrw := TXBrowse():New( oChild )

   oBrw:nMarqueeStyle       := MARQSTYLE_HIGHLCELL
   oBrw:nColDividerStyle    := LINESTYLE_BLACK
   oBrw:nRowDividerStyle    := LINESTYLE_BLACK
   oBrw:lColDividerComplete := .t.
   oBrw:nHeaderLines        := 1
   oBrw:nFooterLines        := 1
   oBrw:nDataLines          := 2
   oBrw:lFooter             := .t.
   oBrw:SetRDD()



   for nFor := 1 to Fcount()
   if nFor=20
      oBrw:aCols[ nFor ]:cHeader       := FieldName( nFor )
      oBrw:aCols[ nFor ]:cFooter       := alltrim(STR(TOTALEM2(),12,0))
      loop
   endif
      *oBrw:aCols[ nFor ]:cHeader       := "Field: " + ltrim( str( nFor ) ) + CRLF + FieldName( nFor )
      oBrw:aCols[ nFor ]:cHeader       := FieldName( nFor )
      oBrw:aCols[ nFor ]:cFooter       := FieldName( nFor )
      oBrw:aCols[ nFor ]:bRClickHeader := {|r,c,f,o| Msginfo("Right click on column header " + o:cHeader, "TXBrowse power") }
      oBrw:aCols[ nFor ]:bLClickFooter := {|r,c,f,o| Msginfo("Left click on column footer " + o:cHeader, "TXBrowse power") }
      oBrw:aCols[ nFor ]:bRClickFooter := {|r,c,f,o| Msginfo("Right click on column footer " + o:cHeader, "TXBrowse power") }
      oBrw:aCols[ nFor ]:blDClickData  := {|r,c,f,o| Msginfo("Left double click on column data " + o:cHeader, "TXBrowse power") }
      oBrw:aCols[ nFor ]:bRClickData   := {|r,c,f,o| Msginfo("Right click on column data " + o:cHeader, "TXBrowse power") }
   next




   oBrw:CreateFromCode()

   oChild:oClient := oBrw

   ACTIVATE WINDOW oChild MAXIMIZED ON INIT oBrw:SetFocus()

RETURN NIL
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests