python sqlite3簡單操做

python sqlite3簡單操做(原創)import sqlite3class CsqliteTable:    def __init__(self):        pass    def linkSqlite3(self):        self.conn = sqlite3.connect('./data/xiaohai.db')        self.c = self.conn.cursor()        print("Opened database successfully")    def insertTable(self,sql):        self.c.execute(sql)        self.conn.commit()        print("insert success")    def selectValues(self):        self.conn = sqlite3.connect('./data/xiaohai.db')        self.c = self.conn.cursor()        self.cursor = self.c.execute("SELECT id from t_member;")        list1=[]        for row in self.cursor:            list1.append(row[0])        return list1    def updateTable(self):        self.conn = sqlite3.connect('./data/xiaohai.db')        self.c = self.conn.cursor()        self.cursor = self.c.execute("UPDATE t_member set name = '墨軒' where ID='1001';")        self.conn.commit()    def delValue(self):        self.conn = sqlite3.connect('test.db')        self.c = self.conn.cursor()        self.c.execute("DELETE from t_member where ID=2;")        self.conn.commit()    def closeTable(self):        print("close table")        self.conn.close()if __name__=="__main__":    sqliteTable=CsqliteTable()    sqliteTable.linkSqlite3()    # sql="insert into t_member(id,name) values('3166102029','蕭海')"    # sqliteTable.insertTable(sql)    # list1=sqliteTable.selectValues()    sqliteTable.updateTable()    sqliteTable.closeTable()
相關文章
相關標籤/搜索