Re: Indexes removed and renamed
Stan, here is a function I use that will recreate indexes from a table called zindexes I use that has the definitions in a memo field. It tells the user which ones could not be rebuilt/recreated as the tables were in use.
'Date Created: 26-Feb-2011 12:57:48 PM
'Last Updated: 23-Apr-2015 01:09:02 PM
'Created By : martin cole
'Updated By : MARTIN
function indexes_rebuild as L ()
time1=toseconds(time())
on error goto errors
if alltrim(var->masterpassword)=""
end
end if
dim shared is_shadowed as l
if a5.get_master_path() > ""
is_shadowed=.t.
else
is_shadowed=.f.
end if
if is_shadowed=.t.
mpath=a5.get_master_path() + chr(92)
end if
temp=""
datapath = a5.get_path() + chr(92)
dim tp as p
t1=toseconds(time())
t=table.open("zindexes")
n=t.records_get()
m=0
DIM GLOBAL pDlg1 as waitdialog
pDlg1.Set_Title("Please Wait")
pDlg1.Create(1,"Bounce")
pDlg1.Set_Message("Processing Please Wait")
pDlg1.Set_Bottom_Message("")
t.fetch_first()
while .not. t.fetch_eof()
lastuse=toseconds(time())
m=m + 1
pDlg1.Set_Bottom_Message("Processing " + alltrim(str(m)) + " of " + alltrim(str(n)))
temp1=alltrim(t.Tablename)
temp2=alltrim(t.Indexnames)
if table.in_use(temp1)
if temp1="zindexes" .or. temp1="menu"
else
temp=temp + f_upper(temp1) + crlf()
end if
goto next1
end if
tp=create_indexes(temp1,temp2)
ui_yield()
if tp.haserror
temp=temp + f_upper(temp1) + crlf()
end if
if is_shadowed=.t.
file.copy(datapath + temp1 + ".cdx", mpath + temp1 + ".cdx")
file.remove(datapath + temp1 + ".cdx")
ui_yield()
end if
next1:
t.fetch_next()
end while
t.close()
pdlg1.close()
t2=toseconds(time())
t3=t2-t1
if temp=""
time2=toseconds(time())
textindexes.text="Finished - all indexes rebuilt."
ui_beep(UI_CRITICAL_BEEP); ui_yield(); ui_beep(UI_CRITICAL_BEEP)
else
time2=toseconds(time())
ui_beep(UI_CRITICAL_BEEP); ui_yield();ui_beep(UI_CRITICAL_BEEP)
msgbox("Note","" + crlf() + "The following tables were in use and could not be updated:" + crlf() + alltrim(temp) + crlf()\
+ "Find out who is using these files, and ask them to go back to the main menu for about a minute while you "\
+ "rebuild the indexes!",48)
end if
indexes_rebuild=.t.
if a5.Get_Master_Path() > ""
dim temp as c
temp3="hasteststemp,hashydrogentemps,cscreen"
for i=1 to w_count(temp3,",")
temp4=word(temp3,i,",")
mpath=a5.Get_Master_Path()
files=filefind.first(mpath + chr(92) + temp4 + ".*")
WHILE .not. files.eof()
temp=files.name()
temp2=file.filename_parse(temp,"ne")
file.copy(temp,a5.get_path() + chr(92) + temp2)
files.next()
END WHILE
next
end if
time2=toseconds(time())
time3=time2-time1
msgbox("Note","This took " + alltrim(str(time3)) + " seconds.")
end
errors:
indexes_rebuild=.f.
err_msg = error_text_get(error_code_get())
line = error_line_number_get()
script = error_script_get()
ui_msg_box("Error", err_msg+" Error occurred at line "+alltrim(str(line,4,0))+ " in script: "+script)
end
isopen:
temp=temp + f_upper(temp1) + crlf()
1=1
goto next1
end
end function
Stan, here is a function I use that will recreate indexes from a table called zindexes I use that has the definitions in a memo field. It tells the user which ones could not be rebuilt/recreated as the tables were in use.
'Date Created: 26-Feb-2011 12:57:48 PM
'Last Updated: 23-Apr-2015 01:09:02 PM
'Created By : martin cole
'Updated By : MARTIN
function indexes_rebuild as L ()
time1=toseconds(time())
on error goto errors
if alltrim(var->masterpassword)=""
end
end if
dim shared is_shadowed as l
if a5.get_master_path() > ""
is_shadowed=.t.
else
is_shadowed=.f.
end if
if is_shadowed=.t.
mpath=a5.get_master_path() + chr(92)
end if
temp=""
datapath = a5.get_path() + chr(92)
dim tp as p
t1=toseconds(time())
t=table.open("zindexes")
n=t.records_get()
m=0
DIM GLOBAL pDlg1 as waitdialog
pDlg1.Set_Title("Please Wait")
pDlg1.Create(1,"Bounce")
pDlg1.Set_Message("Processing Please Wait")
pDlg1.Set_Bottom_Message("")
t.fetch_first()
while .not. t.fetch_eof()
lastuse=toseconds(time())
m=m + 1
pDlg1.Set_Bottom_Message("Processing " + alltrim(str(m)) + " of " + alltrim(str(n)))
temp1=alltrim(t.Tablename)
temp2=alltrim(t.Indexnames)
if table.in_use(temp1)
if temp1="zindexes" .or. temp1="menu"
else
temp=temp + f_upper(temp1) + crlf()
end if
goto next1
end if
tp=create_indexes(temp1,temp2)
ui_yield()
if tp.haserror
temp=temp + f_upper(temp1) + crlf()
end if
if is_shadowed=.t.
file.copy(datapath + temp1 + ".cdx", mpath + temp1 + ".cdx")
file.remove(datapath + temp1 + ".cdx")
ui_yield()
end if
next1:
t.fetch_next()
end while
t.close()
pdlg1.close()
t2=toseconds(time())
t3=t2-t1
if temp=""
time2=toseconds(time())
textindexes.text="Finished - all indexes rebuilt."
ui_beep(UI_CRITICAL_BEEP); ui_yield(); ui_beep(UI_CRITICAL_BEEP)
else
time2=toseconds(time())
ui_beep(UI_CRITICAL_BEEP); ui_yield();ui_beep(UI_CRITICAL_BEEP)
msgbox("Note","" + crlf() + "The following tables were in use and could not be updated:" + crlf() + alltrim(temp) + crlf()\
+ "Find out who is using these files, and ask them to go back to the main menu for about a minute while you "\
+ "rebuild the indexes!",48)
end if
indexes_rebuild=.t.
if a5.Get_Master_Path() > ""
dim temp as c
temp3="hasteststemp,hashydrogentemps,cscreen"
for i=1 to w_count(temp3,",")
temp4=word(temp3,i,",")
mpath=a5.Get_Master_Path()
files=filefind.first(mpath + chr(92) + temp4 + ".*")
WHILE .not. files.eof()
temp=files.name()
temp2=file.filename_parse(temp,"ne")
file.copy(temp,a5.get_path() + chr(92) + temp2)
files.next()
END WHILE
next
end if
time2=toseconds(time())
time3=time2-time1
msgbox("Note","This took " + alltrim(str(time3)) + " seconds.")
end
errors:
indexes_rebuild=.f.
err_msg = error_text_get(error_code_get())
line = error_line_number_get()
script = error_script_get()
ui_msg_box("Error", err_msg+" Error occurred at line "+alltrim(str(line,4,0))+ " in script: "+script)
end
isopen:
temp=temp + f_upper(temp1) + crlf()
1=1
goto next1
end
end function
Comment