Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Use Index Files with Offline Views


View products that this article applies to.

This article was previously published under Q192857

↑ Back to the top


Summary

The introduction of Offline views in Visual FoxPro 5.0 enabled users to work with selected data sets while disconnected from the server. Use of indexes and functions that take advantage of Rushmore Optimization provide a highly efficient method of searching Offline view data sets.

This article explains how to create and use indexes with Offline views.

↑ Back to the top


More information

Creation of an Offline view creates a table structure and properties that match the structure and properties of the source view. Issuing an index command with an Offline view creates an index file for the Offline view. The Table and Index(es) remain in the directory in which the Offline view was created until a DROPOFFLINE() command is issued or the Offline view is USEd ONLINE or in ADMIN mode. When the Offline view is taken back online, the table and index files are deleted from the disk.

Create a program file named OFFINDEX.PRG, using the following code:
   SET SAFETY OFF
   SET MULTILOCKS ON
   * Create a database
   CREATE DATABASE MYOLV
   * Declare API function to create ODBC DSN
   DECLARE INTEGER SQLConfigDataSource IN odbccp32.DLL ;
      INTEGER, INTEGER, STRING, STRING
   IF VAL(SUBSTR(VERSION(),15,2))=6
      lcDir=HOME(2)+"data\"
   ELSE
      lcDir=HOME()+"SAMPLES\DATA\"
   ENDIF
   * Information to setup ODBC DSN
   lcSetUp="DSN=MyOffLine"+CHR(0)+;
      "Description=VFP Offline View Demo"+CHR(0)+;
      "SourceDB="+lcDir+"testdata.dbc"+CHR(0)+;
      "SourceType=DBC"
   * Call API function to create a DSN
   =SQLConfigDataSource(0,1,"Microsoft Visual FoxPro Driver",lcSetUp)
   CLEAR DLLS
   * Create a connection
   CREATE CONNECTION MyOLV DATASOURCE "myoffline"
   * Create a view to take offline
   CREATE SQL VIEW test REMOTE CONNECT MyOLV ;
      AS SELECT cust_id, company, city ;
      FROM customer ;
      ORDER BY customer.cust_id
   USE test
   * Take the view offline
   * Creates file named 'TEST.DBF'
   =CREATEOFFLINE('test')
   * Close all and open the Table for OffLine view
   CLOSE ALL
   USE test.dbf
   * Create structural indexes on the Offline view
   INDEX ON cust_id TAG cust_id OF ALIAS()
   INDEX ON city TAG city OF ALIAS()
   * Set the order to customer id
   SET ORDER TO TAG cust_id
   LOCATE
   BROWSE TITLE "ORDERED BY CUSTOMER ID"
   * Set the order to city
   SET ORDER TO TAG city
   BROWSE TITLE "ORDERED BY CITY"
   * Create an IDX index
   INDEX ON city+company TO cocity
   BROWSE TITLE "ORDERED BY City and Company Using IDX FILE"
   * Revert any changes and take the view back online
   CLOSE ALL
   OPEN DATABASE MyOLV
   =DROPOFFLINE('test')
   * Indexes and working table destroyed with dropoffline command.
   * Close the view
   CLOSE ALL
   RETURN
				
Note that the table order changes when the order is changed. Also note that the table and all associated files are deleted when the offline view is taken back online.

↑ Back to the top


References

For additional information, please see the following articles in the Microsoft Knowledge Base:
165234� PRB: CREATEOFFLINE Opens Parent Table Exclusively

156552� How To Use Offline Views in Visual FoxPro

156013� INFO: Possible Uses for Offline Views in Visual FoxPro

156011� INFO: Use of the ADMIN Clause with Offline Views

155820� How To Refreshing an Offline View in Visual FoxPro 5.0

155528� How To Set Up an Offline View in Visual FoxPro 5.0

↑ Back to the top


Keywords: KB192857, kbhowto, kbdatabase

↑ Back to the top

Article Info
Article ID : 192857
Revision : 3
Created on : 7/13/2004
Published on : 7/13/2004
Exists online : False
Views : 454