How to Use GENDBC to Create Utility that Recreates Complex CDX

ID: Q135112


The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0


SUMMARY

Gendbc.prg is a program file that is included with Visual FoxPro and is used to generate code for the purpose of rebuilding a database container (.DBC) file. It is installed by default in the VFP30\Tools\Gendbc directory. Once this program is run with your database open, it will generate code that will recreate the .DBC file, any tables and indexes, and any persistent relations that exist in the database. If any changes are made to the structure of your database, you must rerun Gendbc.prg for the changes to be reflected in the code generated by it.

NOTE: The resulting generated program is primarily used in case your database container becomes corrupt. It will rebuild the structure; however, lost data is irrecoverable. It is a good idea to back up your data on a regular basis. For more information on Gendbc.prg and its use, please see the online documentation or help file.


MORE INFORMATION

While its main purpose is to create code for rebuilding a database (.DBC) file, Gendbc.prg can also be used for a variety of other purposes. One such purpose would be for creating code for rebuilding indexes that are attached to the tables contained in the database.

The following code is an excerpt from Testdata.prg, which is the program file generated by GENDBC with the Testdata.dbc in use. Testdata.dbc is installed by default in the VFP30\Samples\Data directory.


   ***** Create each index for CUSTOMER *****
   INDEX ON COMPANY TAG COMPANY
   INDEX ON CONTACT TAG CONTACT
   INDEX ON POSTALCODE TAG POSTALCODE
   ALTER TABLE 'CUSTOMER' ADD PRIMARY KEY CUST_ID TAG CUST_ID

   ***** Create each index for PRODUCTS *****
   ALTER TABLE 'PRODUCTS' ADD PRIMARY KEY PRODUCT_ID TAG PRODUCT_ID

   ***** Create each index for ORDITEMS *****
   INDEX ON ORDER_ID+STR(LINE_NO,5,0) TAG ORDER_ID
   INDEX ON PRODUCT_ID TAG PRODUCT_ID

   ***** Create each index for ORDERS *****
   INDEX ON CUST_ID TAG CUST_ID
   INDEX ON EMP_ID TAG EMP_ID
   ALTER TABLE 'ORDERS' ADD PRIMARY KEY ORDER_ID TAG ORDER_ID

   ***** Create each index for EMPLOYEE *****
   ALTER TABLE 'EMPLOYEE' ADD PRIMARY KEY EMP_ID TAG EMP_ID 
These segments of code can be placed into a separate program file, procedure, function, stored procedure, or method and can be called at any time to rebuild the indexes of the tables that are in the Testdata.dbc database. You can execute Gendbc.prg with your database open and it will generate similar code for recreating your database and any indexes attached to the tables contained in it.

Additional query words: VFoxWin Utilities Tools CDX DBC

Keywords : kbcode FxtoolGeneral
Version : 3.00
Platform : WINDOWS
Issue type :


Last Reviewed: August 20, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.