Dynamic Database Switching: Difference between revisions
m
adding
m (formatting) |
m (adding) |
||
Line 126: | Line 126: | ||
Object oDbSwitcher is a cDbSwitcher | Object oDbSwitcher is a cDbSwitcher | ||
End_Object // oDbSwitcher | End_Object // oDbSwitcher | ||
</source> | |||
This object should then be used in each program which will require this functionality, ideally near the top of the source file, before any tables get opened. | |||
===DataDictionary Sub-Class=== | |||
We then need to define which tables will be "customer" tables - that is the ones which will exist as different versions in different databases. To do this it is most convenient to have a subclass of the Data Access DataDictionary class, eith just in the workspace, or in a library workspace if it is to be used in more than one project (placed in the AppSrc directory it either case). In this we will: | |||
* Create a property in Construct_Object | |||
* Augment End_Construct_Object to "register" the table if required. | |||
<source lang="vdf"> | |||
Use DataDict.pkg | |||
// We want to should ensure that the global handle is defined, so that this | |||
// class will work even if the database switch object is not in use. | |||
#IFDEF ghoDbSwitch | |||
#ELSE | |||
Global_Variable Handle ghoDbSwitch | |||
Move 0 to ghoDbSwitch // Initalise to zero | |||
#ENDIF | |||
// Register the procedure we are (maybe) going to call, so calss will work in | |||
// all cases. | |||
Register_Procedure AddCustomerTable Integer iTab | |||
Class cMyDataDictionary is a DataDictionary | |||
Procedure Construct_Object | |||
Forward Send Construct_Object | |||
Property Boolean pbCustomerTable Public False | |||
End_Procedure // Construct_Object | |||
Procedure End_Construct_Object | |||
Forward Send End_Construct_Object | |||
// IF this is a customer table AND we have the switcher object: | |||
If (pbCustomerTable(Self) and (ghoDbSwitch <> 0)) ; | |||
Send AddCustomerTable of ghoDbSwitch (Main_File(Self)) | |||
End_Procedure // End_Construct_Object | |||
End_Class // cMyDataDictionary | |||
</source> | </source> |