DBeval for unique values

DBeval for unique values

Postby Marc Venken » Thu Jan 31, 2019 6:55 pm

Hello,

Is there a function to fill a array with unique values from a dbf field ?

Ex. STate has : A B C A B B B D

the array should have A,B,C,D

The purpose is in a Xbrowse to filter data with a combo from a
BarGet.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1343
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: DBeval for unique values

Postby James Bott » Thu Jan 31, 2019 7:47 pm

There is a "UNIQUE" clause for indexes:

INDEX … UNIQUE

That might help. However, It seems to me that you have already established the set of unique values, or are you going to let users enter new values too?

Perhaps you need a separate database for these.

I think we need more information.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: DBeval for unique values

Postby Marc Venken » Thu Jan 31, 2019 8:32 pm

James,

Asume the folowing

I will Xbrowse all Customers and many colums end have the getbars on top of Xbrowse.

I can put "Senford" in the col city, hit the filter button and I will have all customers from Senford.

No let say that I don't know the possible city's. Therefore I want to make a Combobox in the Xbrowse with the unique city's.

Your suggestion is right. I could make a temp dbf or index and then fill a array for the combo.

Maybe FW_dbftoarr has a option. I will look into it.

Thanks
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1343
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: DBeval for unique values

Postby nageswaragunupudi » Thu Jan 31, 2019 9:13 pm

For example, we need an array of unique values of the field STATE from customer.dbf

Case-1:
If you already have a Unique Index on STATE.
Code: Select all  Expand view

aVals := {}
SET ORDER TO TAG STATEUNQ
DBGOTOP()
DBEVAL( { || AAdd( aVals, FIELD->STATE } )
 


Case-2:
You have a normal index on STATE ( not unique )
Code: Select all  Expand view

   OrdSetFocus( "STATE" )
   DBGOTOP()
   do while !Eof()
      AADD( aVals, OrdKeyVal() )
      OrdSkipUnique()
   enddo
 


Case-3:
You do not have index on STATE at all. (neither normal nor unique)
One option is to create a temporary index in memory:
Code: Select all  Expand view

   INDEX ON STATE TAG STATEUNQ TO TMP MEMORY ADDITIVE UNIQUE
 

Adopt the logic in Case-1.

Case-4
If we do not want to use indexes.
Code: Select all  Expand view

aVals := {}
   DBGOTOP()
   DBEVAL( { || If( AScan( aVals, FIELD->STATE ) == 0, AAdd( aVals, FIELD->STATE ), nil ) } )
   DBGOTOP()
   ASORT( aVals )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10252
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: DBeval for unique values

Postby Marc Venken » Thu Jan 31, 2019 10:18 pm

Thanks you for the options.

Some new technique's for me...
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1343
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: DBeval for unique values

Postby ukoenig » Fri Feb 01, 2019 12:36 pm

Mr. Rao,

I added the 4 array unique-tests to the tDatabase-samples

Image

This doesn't exist
Is there a replacement for it :?:

Case-2 and 3 :
oCust:OrdSkipUnique()

Code: Select all  Expand view
 
// You have a normal index on LAST ( not unique )

oCust:OrdSetFocus( "CUST1" )
oCust:GoTop()
do while !oCust:Eof()
      AADD( aVals, { oCust:Last, oCust:First } )  
      oCust:OrdSkipUnique() // !!!! not possible
enddo
 


That skips unique records on normal index
changed to :

Code: Select all  Expand view

// You have a normal index on LAST ( not unique )

oCust:OrdSetFocus( "CUST1" )
oCust:GoTop()

cStrTest := oCust:Last + oCust:First
lUnique := .F.

DO WHILE !oCust:Eof()
     IF lUnique = .F.
          AADD( aVals, { oCust:Last, oCust:First } )
     ENDIF
     oCust:Skip(+1)
     // OrdSkipUnique() !!!
     IF cStrTest = oCust:Last + oCust:First
          lUnique := .T.
     ELSE
         lUnique := .F.
         cStrTest := oCust:Last + oCust:First
     ENDIF
ENDDO
 


regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Jimmy and 14 guests