Python: Example No. 5 

If a command is changed at runtime, for example, because user inputs are part of the command, syntax errors can easily occur.
The SQL method only provides SQL error codes. You need exceptions to intercept syntax errors or other REPMServer errors in the
REPMServer commands.

Set up a user session
Log on to the database instance
Use REPMServer command(s) to load data into table and intercept exceptions
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))

 

# Example of exception handling

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

try:

loadrc = session.sql ("""DATALOAD TABLE customer

cno 1-4

surname 6-12

zip 14-18

place 20-31

INFILE %s\customer.dat""" %data_path )

print "'%s'" % loadrc

except repman.RepManServError, err:

print 'command failed:', err

 

# Log off by releasing the instance

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

del session