switching between indices

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

switching between indices

Post by ROBROS »

Hi friends,
I know it is possible to have multiple indices of dbf in one index file and then switching between them. In an old clipper book (5.01) I found the following sample: INDEX ON datei INDEX ind1, ind2, ind3.
datei is the german word for file. I suppose ind1, ind2, ind3 are the dbf-fields to be indexed.

But I get a compiler error: syntax error at 'ON'

Can anybody help please?
Robert
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: switching between indices

Post by mol »

Index syntax is:

Code: Select all

INDEX ON <expKey> [TAG <cOrderName>] [TO <cOrderBagName>]
             [FOR <lCondition>] [ALL]
             [WHILE <lCondition>] [NEXT <nNumber>]
             [RECORD <nRecord>] [REST]
             [EVAL <bBlock>] [EVERY <nInterval>]
             [UNIQUE] [ASCENDING|DESCENDING]
             [USECURRENT] [ADDITIVE]
             [CUSTOM] [NOOPTIMIZE]
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: switching between indices

Post by ROBROS »

Thank you Marek,

I found this sample I did some years ago:

Procedure OpenTables
USE bbpers alias bbpers codepage ("DE850") new
index on name+vname to name
index on persnr to persnr
set index to name,persnr
Return

switching is done by
dbsetorder(1)
dbsetorder(2)
User avatar
AUGE_OHR
Posts: 2061
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: switching between indices

Post by AUGE_OHR »

hi,
ROBROS wrote: Sun Sep 08, 2019 5:44 pm

Code: Select all

USE bbpers alias bbpers codepage ("DE850") new
where do you get Syntax "codepage ("DE850")" from :?:

Index can use Different Fields but than it must be a String:

Code: Select all

INDEX ON STREET + STR(NUMBER) TO Index_Street
// or
INDEX ON STREET + STR(NUMBER) TAG "MyStreet" TO Index_Street
to switch Index use

Code: Select all

SET ORDER TO [<nIndex>] 
// or 
SET ORDER TO TAG <cTagName> 

//or
DbSetOrder( <nIndex> ) --> NIL 
//or
OrdSetfocus( [<cTagName>|<nIndex>] )
! Note : allways open ALL Index belong to DBF else you get Index Corruption :!:

Tip : Use a Function NET_USE( cDBF ) to open DBF and Index

Code: Select all

FUNCTION NET_USE( cDBF , lExlusive)
LOCAL lRet := .F.
LOCAL nMaxTry := 10
LOCAL nTry := 0

DO WHILE nTry < nMaxTry
   DO CASE
      CASE EMPTY( cDBF )
         RETURN .F.
      CASE cDBF = "KUNDE"
         USE KUNDE NEW
      CASE cDBF = "ARTIKEL"              
         USE ARTIKEL NEW
   ENDCASE
   
   // check for Error
   IF NetErr()            
      nTry++
      LOOP
   ELSE
     // set Index
     DO CASE
       CASE cDBF = "KUNDE"
           SET INDEX TO K1, K2, K3
       CASE cDBF = "ARTIKEL"              
           SET INDEX TO A1,A2                        
          ...
     ENDCASE
     lRet := .T.
     EXIT
   ENDIF
ENDDO

RETURN lRet                   
have fun
Jimmy
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: switching between indices

Post by ROBROS »

That is how the codepage can be set:
request HB_CODEPAGE_DE850
REQUEST HB_SETCODEPAGE
set( _SET_CODEPAGE, "DE850" )

Thank you for your Index-tip. The way I did works fine.

Robert
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: switching between indices

Post by KDJ »

AUGE_OHR wrote: Sun Sep 08, 2019 8:09 pm
ROBROS wrote: Sun Sep 08, 2019 5:44 pm

Code: Select all

USE bbpers alias bbpers codepage ("DE850") new
where do you get Syntax "codepage ("DE850")" from :?:
This is in Harbour std.ch:

Code: Select all

#command USE <(db)> [VIA <rdd>] [ALIAS <a>] [<nw: NEW>] ;
            [<ex: EXCLUSIVE>] [<sh: SHARED>] [<ro: READONLY>] ;
            [CODEPAGE <cp>] [INDEX <(index1)> [, <(indexN)>]] => ;
         dbUseArea( <.nw.>, <rdd>, <(db)>, <(a)>, ;
                    iif( <.sh.> .OR. <.ex.>, ! <.ex.>, NIL ), <.ro.> [, <cp>] ) ;
         [; dbSetIndex( <(index1)> )] ;
         [; dbSetIndex( <(indexN)> )]
User avatar
AUGE_OHR
Posts: 2061
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: switching between indices

Post by AUGE_OHR »

KDJ wrote: Sun Sep 08, 2019 8:30 pm This is in Harbour std.ch:

Code: Select all

#command USE <(db)> [VIA <rdd>] [ALIAS <a>] [<nw: NEW>] ;
            [<ex: EXCLUSIVE>] [<sh: SHARED>] [<ro: READONLY>] ;
            [CODEPAGE <cp>] [INDEX <(index1)> [, <(indexN)>]] => ;
         dbUseArea( <.nw.>, <rdd>, <(db)>, <(a)>, ;
                    iif( <.sh.> .OR. <.ex.>, ! <.ex.>, NIL ), <.ro.> [, <cp>] ) ;
         [; dbSetIndex( <(index1)> )] ;
         [; dbSetIndex( <(indexN)> )]
AHA ... nice :!:
thx for Answer
have fun
Jimmy
Post Reply