Entering content frame

This graphic is explained in the accompanying text Querying Whether a Table Exists Locate the document in the library structure

In this example you use the Loader class and the sql method of the sdb.loader module. You call the Loader, log on to a database instance and query whether a certain table exists.

Procedure

...

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

# Import Python modules

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

import sys

import sdb.loader

 

# Call Loader

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

session = sdb.loader.Loader ()

 

# Log on to the database instance

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

session.cmd ("USE USER MONA RED DB DEMODB")

 

# Query whether table HOTEL.CUSTOMER exists.

# If the table does not exist, the Loader returns

# an error.
# -------------------------------------

sqlrc = session.sql("EXISTS TABLE HOTEL.CUSTOMER")

if (sqlrc == 0):

    print 'Table HOTEL.CUSTOMER exists.'

elif (sqlrc == -4004):

    print 'Error -4004: Table HOTEL.CUSTOMER does not exist.'

 

# Close connection to the database instance
# -------------------------------------

session.release ()

 

       2.      Call the Python script:

python sample.py

See also:

Examples for the sdb.loader Module

 

Leaving content frame