Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rebuilding tables

Status
Not open for further replies.

lemonjuice

Programmer
Jun 12, 2003
62
ZA
Is there a command in Object PAL that allows you to rebuild tables?
 
Lemonjuice,

I had a quick look under help using 'restructure' as the keyword and found this:
"Restructures a table.

Syntax

restructure( const createSpec DynArray[ ] AnyType ) Logical

Description

restructure allows you to modify a table's structure under program control. You can add, delete, or modify the fields in your table, create indexes, change referential integrity relationships, and so on. restructure also allows you to perform other operations that are available when restructuring a table (for example: packing the table).

restructure uses a dynamic array named createSpec, which contains the information on the changes to make to the table.

To specify the kind of change to be made, the field, index, referential integrity, and security structure tables, if specified, must include an ID field. This ID field is named slightly differently in each structure file, however, all end with id. Use this ID field to specify the type of operation to perform. The RestructureOperations constants RestructureModify, RestructureAdd, and RestructureDrop are provided for each operation.

restructure returns True if successful, and False if the restructure operation fails, or if a Keyviol or Problems table is generated. It also fails if it cannot obtain a full lock on the table.

The following clauses specify table attributes in createSpec and are optional. They can appear in any order within the dynamic array:

saveAs specifies a new name for the restructured table, leaving the original table unchanged. By default, the restructured table is saved with the same name, which overwrites the original table.

Keyviol specifies the table to which any records causing a key violation are saved.

Problems specifies the table to which any problem records are saved. If data is lost during the restructure, the problem records are placed in the problems table, and the operation that caused the problem is not performed on those records.

fieldStruct specifies the name of the table from which you can borrow field structure information. Use enumFieldStruct to generate the field structure table before executing restructure. The _Invariant Field Id field of the field structure table contains the original field number of the table to be restructured. Use the _Invariant Field Id field to specify the change to be made to the table. To add a field, insert a new record in the field structure table describing the new field and place 0 in the _Invariant Field Id field. To delete an existing field, remove the record from the field structure table.

indexStruct specifies the name of the table from which you can borrow index structure information. Use enumIndexStruct to generate the index structure table (or create it manually). Use the iIndexId field of the index structure table to specify the change to be made to the table. To modify an index, use RestructureModify in the iIndexId field. You can modify an index name by dropping (RestructureDrop), and adding (RestructureAdd) another record with the changed name.

refIntStruct specifies the name of the table from which you can borrow referential integrity structure information. Use enumRefIntStruct to generate the referential integrity structure table (or create it manually). Use the iRefId field of the referential integrity structure table to specify the change to be made to the table. Use RestructureModify to modify existing values, RestructureAdd to add, or RestructureDrop to delete.

secStruct specifies the table from which you can borrow security structure information. Use enumSecStruct to generate the security structure table name (or create it manually). Use the iSecId field in the security structure table to specify the change to be made to the table. Use RestructureModify to modify existing values, RestructureAdd to add, or RestructureDrop to delete.

pack specifies whether to pack the table. Valid values are True or False. For more information, see compact (Table type).

versionLevel specifies the table version level. See create for a listing of version numbers for Paradox and dBASE tables.

languageDriver specifies the language driver name. For a list of language drivers for Paradox tables, see Language drivers for Paradox tables. For dBASE tables, see Language drivers for dBASE tables.

blockSize specifies the size of data blocks used to store information in the table, in kilobytes. (A kilobyte is 1,024 bytes.) Valid block sizes depend on the file format of the table. For Paradox versions 4.5 or earlier, 1K through 4K are valid. For versions 5.0 and later, 1K through 4K, 8K, 16K, and 32K are valid.

warnings specifies whether warnings encountered during the restructure operation are displayed. Valid values are True or False. If warnings is set to True, warnings can be placed on the error stack for examination.

If errorTrapOnWarnings is set to True, the first warning generated terminates the restructure operation."

You should find something in this lot to help.

Regards,

Lewy
 
As Lewy has pointed out, there's lots of Help on the table.restructure() method.

However, I would give very serious thought to the desirability of doing this "on the fly".

What are your reasons for doing this ?
What are the risks ?
What are the hoped-for benefits ?

I would suggest that adding and removing fields in a table using SQL is as effective, and also that, as an empty table occupies only 2 KB, keeping all tables around, instead of altering them when you want some change, is a better and safer option.

Mike Irwin
 
We have a ten user client on our application software done in paradox 9. They have got a very unstable network. Every time there is a power failure while they are working, we get a table that is unable to open. We take the data and repair the table in paradox under tools, repair tables. Is there a function or a way in object pal that we can supply this user with this facility, so that they can repair their own tables?
 
Yes,

The table rebuild utility is a delivered form itself, TUTIL32.FDL for paradox 9. The following is from the FAQ that is on the corel newsgroup:

From Paradox 10 help files:
Paradox Runtime Developer Help |
Installing Paradox Runtime |
Overview:
Installing Paradox Runtime

<<<
In addition, you may also distribute the following files if
they are required by your application:

Table Repair Utility:

· TUTIL32.DLL
· TUTIL32.FDL
· TUWWR32.DLL
· TUTILITY.HLP

Copyright (c) Corel Corporation. 2001. All rights reserved.
>>>

In full Paradox 10, Tutil32.fdl is found in the Paradox
directory, tutil32.dll, and tuwwr32.dll in Programs directory.
The tutility.hlp and tutil32.hlp is not found anywhere but in
my Paradox 7 directories.

Paradox 10 documentation forgets to mention two more files
that are needed for Paradox 10, but not for previous versions
of Paradox, ExpertsSL.PXR and Expsrv01.LDL. Both are found
in the Experts directory.

You also need an alias named pdxExperts, which should be
created prior to opening the tutil32.fdl.

if not isdir("C:\\Program Files\\Corel\\Paradox 10
Runtime\\experts") then
makedir("C:\\Program Files\\Corel\\Paradox 10 Runtime\\experts")
endif
addalias("pdxExperts",
"standard",
"C:\\Program Files\\Corel\\Paradox 10 Runtime\\experts")

; here goes code for opening the form


This gives you the ability to put the table repair utiility into your app.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top