The InitCommands element define initialization commands that are executed just before the rest of the database profile is loaded. These commands are typically used to determine characteristics of the target database and database session. The result of these commands are stored in variables that can be used in conditions that are evaluated when the rest of the profile is loaded. A common use case is to find out the authorization level of the current user as defined in the database. If the user have limited privileges then some object types, views and actions should be disabled.
Multiple commands may be defined in the InitCommands element and these are executed in order.
The main purpose with the following sample and the commands is to first determine the database version by querying a system table. Based on the database version a condition controls which of two queries will be executed to find out another property from the database. The result of the executed query is stored in a the METACAT variable.
The extends="true" attribute specifies that the list of commands will extend the list of commands defined in the profile being extended.
Initialization commands are processed in two stages:
- First stage is to execute all commands having the attribute method="runBeforeConditionsEval" set. As the attribute reveal, these commands are execute before any conditions are evaluated,
- The second and last stage will execute all commands with no method="runBeforeConditionsEval" set. This time any conditions are evaluated.
The reason for these stages is that the processing of initialization commands may also rely on conditions.
Here is an example how the new METACAT variable is used in the rest of the database profile:
Here is another example for Oracle getting the instance_type property from the v$parameter table and put the value in the INSTANCE_TYPE variable.
Below show that only if INSTANCE_TYPE have the value RDBMS schema objects should be displayed in the database objects tree:
One more example showing the use of <OnError> and <Message> element <InitCommands>. Based on the database major version it runs one of two SQLs. If any 924 error (table not found) is raised the message will be logged in the DbVisualizer log. The
type="info" defines that the log entry should be logged without further notification. Leaving the type out or setting it to
type="warning" will also raise the error balloon in the DbVisualizer tool. Use this only when really necessary.