Only in DbVisualizer Pro
This document and the Database Profile Framework in general is appropriate only when using the licensed DbVisualizer Pro edition.
Conditional processing simply means that a profile can adjust its content based on certain conditions. A few examples:
- Which version of the database is being accessed
- The format of the database URL
- The client environment i.e Java version, vendor, etc.
- User properties
- Database connection properties
Conditional processing is especially useful when adapting the profile for different versions of the database (and/or JDBC driver). Another use is to replace generic error messages with more user friendly messages.
If you have some programming skills conditions are expressed using If, Elseif and Else statements.
There are two phases when conditions are processed:
- Conditional processing when database connection is established
If, ElseIf and Else elements can be specified almost everywhere in the profile
- Conditional processing during command execution
The OnError element is used to define a message that will appear in DbVisualizer if a command fails. Conditions are used to control what message should appear
DbVisualizer uses the type attribute to determine which If elements should be executed in which of the two phases. If this attribute is set to the value runtime, it will be processed in the second phase. If it is not specified, it will be processed in the first phase.
Conditional processing when database connection is established
These are the call signatures for the utilities used when processing conditions:
The following example shows the use of conditions that are processed during connect of the database connection.
The above means that if the major version of the database being accessed is less than or equal to 5, the first SQL is used. If the major version is equal to 9, the second SQL is used, and the last SQL is used for all other versions. The test attribute may contain conditions that are ANDed or ORed. Conditions can contain multiple evaluations, combined using parenthesis. The If, ElseIf and Else elements may be placed anywhere in the XML file.
Here is another example that controls whether certain nodes will appear in the database objects tree or not.
As you can see, this example contains nested uses of If.
Conditional processing during command execution
Using conditional processing to evaluate any errors from a Command may be useful to rephrase error messages to be more user friendly.
The OnError element can be used in Commands and Command elements. If used in Commands element, its conditions are processed for all its commands. If it's part of a specific Command, it is processed only for that command.
The drop-on-condition attribute is processed during profile load and may have the constant value "always" or a boolean statement that is evaluated. This attribute is valid for the following XML elements:
This will drop the element if the database version is less than 4.1:
This will drop the element unconditionally which is useful in a sub profile needing to for example drop a parent DataView defined in the same ObjectView:
If you are looking to drop for example the parent ObjectView and all its DataView elements, and then add a replacement for the ObjectView in the sub profile, you need to drop each of the DataView elements in the sub profile rather than first doing a drop of the parent ObjectView and then re-define it in the sub profile. Here is an example that will not work resulting that both ObjectView="Procedures" definitions will be removed:
Instead you need to override the ObjectView and in it, drop the DataView:
The same apply for all elements supporting the drop-on-condition attribute.