File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ encoding/\u5206\u5E03\u5F0F\u8FDB\u7A0B.py=utf-8
77encoding/\u591A\u7EBF\u7A0B.py =utf-8
88encoding/\u591A\u8FDB\u7A0B.py =utf-8
99encoding/\u5E8F\u5217\u5316.py =utf-8
10+ encoding/\u6570\u636E\u5E93\u7F16\u7A0B.py =utf-8
1011encoding/\u6B63\u5219\u8868\u8FBE\u5F0F.py =utf-8
1112encoding/\u9519\u8BEF_\u8C03\u8BD5\u548C\u6D4B\u8BD5.py =utf-8
1213encoding/\u9762\u5411\u5BF9\u8C61.py =utf-8
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # -*- coding: utf-8 -*-
3+
4+ type = 'sqlite3'
5+
6+ if type == 'sqlite3' :
7+ # 导入驱动
8+ import sqlite3
9+ # 连接到数据库 test.db 如果文件不存在,则会自动创建
10+ conn = sqlite3 .connect ('test.db' )
11+ # 创建一个cursor
12+ cursor = conn .cursor ()
13+ # 执行创建表
14+ cursor .execute ('create table user (id varchar(20) primary key, name varchar(20))' )
15+ # 执行插入数据
16+ cursor .execute ("insert into user (id, name) values ('1', 'wangh')" )
17+ # 通过rowcount获取影响的行数
18+ print cursor .rowcount
19+ # 关闭cursor
20+ cursor .close ()
21+ # 提交事物
22+ conn .commit ()
23+ # 关闭connection
24+ conn .close ()
25+
26+ conn1 = sqlite3 .connect ('test.db' )
27+ cursor1 = conn1 .cursor ()
28+ # 执行查询语句
29+ cursor1 .execute ("select * from user where id=?" , '1' )
30+ # 获取结果集
31+ value = cursor1 .fetchall ()
32+ print value
33+ cursor1 .close ()
34+ conn1 .close ()
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
You can’t perform that action at this time.
0 commit comments