This article mainly introduced the Python simple operation Sqlite3 method, combined with the example form analysis Python to the Sqlite3 database reading, the creation, the enhancement and deletion check and so on basic operation skill, needs the friend can refer to the next
Import Sqlite3def Test1 (): #con =sqlite3.connect ("d:\\test.db") Con =sqlite3.connect (": Memory:") #store in memory cur = Con.cursor () try:cur.execute (' CREATE TABLE score (ID integer primary key,name varchar (TEN), scores integer) ') Cur.exe Cute ("INSERT into score values (0, ' Rose ',") ") Cur.execute (" INSERT into score values (1, ' Alice ', ")") Cur.execute ("Ins ert into score values (2, ' Helon ', +) ") Cur.execute (" INSERT INTO score values (3, ' Tom ', 98) ") Cur.execute (" INSERT INTO Score values (4, ' Jack ', 198) ") Cur.execute (" INSERT INTO score values (5, ' Tony ', 198) ") Cur.execute (" INSERT INTO score VA Lues (6, ' David ', Cur.execute) ' ("UPDATE score Set scores =?") Where id=? ", (45,3)) Cur.execute (" Update score set name=? "). Where id=? ", (" John ", 0)) cur.execute (" Delete from score where ID =1 ") except Exception,e:print" There is some exce PT ", e con.commit () print" Insert complete "print"-----------------------------------------"print" Last Row ID is ", c Ur.lastrowid cur.execUte (' select * from score ') print Cur.fetchall () print "----------------------------------------" Cur.execute ("SELECT Co UNT (*) from score ") print" Current Rows are: ", Cur.fetchall () [0] Cur.close () con.close () if name = = ' main ': Test1 () prin T "Hello World"