Пример #1
0
def connect(options,
            userInfoName='userInfo',
            dbnameName='dbname',
            nodeName='node',
            propName='connectProperties'):
    userInfo = getattr(options, userInfoName)
    dbname = getattr(options, dbnameName)
    node = getattr(options, nodeName)
    try:
        properties = getattr(options, propName)
    except AttributeError:
        properties = ''
    pos = string.find(userInfo, ',')
    if pos != -1:
        username = userInfo[:pos]
        pwd = userInfo[pos + 1:]
    else:
        username = userInfo
        pwd = ''
    if not node:
        pos = string.find(dbname, ':')
        if pos != -1:
            node = dbname[:pos]
            dbname = dbname[pos + 1:]
        else:
            node = ''
    import sapdb
    result = sapdb.connect(username, pwd, dbname, node, properties)
    return result
Пример #2
0
 def simpleSQL (self, cmd):
     try:
         user, pwd = self.getuser ()
         session = sapdb.connect (user, pwd, self.name, self.host)
         session.sql (cmd)
     except sapdb.SQLError, err:
         sys.stdout.write ("SQLError: [%d] %s\n"
             % (err.errorCode, err.message))
Пример #3
0
    def catalog (self, *words):
        """displays part of the sql catalog.

        Possible queries are:
            tables [<owner>.][<table>]
            table  [<owner>.]<table>
        """
        stmt = join (words)
        user, pwd = self.getDefaultUser ()
        session = sapdb.connect (user, pwd, self.name, self.host,
            'component=XCI&sqlmode=ORACLE')
        import sqlCatalog
        sqlCatalog.sqlCatalog (session, stmt)
Пример #4
0
 def layout (self, *words):
     """display the structure of a result set or a table
     """
     user, pwd = self.getDefaultUser ()
     session = sapdb.connect (user, pwd, self.name, self.host)
     withInOut = None
     if len (words) == 1:
         stmt = 'select * from ' + words [0]
         description = session.sql (stmt).getDescription ()
     else:
         prepared = session.prepare (join (words))
         description = prepared.getDescription ()
         if len (description) > 0:
             withInOut = 1
         else:
             description = prepared.execute ().getDescription ()
     self.dumpLayout (description, withInOut)
Пример #5
0
 def sql (self, *words):
     """execute SQL command"""
     try:
         user, pwd = self.getuser ()
         session = sapdb.connect (user, pwd, self.name, self.host,
             'component=XCI&sqlmode=ORACLE')
         import report
         options, stmt = report.parseWords (words)
         result = session.sql (stmt)
         if isinstance (result, sapdb.SapDB_ResultSet):
             report.doReport (result, options)
         elif type (result) == type (()):
             sys.stdout.write (`result` + '\n')
         else:
             sys.stdout.write ('OK\n')
         session.commit ()
     except sapdb.SQLError, err:
         sys.stdout.write ("SQLError: [%d] %s\n"
             % (err.errorCode, err.message))
Пример #6
0
 def sqlSession (self, userName = None, **config):
     user, pwd = self.getuser (userName)
     result = sapdb.connect (user, pwd, self.name, self.host,
         _buildConfig (config))
     return result