switching between indices

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
ROBROS
Posts: 188
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen
Has thanked: 56 times
Been thanked: 18 times

switching between indices

Post by ROBROS » Sun Sep 08, 2019 5:26 pm

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: 3250
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 233 times
Been thanked: 132 times
Contact:

Post by mol » Sun Sep 08, 2019 5:38 pm

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: 188
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen
Has thanked: 56 times
Been thanked: 18 times

Post by ROBROS » Sun Sep 08, 2019 5:44 pm

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: 209
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany
Has thanked: 21 times
Been thanked: 28 times

Post by AUGE_OHR » Sun Sep 08, 2019 8:09 pm

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                   

ROBROS
Posts: 188
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen
Has thanked: 56 times
Been thanked: 18 times

Post by ROBROS » Sun Sep 08, 2019 8:22 pm

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: 231
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 264 times

Post by KDJ » Sun Sep 08, 2019 8:30 pm

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: 209
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany
Has thanked: 21 times
Been thanked: 28 times

Post by AUGE_OHR » Sun Sep 08, 2019 11:32 pm

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

Post Reply