Entering content frame

This graphic is explained in the accompanying text Executing a DBM Command Locate the document in the library structure

In this example you use the cmd method of the sdb.sql module. You execute the DBM command db_enum (display list of all registered database instances) and format the output.

Procedure

...

       1.      Create a Python script sample.py with the following contents:

# Import Python modules

# ----------------------------

import sys

import sdb.dbm

#

# Call the Database Manager and log on to the database instance

# ------------------------------------------------------

session = sdb.dbm.DBM ()

# Execute DBM command db_enum (display list of all registered

# database instances)

# Result: character string

output = session.cmd ('db_enum')

dbstate = 'offline'

lastdb = ''

# Separate result with line breaks.

for line in output.split ('\n'):

    if not line:

        continue

    # Data fields are separated by tab characters.

    database_name, installation_path, version, kernel_variant, operational_state = line.split ('\t')

    if database_name != lastdb:

    # Several lines exist for each database instance,

    # one for each of the following kernel variants:

    # fast, slow and test.

        if lastdb != '':

            print lastdb, '\t', dbstate

        lastdb = database_name

        dbstate = 'offline'

    # The database is in operation if one of the kernel variants

    # is displayed as 'running'.

    if operational_state == 'running':

        dbstate = operational_state

print lastdb, '\t', dbstate

       2.      Call the Python script:

python sample.py

DEMODB  running

TESTDB  offline

See also:

Examples for the sdb.dbm Module

 

Leaving content frame