|
Problem |
These WSCP commands can be used to pull the databaseName
subattribute from the ConfigProperties attribute on a DataSource
object. |
|
Solution |
Suppose you wanted to query the actual database name that
a data source is using. One way to do this would be to use WSCP. The
problem that arises is the fact that the databaseName attribute is
actually a part of the ConfigProperties attribute, so a simple
"-attribute" tag on the "DataSource show" command will not be enough. The
following commands are an example of what you could do to obtain the
database name.
The first 2 steps are only necessary to make this example clearer. The
real work is done in the final 2 steps. Commands begin with the "wscp>"
prompt and results are on a following line.
1. Showing our datasource.
wscp> DataSource show {/JDBCDriver:Sample DB
Driver/DataSource:SampleDataSource/}
{Name SampleDataSource} {FullName {/JDBCDriver:Sample DB
Driver/DataSource:SampleDataSource/}} {Description {Example Data Source}}
{ConfigProperties {{serverName {}} {ifxIFXHOST {}} {user db2inst1}
{informixLockModeWait {}} {databaseName WAS40} {URL {}} {disable2Phase
true} {password *****} {portNumber {}}}} {ConnTimeout 180}
{DisableAutoConnectionCleanup False} {IdleTimeout 1800} {JNDIName
jdbc/SampleDataSource} {MaxPoolSize 10} {MinPoolSize 1} {OrphanTimeout
1800} {StatementCacheSize 100}
2. Showing that the databaseName is indeed part of the ConfigProperties
attribute.
wscp> DataSource show {/JDBCDriver:Sample DB
Driver/DataSource:SampleDataSource/} -attribute ConfigProperties
{ConfigProperties {{serverName {}} {ifxIFXHOST {}} {user db2inst1}
{informixLockModeWait {}} {databaseName WAS40} {URL {}} {disable2Phase
true} {password *****} {portNumber {}}}}
3. Setting a variable "z" to make the next command easier to read.
wscp> set z [DataSource show {/JDBCDriver:Sample DB
Driver/DataSource:SampleDataSource/} -attribute ConfigProperties]
{ConfigProperties {{serverName {}} {ifxIFXHOST {}} {user db2inst1}
{informixLockModeWait {}} {databaseName WAS40} {URL {}} {disable2Phase
true} {password *****} {portNumber {}}}}
4. Split the variable just set up on both types of curly brackets and on
the space character. Since the actual database name will follow the
"databaseName" label, we use a mathematical expression to calculate the
appropriate index value to pull
wscp> lindex [split $z "{} "] [expr 1 + [lsearch [split $z "{} "]
databaseName]]
WAS40
|
|
|
|
|
|
|