Python experience (05). Python processing SQLite Database

Source: Internet
Author: User
Python processes SQLite Databases
1. Check whether SQLite is installed in the user environment
Aptitude show sqlite3
2. Create a database, add tables, and insert data
Sqlite3 myfamily Create   Table People (ID Int , Name Varchar ( 30 ), Age Int , Sex Char ( 1 ));
Insert   Into People Values ( 0 , ' Zihao Xu ' , 5 , ' M ' );
Select   *   From People ;. Exit ;

3. Write Code Phoenix @ Debian: ~ / PY / Database $ cat SQLite. py
# ! /Usr/bin/Python
# Filename: SQLite. py
#
Import Sqlite3 # Import sqlite3 Module
Con = Sqlite3.connect ( ' Myfamily ' ) # Connect to the database
Cur = Con. cursor () # Get the database cursor
Cur.exe cute ( ' Insert into people (ID, name, age, sex) '   +
' Values (99 ,\ ' Temp \ ' , 99 ,\ ' F \ ' ) ' )
R = Cur.exe cute ( ' Delete from people where age = 99 ' )
Con. Commit ()
Cur.exe cute ( ' Select * from people ' )
S = Cur. fetchall ()
Print S
Cur. Close ()
Con. Close ()

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.