zoukankan      html  css  js  c++  java
  • python sqlite3简单操作

    python sqlite3简单操作(原创)
    import sqlite3

    class 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()

  • 相关阅读:
    恭喜,贺喜,同喜
    IIS 原理学习
    ASP.NET Ajax 学习(一)服务器端部分
    一张图片引发的血案
    poj 2828 Buy Tickets
    hdu 1556 Color the ball
    nyoj 求余数
    hdu 1358Period
    hdu 3577Fast Arrangement
    poj2752 Seek the Name, Seek the Fame
  • 原文地址:https://www.cnblogs.com/xiaohai123/p/13583799.html
Copyright © 2011-2022 走看看