参考网址:
举例:
def queryEx(self, sql, args):
try:
cursor = self.conn.cursor()
cursor.execute(sql,args)
except (AttributeError, MySQLdb.OperationalError):
self.connect()
cursor = self.conn.cursor()
cursor.execute(sql,args)
except MySQLdb.Error, e:
Logger.logr.info("{0}".format(e))
return cursor
def insertServerCertList(self,tms_uuid,server_uuid,cert_md5,cert_pem,certDecDic):
try:
sql = u""" insert into server_cert_list(tms_uuid,server_uuid,cert_md5,cert_pem,x509_issuer,x509_serial,x509_subject) values('{0}','{1}','{2}','{3}',%(x509_issuer)s,%(x509_serial)s,%(x509_subject)s)""".format(tms_uuid,server_uuid,cert_md5,cert_pem)
cur=self.db.queryEx(sql,certDecDic)
except MySQLdb.Error, e:
Logger.logr.error(u"MysqlError({0})!").format(e)