-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlg.py
More file actions
33 lines (24 loc) · 874 Bytes
/
sqlg.py
File metadata and controls
33 lines (24 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# executemany() method
import sqlite3
with sqlite3.connect("new.db") as connection:
c = connection.cursor()
# insert multiple records as a tuple
cities = [
('Boston', 'MA', 600000),
('Los Angeles', 'CA', 38000000),
('Houston', 'TX', 2100000),
('Philadelphia', 'PA', 1500000),
('San Antonio', 'TX', 1400000),
('San Diego', 'CA', 130000),
('Dallas', 'TX', 1200000),
('San Jose', 'CA', 900000),
('Jacksonville', 'FL', 800000),
('Indianapolis', 'IN', 800000),
('Austin', 'TX', 800000),
('Detroit', 'MI', 700000)
]
c.executemany("INSERT INTO population VALUES (?,?,?)", cities)
c.execute("SELECT * FROM population WHERE population > 1000000")
rows = c.fetchall()
for r in rows:
print r[0],r[1],r[2]