Beispiel #1
0
class InsertData(object):
    def __init__(self):
        self.sd = SwitchDatabase()
        self.cursor = self.sd.connect_databases().cursor()

    def insert_one(self, sql, data):
        try:
            self.cursor.execute(sql, data)
            print(sql)
            # 一定得提交数据
            self.sd.conn.commit()
        except Exception as e:
            print("Error: %s" % e)
            self.sd.conn.rollback()
        # 关闭游标
        self.cursor.close()
        self.sd.close_databases()

    def insert_more(self, sql, data):
        try:
            self.cursor.executemany(sql, data)
            self.sd.conn.commit()
        except Exception as e:
            print("Error: %s" % e)
            self.sd.conn.rollback()
        # 关闭游标
        self.cursor.close()
        # 关闭连接
        self.sd.close_databases()
Beispiel #2
0
class UpdateData(object):

    def __init__(self):
        self.sd = SwitchDatabase()
        self.cursor = self.sd.connect_databases().cursor()

    def update_one(self, sql, data):
        try:
            # sql
            self.cursor.execute(sql, data)
            self.sd.conn.commit()
        except Exception as e:
            print("Error: %s" % e)
        # 关闭游标
        self.cursor.close()
        self.sd.close_databases()

    def update_more(self, sql, data):
        try:
            self.cursor.executemany(sql, data)
            self.sd.conn.commit()
        except Exception as e:
            print("Error: %s" % e)
        # 关闭游标
        self.cursor.close()
        self.sd.close_databases()
Beispiel #3
0
class DeleteData(object):
    def __init__(self):
        self.sd = SwitchDatabase()
        self.cursor = self.sd.connect_databases().cursor()

    def delete_data(self, sql, data):
        try:
            self.cursor.execute(sql, data)
            self.sd.conn.commit()
        except Exception as e:
            print("Error: %s" % e)
        # 关闭游标
        self.cursor.close()
        # 关闭连接
        self.sd.close_databases()
Beispiel #4
0
class SelectData(object):
    def __init__(self):
        self.sd = SwitchDatabase()
        self.cursor = self.sd.connect_databases().cursor()

    def get_one(self, sql):
        self.cursor.execute(sql)
        results = self.cursor.fetchone()
        print(results)
        self.cursor.close()
        self.sd.close_databases()

    def get_all(self, sql):
        self.cursor.execute(sql)
        results = self.cursor.fetchall()
        print(results)
        self.cursor.close()
        self.sd.close_databases()
Beispiel #5
0
 def __init__(self):
     self.sd = SwitchDatabase()
     self.cursor = self.sd.connect_databases().cursor()