Script 1 loops through all of the table in a database and stores the index definitions in a text file on disk. The text file is the same as the Database name but it has a ".TableInformation" extension.
'get a list of all tables
dim tables as c
tables = a5.Table_Enum()
dim td as p
'create an array to hold the index information for each table
dim count as n
count = line_count(tables)
dim td.TableInfo[count] as p
'initialize the array
td.TableInfo.initialize_properties("TableName",tables)
'put up a progress dialog box.
DIM pDlg1 as {waitdialog}
pDlg1.Create(3,"Percent")
pDlg1.Set_Title("Please Wait")
pDlg1.Set_Message("Storing index information. Please wait...")
dim i as n
dim table_i as c
dim indexInfo_i as c
dim sourceType_i as c
for i = 1 to count
table_i = td.TableInfo[i].tablename
'check the table type - we don't want to bother with shadow
or linked tables - only care about Native tables
sourceType_i =
table.get_source_type(table.filename_get(table_i))
td.TableInfo[i].sourceType = sourceType_i
pDlg1.Set_Bottom_Message(table_i)
if sourceType_i = "Native" then
td.TableInfo[i].indexDefinitions =
get_index_definitions(table_i)
else
td.TableInfo[i].indexDefinitions = ""
end if
next i
'close the progress dialog
pDlg1.close()
dim fn as c
fn = file.filename_parse(a5.Get_Name(),"dpn") + ".TableInformation"
'save the variable that contains the information to the file on disk.
'before you can save the variable, you have to convert it to a string value
'using property_to_string()
save_to_file(property_to_string(td),fn)
Script 2 is used to check the indexes in the tables against the saved index definitions:
dim fn as c
fn = file.filename_parse(a5.Get_Name(),"dpn") + ".TableInformation"
if file.exists(fn) = .f. then
ui_msg_box("Error","Saved index information file not found.")
goto skip
end if
dim txt as c
txt = get_from_file(fn)
dim td as p
'restore the array that contains the index information from the information
stored on disk.
property_from_string(td,txt)
dim i as n
dim count as n
count = td.TableInfo.first_empty()-1
'put up a progress dialog box.
DIM pDlg1 as {waitdialog}
pDlg1.Create(3,"Percent")
pDlg1.Set_Title("Please Wait")
pDlg1.Set_Message("Checking indexes. Please wait...")
dim tablesWithErrors as c = ""
dim index_info_i as c
dim table_i as c
dim p as p
for i = 1 to count
index_info_i = td.TableInfo[i].indexDefinitions
table_i = td.TableInfo[i].tablename
pDlg1.Set_Bottom_Message(table_i)
'only restore indexes if the table type is a native table
if td.TableInfo[i].sourceType = "Native" then
P = indexes_match_defstring(table_i ,
index_info_i)
if p.missingIndexTags <> "" then
tablesWithErrors = tablesWithErrors + table_i + crlf()
Create_Indexes(table_i,index_info_i)
end if
end if
next i
'close the progress dialog
pDlg1.close()
if tablesWithErrors <> "" then
ui_msg_box("Notice","Missing indexes were re-created in the
following tables: " + crlf()+ tablesWithErrors)
else
ui_msg_box("Notice","No missing indexes were found")
end if
skip: