Set up a user session
Log on to the database instance
Query whether table exists by querying the error code
Create a table without querying error code
Log off
# Reference to Python Libraries
# ----------------------------
import sys
import repman
# Parse the call arguments
# --------------------------
user = sys.argv [1]
pwd = sys.argv [2]
dbname = sys.argv [3]
data_path = sys.argv[4]
host = ''
# Connect to Replication Manager
# A new instance of the repman object is created
# Host determines the location of the REPMServer
# ------------------------------------------------------
session = repman.RepMan (host, dbname)
# Connect to database
# The cmd method is used for this purpose
# -------------------------------------
session.cmd ('use user %s %s;' % (user, pwd))
# Query error code to determine whether table exists
# The sql method is used for this purpose
# ----------------------------------------------------------
rc = session.sql("EXISTS TABLE CUSTOMER")
If rc!=0
# Then branch of the If statement must be indented in Python
# Create the table CUSTOMER
# ----------------------------------------------------------
session.cmd ( """CREATE TABLE CUSTOMER (
CNO FIXED(4),
SURNAME CHAR(10) ASCII,
ZIP CHAR(5) ASCII,
PLACE CHAR(12) ASCII,
PRIMARY KEY (CNO) """)
session.cmd ("COMMIT")
# Log off by releasing the instance
# -------------------------------------
del session