Skip Top Menu Navigation
Skip Top Menu Navigation

The FREE Enterprise Open Source Database

  Software Documentation Tools Interfaces Administration Development
 

 
You Are Here:    SAP DB > Interfaces > sapdb.loader > Example

SAP DB is now SAP MaxDB! For more information, visit the SAP MaxDB pages in the SAP Developer Network.

Module sapdb.loader (Example)

#
# egLoader.py   call as
#        python egLoader.py <user> <pwd> <db> [<host>]
#

import sys
import sapdb.loader

user = sys.argv [1]
pwd = sys.argv [2]
dbname = sys.argv [3]
try:
    host = sys.argv [4]
except IndexError:
    host = 'localhost'

# connect to db
session = sapdb.loader.Loader (host, dbname)

# execute simple command
print 'Version:', session.cmd ('version')

# connect
session.cmd ('use user %s %s' % (user, pwd))
print 'connected'

# create a table and drop it
for cmd in ['create table loadtest (a char (10))',
        'drop table loadtest']:
    print cmd,
    session.cmd (cmd)
    print '-> ok'

# demonstrate exception handling
try:
    result = session.cmd ('complete nonsense')
    print "'%s'" % result
except sapdb.loader.LoaderError, err:
    print 'command failed:', err

# demonstrate sql method
cmd = 'complete nonsense'
rc = session.sql (cmd)
print cmd, '->', rc;

session = None



Search / Contact Info
See also ...












Questions or comments about the Web site? Contact the webmaster.