importcx_Oracle as cxfrom quartz.comm.config importconfSqlclassOraclePy():def __init__(self,userName,password,host,port,connType,service_name): #标识是根据SID还是SERVICE_NAME连接
self.userName =userName
self.password=password
self.host=host
self.port=portif (connType == 'SID'):
self.con=cx.connect(self.userName, self.password, cx.makedsn(self.host, self.port, service_name))
self.cursor=self.con.cursor()elif(connType == "SERVICE_NAME"):
dns_tns= cx.makedsn(self.host, self.port, service_name=service_name)
self.con=cx.connect(self.userName,self.password,dns_tns)
self.cursor=self.con.cursor()else:print("不支持的数据库连接方式,当前只支持SID和SERVICE_NAME")#批量执行增删改sql
defexecuteSqls(self,sqls):for sql insqls:
self.cursor.execute(sql)
self.con.commit()#self.cursor.close
#self.con.close
#更新交易表
defupdateTxnCtrl(self,sql,idTxn):
sql= sql.replace("IDTXN",str(idTxn))
self.cursor.execute(sql)
self.con.commit()defupdateTxnCtrl1(self,sql,tunnelValue,idTxn):
sql= sql.replace('tunnelValue',str(tunnelValue)).replace("IDTXN",str(idTxn))
self.cursor.execute(sql)
self.con.commit()#self.cursor.close
#self.con.close
#更新交易表
defupdateTxnCtrl2(self, sql,value1 , value2, idTxn):
sql= sql.replace('tunnelValue1', str(value1)).replace('tunnelValue2', str(value2)).replace("IDTXN",str(idTxn))
self.cursor.execute(sql)
self.con.commit()#self.cursor.close
#self.con.close
#查询清分明细表
defClrTxnListQuery(self,sql,idTxn):
sql= sql.replace('idTxn',str(idTxn))
self.cursor.execute(sql)
col=[]
resultSets=[]for i inself.cursor.description:
col.append(i[0])for data inself.cursor.fetchall():
list2=(list(data))
resultSets.append(dict(map(lambdax, y: [x, y], col, list2)))returnresultSetsdefT_RPT_INAMT(self,sql):
self.cursor.execute(sql)
col=[]
resultSets=[]for i inself.cursor.description:
col.append(i[0])for data inself.cursor.fetchall():
list2=(list(data))
resultSets.append(dict(map(lambdax, y: [x, y], col, list2)))returnresultSets#关闭数据连接
defdisConnection(self):
self.cursor.close
self.con.closeif __name__ == '__main__':#conn = OraclePy('partner','partner','192.168.127.121',1530,'SID','billdb')
conn = OraclePy('QAMODIFY', 'bfjwc0qocjp0dlgf', '192.168.6.42', 1530, 'SERVICE_NAME', 'vposdbtaf')
sql= "select t.* from expt t"TrptInamt=conn.T_RPT_INAMT(sql)print(len(TrptInamt))print(TrptInamt)
conn.disConnection()