Dynamic Database Switching: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
m
Formatting
(Creating)
 
m (Formatting)
Line 1: Line 1:
=Dynamic Database Switching=
For some kinds of system - typically those which provide the same service to a number of different customer organisations - there may be a need to maintain multiple versions of ''some'' of the database tables, held within the same database server instance.
For some kinds of system - typically those which provide the same service to a number of different customer organisations - there may be a need to maintain multiple versions of ''some'' of the database tables, held within the same database server instance.


Line 24: Line 22:
===The Database Switching Object===
===The Database Switching Object===


<code lang="vdf">
<source lang="vdf">
Use MerTech.inc
Use MerTech.inc
 
Define C_InitialDB for "defaultDB"  // This will be used for the tables to be  
Define C_InitialDB for "defaultDB"  // This will be used for the tables to be  
                                     // initially opened in and for global tables
                                     // initially opened in and for global tables
 
// We define a global handle for the object which will handle the switching.
// We define a global handle for the object which will handle the switching.
// We do this conditionally in case something else (see below) also defines it.
// We do this conditionally in case something else (see below) also defines it.
Line 36: Line 34:
   Global_Variable Handle ghoDbSwitch
   Global_Variable Handle ghoDbSwitch
#ENDIF
#ENDIF
 
// We use the special Mertech command "Set_Database_Name" to establish the default
// We use the special Mertech command "Set_Database_Name" to establish the default
// database as the one to initially open tables in:
// database as the one to initially open tables in:
Set_Database_Name to C_InitialDB
Set_Database_Name to C_InitialDB
 
// Define the class we are going to make an object of.  This *could* be done
// Define the class we are going to make an object of.  This *could* be done
// directly in the object, but this way is "cleaner".
// directly in the object, but this way is "cleaner".
Line 59: Line 57:
       Function_Return sDB
       Function_Return sDB
   End_Function  // psCurrentDatabase
   End_Function  // psCurrentDatabase
 
   // Opens the "customer" tables
   // Opens the "customer" tables
   Procedure OpenCustomerTables
   Procedure OpenCustomerTables
Line 98: Line 96:
       Set_Database_Name to sDB
       Set_Database_Name to sDB
       Send OpenCustomerTables
       Send OpenCustomerTables
      //Set psCurrentDatabase to sDB
   End_Procedure
   End_Procedure
    
    
Line 124: Line 121:
    
    
End_Class  // cDbSwitcher
End_Class  // cDbSwitcher
 
// Create an instance of the class:
// Create an instance of the class:
Object oDbSwitcher is a cDbSwitcher
Object oDbSwitcher is a cDbSwitcher
End_Object  // oDbSwitcher
End_Object  // oDbSwitcher
</code>
</source>

Navigation menu