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