Python Learning Note Five----using the SQLite database

Source: Internet
Author: User
Tags sqlite sqlite database

Import Sqlite3def Test1 (): con = sqlite3.connect ("d:\\test.db") con = sqlite3.connect ("Memory") cur =con.cursor () Try: Cur.execute (' CREATE TABLE score (ID integer primary key,name varchar (TEN), scores integer) ') Cur.execute ("INSERT INTO score VALUES (0, ' Rose ', ")") Cur.execute ("INSERT into score values (1, ' Alice ',") ") Cur.execute (" INSERT 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 (4, ' Jack ', 198)") #Don ' t execute the following statement when except Occurscur.exec Ute ("INSERT into score values (5, ' Tony ', 198)") Cur.execute ("INSERT into score values (6, ' David ',") ") Cur.execute (" Update score Set scores =? Where id=? ", (45,3)) #With Paramcur.execute (" Update score set name=? "). Where id=? ", (" John ", 0)) #With paramcur.execute (" Delete from score where ID =1 ") except Exception,e:print" There is some ex Cept ", Econ.commit () print" Insert complete "print"-----------------------------------------"Print" Last row ID was ", cur.lastrowidcur.execute (' select * from score ') print Cur.fetchall () print"----------------- -----------------------"Cur.execute (" SELECT count (*) from score ") print" Current Rows are: ", Cur.fetchall () [0]cur.close () Con.close () if __name__ = = ' __main__ ': Test1 () print "Hello World"

Python Learning Note Five----using the SQLite database

Related Article

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.