In this example you use the Loader class and the cmd method of the sdb.loader module. You call the Loader, log on to a database instance and export a table.
...
1. Create a Python script sample.py with the following contents:
# Import Python modules
# -------------------------------------------
import os
import sys
import sdb.loader
# Determine home directory
# -------------------------------------------
homedir = None
if sys.platform[:3] in ['win']:
homedir= os.path.join(os.getenv ('HOMEDRIVE'), os.getenv ('HOMEPATH' ))
else:
homedir = os.getenv ('HOME')
# Call Loader
# -------------------------------------------
session = sdb.loader.Loader ()
# Log on to the database instance
# -------------------------------------------
session.cmd ("USE USER MONA RED DB DEMODB")
# Execute Loader command (export)
# -------------------------------------------
catalogstream = "CATALOG OUTSTREAM '%s' " % os.path.join(homedir, 'room_ddl.catalog')
datastream = "DATA OUTSTREAM '%s' " % os.path.join(homedir, 'room_csv.data')
cmd = "EXPORT TABLE HOTEL.ROOM %s %s " % (catalogstream,datastream)
session.cmd (cmd)
# Close connection to the database instance
# -------------------------------------------
session.release ()
2. Call the Python script:
python sample.py
The database catalog data and the application data in table HOTEL.ROOM have been exported to the output files room_ddl.catalog and room_csv.data in the home directory of the operating system user currently logged on.
See also:
Examples for the sdb.loader Module