Python code example for sqlite3 operations

Source: Internet
Author: User
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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.