Esempio n. 1
0
def _parseDS(node):
     
    s  = {'CONFIG_DB': None,
          'DB_DRIVER'  : None}
        
    for elem in node:
        for e in elem:
            
            if e.tag != 'DS_Driver' : continue
            
            u = None; p = None; dsn = None; t = None 
            if e.get('status') =='1':
                t = e.get('type')
                if t is None or len (ST.strip(t)) < 1: continue
                mg.logger.info("Status is one for DS_DRIVER type = %s" % t)

                for x in e:
                    if x.tag == 'uname' : u = ST.strip(x.text)
                    if x.tag == 'pwd'   : p = ST.strip(x.text)
                    if ST.upper(x.tag) == 'DS_STR' : dsn = ST.strip(x.text)
                     
                # get Connect String                     
                if dsn is None or len (dsn) < 1: 
                    mg.logger.error (" %s DSN is null or blank" % e.get('name'))
                    continue
                
                mg.logger.debug("Invoking getDSConnStr t = %s ,u = %s ,p = %s ,dsn = %s " % (t,u,p,dsn))
                return {'CONFIG_DB': ds.getDSConnStr(t, u, p, dsn),
                        'DB_DRIVER'   : t
                        }                    
    return s
Esempio n. 2
0
 def _connToDB(self, dbEng):
     cs = getDSConnStr(dbEng, self.ib.user, self.ib.pwd, self.ib.dbserver, self.ib.db)
     self.dbh = NZODBC(cs, self.log)
     rc = self.dbh.connToDB () 
     if rc != 0 : 
         self.log.error('Could not connect to the DB rc = %s ' % rc)
         return 1
     return rc
Esempio n. 3
0
def _getNZDS(sql, ib, log):
    r = []
    print('qry = %s' % sql)
    cs = getDSConnStr('NZODBC', ib.user, ib.pwd, ib.dbserver, ib.db)
    dbh = NZODBC(cs, log)
    if dbh.connToDB() != 0: return r
    r = dbh.runQry(sql)
    dbh.closeDBConn()
    return r
Esempio n. 4
0
 def _getDB2CliDS(self, sql,bv=[], po='SEL'):
     self.log.debug('qry = %s' % sql)
     cs = getDSConnStr('DB2CLI', self.ib.user, self.ib.pwd, self.ib.dsn, self.ib.db)
     dbh = DBOracle(cs, self.log)
     rc  = dbh.connToDB ()
     if rc != 0 :
         self.log.error('Could not connect to the DB rc = %s ' % rc)
         return None
      
     if po == 'SEL': r = dbh.runQry(sql)
     else          : r = dbh.exeQry(sql,bv)
     dbh.closeDBConn()
     return r        
Esempio n. 5
0
 def connToDB(self):
     r = 1
     sql = 'SELECT GETDATE() AS [CurrentDate]'
     self.logger.debug('qry = %s' % sql)
     cs = getDSConnStr('MSSQLNAT',self.ib.db_user,self.ib.db_pwd,self.ib.db_server,self.ib.db_name)
     self.logger.debug('ConnStr %s' % cs)
     dbh = MSSQLNat(cs,self.logger)
     if dbh.connToDB() != 0 : return r
     
     rs = dbh.runQry(sql)
     if rs is not None and len(rs) > 0 :  
         r = 0
         self.logger.debug("rs = %s" % rs[0][0])
     
     dbh.closeDBConn()
     return r   
Esempio n. 6
0
 def connToDB(self):
     
     r = 1
     sql = 'select SYSDATE from dual'
     cs = getDSConnStr('ORADB',self.ib.db_user,self.ib.db_pwd,self.ib.db_name)
     self.logger.debug('qry = %s\nCS =%s ' % (sql,cs))
     dbh = DBOracle(cs,self.logger)
     if dbh.connToDB() != 0 : return r
     
     rs = dbh.runQry(sql)
     if rs is not None and type(rs) == list :  
         r = 0
         self.logger.debug("rs = %s" % rs[0][0])
     
     dbh.closeDBConn()
     return r
Esempio n. 7
0
 def connToDB(self):
     r = 1
     sql = 'select current_timestamp'
     self.logger.debug('qry = %s' % sql)
     cs = getDSConnStr('NZODBC',self.ib.db_user,self.ib.db_pwd,self.ib.db_server,self.ib.db_name)
     self.logger.debug('ConnStr %s' % cs)
     dbh = NZODBC(cs,self.logger)
     if dbh.connToDB() != 0 : return r
     
     rs = dbh.runQry(sql)
     if rs is not None and len(rs) > 0 :  
         r = 0
         self.logger.debug("rs = %s" % rs[0][0])
     
     dbh.closeDBConn()
     return r
Esempio n. 8
0
def test_sel_qry(qry, dsn):
    print "QUERY IS %s " % qry
    #log = Logger('C:\ptest\all\env\logs','C:\ptest')
    log = logging.getLogger(__name__)
    #cfg = DBOracle('infadev/infadev@infadev',log)
    cs = getDSConnStr('SQLLITE', 'ib.user', 'ib.pwd', dsn)
    cfg = DBSQLLite(cs, log)
    ret = cfg.connToDB()
    print "Connecting to DB : ret = %s " % ret
    rs = cfg.runQry(qry)
    for r in rs:
        print "r = ", r


#    D = {}
#print "rs = ", rs
#    for (v,k) in rs: D[string.capitalize(k)]=v
#    print D
#    id = list(x[0] for x in rs)
#    print "id = ", id
#    sn = list(x[1] for x in rs)
#    print "sn = ", sn
    cfg.closeDBConn()