许明会的计算机技术主页

Language:C,C++,.NET Framework(C#)
Thinking:Design Pattern,Algorithm,WPF,Windows Internals
Database:SQLServer,Oracle,MySQL,PostSQL
IT:MCITP,Exchange,Lync,Virtualization,CCNP

导航

python体验(05).python处理sqlite数据库

python处理sqlite数据库
1、检查用户环境是否安装sqlite
        aptitude show sqlite3
2、创建数据库,添加表并插入数据
        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、编写代码
 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.execute('insert into people(id,name,age,sex)' +
        
' values(99,\'temp\',99,\'F\')')
= cur.execute('delete from people where age=99')
con.commit()
cur.execute(
'select * from people')
= cur.fetchall()
print s
cur.close()
con.close()


posted on 2010-12-02 15:42  许明会  阅读(278)  评论(0编辑  收藏  举报