FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour temporay index
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
temporay index
Posted: Thu Jul 28, 2011 08:03 PM

Hello,

I create a temporary index on a dbf that already has been opened with other indexes.

But I want to restore the original state but I can´t.

How do I close temporary index and go back to original indexes?.

Thank you,

FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: temporay index
Posted: Thu Jul 28, 2011 10:12 PM

Can you open/use dbf again?

Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: temporay index
Posted: Fri Jul 29, 2011 06:33 AM

If you use DBFCDX with OrdSetFocus( original cTag)

Maurizio

Posts: 55
Joined: Fri Jul 08, 2011 06:43 AM
Re: temporay index
Posted: Fri Jul 29, 2011 07:39 AM

When you create the temp. index , add ADDITIVE

Frank

Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
Re: temporay index
Posted: Fri Jul 29, 2011 01:25 PM

Thank you. I missed Additive.

Also, how many times could I create new indexes with additive clause?

Thanks.

FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: temporay index
Posted: Fri Jul 29, 2011 03:30 PM
Consider this code using an .idx on an open table ( may have to be opened exclusively ) if you really just want this index to be temporary .. say for a report .. then when you are done .. close the table ( or close the index ) and delete the .idx.. This will eliminate the need to add another tag to an existing .CDX.

Rick Lipkin

Code (fw): Select all Collapse
// create a name for the index in a temp folder

// get application default .. assumes that
// SET DEFA to    was defined in the program startup

cDEFA := SET(7)  


DO WHILE .T.
   SITEiDX := "TEMP"+(SUBSTR(TIME(),7,2)+SUBSTR(TIME(),4,2))+".IDX"
   IF .not. FILE( cDEFA+"\DBTMP\"+SITEiDX )
      EXIT
   ENDIF
ENDDO

// open table shared
// should work without opening table exclusively

SELECT 4
IF NETUSE( cDEFA+"\Table.dbf", .F.,5)
    SET ORDER to TAG Whatever
ELSE
   CLOSE DATABASES
    FERASE( cDEFA+"\DBTMP\"+SITEiDX)
   oDlg:END()
   RETURN(.F.)
ENDIF

SELECT 4
INDEX on YourField to ( cDEFA+"\DBTMP\"+SITEiDX )
SET INDEX to ( cDEFA+"\DBTMP\"+SITEiDX )

// .. do what you need

CLOSE 4
FERASE( cDEFA+"\DBTMP\"+SITEiDX)

// if you need to keep the table open you can
// attempt to close the index
//
// SELECT 4
// CLOSE( cDEFA+"\DBTMP\"+SITEiDX)
// FERASE( cDEFA+"\DBTMP\"+SITEiDX)  
//
// SELECT 4
// SET ORDER to TAG Whatever
// .. continue on with your code

oDlg:END()
RETURN(.T.)
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: temporay index
Posted: Fri Jul 29, 2011 05:02 PM
I know xHarbour has the "temporary" clause on the "index on" command. It manages the temporary index automatically. It is created on the local computer and deleted after the dbf is closed.
Here is some documentation on the index clauses you might be interested in. I don't know if all of these are implemented in Harbour.

    USECURRENT - The option instructs the database driver to use the current logical order of records for navigating the database during index creation. The logical order is determined by the controlling index and the SET SCOPE restriction. When the USECURRENT clause is omitted, the records in the current work area are evaluated in physical order.

    ADDITIVE - The option makes sure that index files remain open during index creation. If not specified, all files but <cIndexFile> are closed prior to indexing.

    TEMPORARY - If this option is specified, a temporary index is created which is automatically destroyed when the index is closed. The temporary index may be created in memory only or in a temporary file. This lies in the responsibility of the RDD used for index creation.

    USEFILTER - This option instructs the RDD to recognize a filter condition active in the current work area that is set with SET FILTER or SET DELETED. In this case, filtered records are not included in the index.
    [/list:u]
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
Re: temporay index
Posted: Sun Jul 31, 2011 11:39 AM

Thank you.

I finally use:

close( cIndex )

ferase( cIndex )

set order to 1

It is working perfect with additive clause.

But why index are faster than set filter?.

Why set filter is not optimized?.

Thank you.

FWH 11.11, Harbour 3.1 and Borland C++ 5.82

Continue the discussion