Change Account Name (OpenInsight Specific)
At 10 JAN 2001 07:33:11PM Barry Stevens wrote:
I am still looking for a routine to change the account name in attached files to the current OI account - need to because of problems with adding new indexes.
I have a Arev routine VOLTRNS that does this, but there are some areas I am not sure abouting in converting it to OI.
I could post it here if someone wants a go at converting it.
many thanks
Barry
At 10 JAN 2001 08:50PM WinWin/Revelation Technical Support wrote:
Barry-
Email it to Info@Revelation.com
We'll convert it, post it here.
Thanks-
Mike Ruane
At 10 JAN 2001 09:19PM Barry Stevens wrote:
Choice! - Will do
At 11 JAN 2001 05:43PM WinWin/Revelation Support wrote:
Barry
Converted the program to OI. Left the Copyright unchanged
Please let me know if it works.
bob
*
Subroutine Rename_Volume(Volume, Media, Account)
!
* Matthew Crozier 1 September 1990
* Copyright (C) Vernon Systems Ltd
*
* This program will change the Media name and/or the Account for the files
* in a volume - and will modify the index definitions for any indexed files
* in that volume, thus indexes will not have to be rebuilt when redefining a
* volume's Media or Account.
* No one should be attached to the volume while this routine is run. All
* files in the volume will be renamed to the target account.
*
* Permission is given for commercial and non-commercial use of this program
* by legitimate Revmedia subscribers. No warranty express or implied, no
* responsibility accepted.
*
* 01-11-2001 RJC WinWin Solutions, Inc. Converted to OpenInsight
!
Declare Subroutine Reduce, Set_Status
Declare Function Msg, Get_Status
$INSERT Msg_Equates
If Assigned(Volume) Else Volume='
If Assigned(Account) Else Account='
If Assigned(Media) Else Media='
Convert @LOWER.CASE To @UPPER.CASE In Volume
Convert @LOWER.CASE To @UPPER.CASE In Account
Parent=@WINDOW
If Len(Volume) Else
Def="Def=Rename Volume"Def=Source Volume?'Def=?'Def=RC"Volume=Msg(Parent, Def, '' , '' , '' )End
If Volume #
Then Gosub Read.params If Valid Then Gosub Change.media Read Index_Files From Revmedia, '%RECORDS%' Then Gosub Change.%records% End If Valid Then Gosub Rename.media.records If Valid Then Gosub Change_Index If Valid Then Gosub Finish End End Return
!
Read.params:
Valid=1
Call Alias_Table(Volume, 'SYSPROG' , 'REVMEDIA' , 'REVMEDIA$' )
If Get_Status() Then
x=Msg(@WINDOW, "Unable to alias the REVMEDIA table." , '' , '' , '' )Set_Status (0)Valid=0ReturnEnd
Open 'REVMEDIA$' To Revmedia Then
Readv Old.media From Revmedia, '%%REVMEDIA%%' , 2 THENIf Len(Media) ElseMedia=Old.mediaDef="Def=Rename Volume"Def=New Media Name?'Def=?'Def=RC"Def=MediaMedia=Msg(Parent, Def, '' , '' , '' )EndIf Media=' Then Media=Old.mediaEnd ElseValid=0EndEnd Else
x=Msg(Parent, 'REVMEDIA cannot be attached.|Program aborted.' , '' , '' , '' )Valid=0End
If Valid Then
If Len(Account) ElseAccount=@APPIDDef="Def=Rename Volume"Def=New Account?'Def=?'Def=RC"Def=AccountAccount=Msg(Parent, Def, '' , '' , '' )Is_Valid=( Len(Account) ] 0 )EndEnd
Return
!
Change.media:
Writev Media To Revmedia, 'REVMEDIA' , 2 else
x=Msg(Parent, 'Unable to Update Revmedia %%REVMEDIA%%' , '' , '' , '' )Valid=0End
Return
!
Change.%records%:
Fld.cnt=Count( Index_Files, @FM) + (Index_Files #
) For i=1 To Fld.cnt File.spec=Index_Files Old.account=Field( File.spec, '*' , 2) If Account # Old.account Then Index_Files=Fieldstore( File.spec, '*' , 2, 1, ACCOUNT) End Next i Write Index_Files To Revmedia, '%RECORDS%' Else x=Msg(Parent, 'Unable to Update Revmedia %RECORDS%' ,
,,
)Valid=0End
Return
!
Rename.media.records:
Def="
Def=Rename Volume'
Def=Renaming media records."
Def=U"
If Len(Parent) Then Msgup=Msg(Parent, Def);* display the processing message
Select Revmedia
Done=0
Loop
Readnext R.id ThenOld.account=Field( R.id, '*' , 2)If Account # Old.account And Old.account # '' ThenRead R.rec From Revmedia, R.id ThenDelete Revmedia, R.id Elsex=Msg(Parent, 'Unable to Delete Revmedia ' : Quote(R.id), '' , '' , '' )Valid=0EndR.id=Fieldstore( R.id, '*' , 2, 1, ACCOUNT)Write R.rec To Revmedia, R.id Elsex=Msg(Parent, 'Unable to Update Revmedia %RECORDS%' , '' , '' , '' )Valid=0EndEndEndEnd Else Done=1
Until Done
While Valid
Repeat
If Len(Parent) Then x=Msg(Parent, Msgup);* take down the processing message
Return
!
Change_Index:
Def="
Def=Rename Volume'
Def=Changing Index information."
Def=U"
If Len(Parent) Then Msgup=Msg(Parent, Def);* display the processing message
Flag='
Reduce( 'WITH {@ID} ] "!"' ,
, 0, 'REVMEDIA$' , 1, FLAG) If Flag Then Select 'REVMEDIA$' By
Using 1 ThenDone=0LoopReadnext Index_File Using 1 By AT ThenIndex_File=Index_File1, '*'Gosub Change_Index_FileEnd ElseDone=1EndUntil DoneWhile ValidRepeatEnd Elsex=Msg(Parent, 'Failure in SELECT.' , '' , '' , '' )Valid=0EndEnd Else
x=Msg(Parent, 'Failure in REDUCE.' , '' , '' , '' )Valid=0End
If Len(Parent) Then x=Msg(Parent, Msgup);* take down the processing message
Return
!
Change_Index_File:
Def="
Def=Rename Volume'
Def=Changing Index information|for file ' : Index_File
Def=U"
If Len(Parent) Then Msgup2=Msg(Parent, Def);* display the processing message
Data_File=Index_File2,65534
If TableExists(Data_File) Then
Call Detach_Table(Data_File)End
If TableExists(Index_File) Then
Call Detach_Table(Index_File)End
Call Attach_Table(Volume,Index_File,Account,
) If Get_Status()=0 Then Index_Attached_Name=Index_File End Else Call Alias_Table(Volume,Account,Index_File, Index_File ) If Get_Status()=0 Then Index_Attached_Name=INDEX_FILE$' End Else x=Msg(@WINDOW, 'Unable to alias the ' : Quote(Index_File ): ' table.' ,
,,
)Index_Attached_Name='Valid=0ReturnEndEnd
Open Index_Attached_Name To If.fv Then
Read Index.defn From If.fv, Index_File ThenHeader=Index.defnFile=Header1, '*'Header=File: '*' : Account: '*' : MediaIndex.defn=HeaderWrite Index.defn To If.fv, Index_File Elsex=Msg(Parent, 'Unable to Update Index definitions for ' :quote(Index_File), '' , '' , '' )Valid=0ReturnEndEndRead Index.sym From If.fv, '!' ThenWritev '' To If.fv, '!' , 8 elsex=Msg(Parent, 'Unable to Update Index_SYM' , '' , '' , '' )Valid=0ReturnEndEndClearselectCall Rlist( 'SELECT ' :index_Attached_Name ,5, '' , '' )If @RECCOUNT ThenEof=0LoopReadnext Indxkey Else Eof=1Until EofRead Indexrec From If.fv,Indxkey ThenSwap Old.account: "*" :old.media With Account: "*" :media In IndexrecWrite Indexrec To If.fv,Indxkey Elsex=Msg(Parent, 'Unable to Update Revmedia %RECORDS%' , '' , '' , '' )Valid=0ReturnEndEndRepeatEndCall Detach_Table( Index_Attached_Name )End Else
x=Msg(Parent, Index_File: ' cannot be attached!.' , '' , '' , '' )Valid=0End
If Len(Parent) Then x=Msg(Parent, Msgup2);* take down the processing message
Return
!
Finish:
Call Detach_Table( 'REVMEDIA$' )
Call Attach_Table(Volume,
,account,
)Return
At 11 JAN 2001 09:09PM Barry Stevens wrote:
Great, It works fine. Thank you very very much.
WARNING - IT MUST BE RUN FROM THE SYSTEM MONITOR TO WORK PROPERLY
Barry
At 11 JAN 2001 09:52PM Barry Stevens wrote:
I have just logged out of the application and then back in, and when I look at the "list of indexed table" or try to update, its says there are no indexed tables.
Could you please test and verify, and fix.
Thanks
Barry
At 11 JAN 2001 10:14PM Barry Stevens wrote:
The database definition has to be saved, so replace the last paragraph with this:
!
Finish:
Call Detach_Table( 'REVMEDIA$' )Call Attach_Table(Volume,'',account,'')call Define_Database(account, 1, "", "")Return
Barry
At 12 JAN 2001 05:06AM Oystein Reigem wrote:
Barry/Bob/Mike,
Thanks for that useful piece of code! In my work I've never needed to change the account name but often the volume label. I had a RenameVolume subroutine from earlier, but I never got it to save the database definition. Off to the Old Procedures Resting Home with that!
Barry - when you say the subroutine must be run from the System Monitor it's only because of the Msg calls, right? It seems to run OK from an OI form, but of course not from the System Editor.
(In my own version of your routine I've added a few Utility('CURSOR', 'H') calls to set an hourglass cursor. That's because saving the database definition takes some time, and when you run the subroutine from a form nothing tells you it's still processing. When running from the System Monitor you see from the "Getting Remove List" and "Get Add List" lines that something's going on and the hourglass isn't really necessary. - I have one Utility call around the beginning, and one after most of the Msg calls, since Msg resets the cursor to arrow.)
- Oystein -
At 14 JAN 2001 09:25PM Barry Stevens wrote:
]]Barry - when you say the subroutine must be run from the System Monitor it's only because of the Msg calls, right? It seems to run OK from an OI form, but of course not from the System Editor.«
Correct
At 15 JAN 2001 05:04AM Barry Stevens wrote:
Reletaional indexes dont appear to be working….have to delete\add index.
Could you look into please
Barry
At 15 JAN 2001 05:33AM Barry Stevens wrote:
Cant delete \add index:
delete index then add - still have to remove spome index info from dict.
Add - doesnt rebuildAdding records doesnt add
Please Help
At 15 JAN 2001 02:52PM WinWin/Revelation Support wrote:
Barry:
Will investigate. In translating I focused on syntax changes (trees) rather than core functionality (forest)
I probably need to make program detach each table, save database, then re-attach each table, save database again.
In the meantime:
1. re: Indexes not listing
If you run LIST_INDEX from the system monitor do you get error messages? In the past I have found that system monitor gives messages that the screen does not.2. re: need to delete / add information.
delete / add using menu ordid you need to edit dict records or the ! file ?3. re: Add does not rebuild
btree and relational or relational only?Bob
At 16 JAN 2001 01:52AM Barry Stevens wrote:
The !IndexedField in !file is not being converted. The Old names appear to be the new names by the time it gets there.
Barry
At 16 JAN 2001 02:48AM Barry Stevens wrote:
Here is the section of code.
I have noted the spot where the error is.
!
Change_Index_File:
Def="Def=Rename Volume'Def=Changing Index information|for file ' : Index_FileDef=U"If Len(Parent) Then Msgup2=Msg(Parent, Def);* display the processing messageData_File=Index_File2,65534If TableExists(Data_File) ThenCall Detach_Table(Data_File)EndIf TableExists(Index_File) ThenCall Detach_Table(Index_File)EndCall Attach_Table(Volume,Index_File,Account, '' )If Get_Status()=0 ThenIndex_Attached_Name=Index_FileEnd ElseCall Alias_Table(Volume,Account,Index_File, Index_File )If Get_Status()=0 ThenIndex_Attached_Name=INDEX_FILE$'End Elsex=Msg(@WINDOW, 'Unable to alias the ' : Quote(Index_File ): ' table.' , '' , '' , '' )Index_Attached_Name='Valid=0ReturnEndEndOpen Index_Attached_Name To If.fv ThenRead Index.defn From If.fv, Index_File ThenHeader=Index.defnFile=Header1, '*'Header=File: '*' : Account: '*' : MediaIndex.defn=HeaderWrite Index.defn To If.fv, Index_File Elsex=Msg(Parent, 'Unable to Update Index definitions for ' :quote(Index_File), '' , '' , '' )Valid=0ReturnEndEndRead Index.sym From If.fv, '!' ThenWritev '' To If.fv, '!' , 8 elsex=Msg(Parent, 'Unable to Update Index_SYM' , '' , '' , '' )Valid=0ReturnEndEndClearselectCall Rlist( 'SELECT ' :index_Attached_Name ,5, '' , '' )If @RECCOUNT ThenEof=0LoopReadnext Indxkey Else Eof=1Until EofRead Indexrec From If.fv,Indxkey Then
*
AT THIS POINT OLD.ACCOUNT is the same as ACCOUNT*««—ERROR HERE BJS
*Swap Old.account: "*" :old.media With Account: "*" :media In IndexrecWrite Indexrec To If.fv,Indxkey Elsex=Msg(Parent, 'Unable to Update Revmedia %RECORDS%' , '' , '' , '' )Valid=0ReturnEndEndRepeatEndCall Detach_Table( Index_Attached_Name )End Elsex=Msg(Parent, Index_File: ' cannot be attached!.' , '' , '' , '' )Valid=0EndIf Len(Parent) Then x=Msg(Parent, Msgup2);* take down the processing messageReturn
At 16 JAN 2001 08:26AM Bob Carten wrote:
Thanks Barry.