OnFinish;
The OnFinish method implements an event that takes place after the execution of whole script.
Executing the example requires the ORCL server named Test. Platform repository was created within the TestSchema scheme on the server. The root of disk C contains the current.rm4 file that includes the script for repository creating and updating.
Sub Main;
Var
Rsm: IRepositoryScriptManager;
Driv: IDalDriver;
ConDesc: IDalConnectionDescriptor;
Params: IDalConnectionDescriptorParams;
Con: IDalConnection;
CallBack: IRepositoryScriptCallback;
Begin
//Connection to the scheme on the ORCL server
Driv := New DalOrclDriver.Create As IDalDriver;
ConDesc := Driv.CreateDescriptor;
Params := ConDesc.Params;
Params.Find("User Name").Value := "TestSchema";
Params.Find("Password").Value := "TestSchema";
Params.Find("Host BSTR").Value := "Test";
Params.Find("Scheme").Value := "TestSchema";
Con := ConDesc.CreateConnection;
//Settings of the repository manager
Rsm := New RepositoryScriptManager.Create;
Rsm.Connection := Con;
Rsm.Driver := RepositoryDriverType.ORCL;
Rsm.Operation := RepositoryOperationType.Update;
//Repository updating
Rsm.Repository := RepositoryType.Metabase;
Rsm.LoadScript(New FileStream.Create("c:\current.rm4", FileOpenMode.Read, FileShare.Exclusive));
CallBack := New ScrCallback.Create;
Rsm.Execute(CallBack);
End Sub Main;
Class ScrCallback: RepositoryScriptCallback
s: String;
Public Sub OnStart(Error: RepsitoryScriptInitError; FilesToProcess: Integer);
Begin
Debug.WriteLine("Start of updating");
Select Case Error
Case RepsitoryScriptInitError.None:
Debug.WriteLine("Number of queries that will be executed: " + FilesToProcess.ToString);
Case RepsitoryScriptInitError.NoTables:
Debug.WriteLine("There are no repository tables in the specified base");
Case RepsitoryScriptInitError.TablesAlreadyExist:
Debug.WriteLine("There are already repository tables in the specified base");
Case RepsitoryScriptInitError.EmptyRepository:
Debug.WriteLine(Empty repository for updating");
Case RepsitoryScriptInitError.CannotUpdateVers:
Debug.WriteLine("Repository version can not be updated");
Case RepsitoryScriptInitError.UnicodeMismatch:
Debug.WriteLine("Unicode of the repository version does not coincide in the base and in the file");
End Select;
End Sub OnStart;
Public Sub BeginStatement(Statement: String);
Begin
s := Statement;
End Sub BeginStatement;
Public Sub EndStatement(bError: Boolean; Message: String; Var Cancel: Boolean);
Begin
If bError = True Then
Debug.WriteLine("Error occurs when executing the code!");
Debug.Indent;
Debug.WriteLine("Query: " + s);
Debug.WriteLine("Error: " + Message);
Debug.Unindent;
Cancel := False;
End If;
End Sub EndStatement;
Public Sub OnFinish;
Begin
Debug.WriteLine("Updating is completed");
End Sub OnFinish;
End Class ScrCallback;
After executing the example the repository version is updated in accordance with the contents of the current.rm4 file. The ScrCallback custom class is used to track the process of update. Information about readiness for updating and about errors that can occur when executing the queries is displayed in the development environment console.
See also: