python解析json到sql语句
#!/usr/bin/python# -*- coding: utf-8 -*-from Mysqlhelper import MysqlHelperclass DoDatabase():def __init__(self,newdaip,table,database,port,dbusername,password,**dictinfo):self.newdaip = newdaipself.t
·
#!/usr/bin/python
# -*- coding: utf-8 -*-
from Mysqlhelper import MysqlHelper
class DoDatabase():
def __init__(self,newdaip,table,database,port,dbusername,password,**dictinfo):
self.newdaip = newdaip
self.table = table
self.database = database
self.port = port
self.dbusername = dbusername
self.password = password
self.dictinfo = dictinfo
def createdasql(self,table,**dictinfo):
ls = [(k, v) for k, v in dictinfo.items() if v is not None]
sql = 'insert into %s (' % table + ','.join([i[0] for i in ls]) + \
') values (' + ','.join(repr(i[1]) for i in ls) + ');'
return sql
def insertdadatabase(self,newdaip,port,database,dbusername,password,sql,**dictinfo):
mysqlhelper = MysqlHelper(newdaip,port,database,dbusername,password,charset='utf8')
mysqlhelper.insert(sql)
mysqlhelper.close()
更多推荐
已为社区贡献23条内容
所有评论(0)