#!/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()
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐