forked from rasbt/python_reference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_db.py
More file actions
28 lines (21 loc) · 758 Bytes
/
query_db.py
File metadata and controls
28 lines (21 loc) · 758 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
# 10/28/2013 Sebastian Raschka
# Syntax basics for querying sqlite3 data bases
import sqlite3
# open existing database
conn = sqlite3.connect('zinc_db1.db')
c = conn.cursor()
# print all lines ordered by number of non_rot_bonds
for row in c.execute('SELECT * FROM zinc_db1 ORDER BY non_rot_bonds'):
print row
# print all lines that are purchasable and have <= 7 rotatable bonds
t = ('YES',7,)
for row in c.execute('SELECT * FROM zinc_db1 WHERE purchasable=? AND non_rot_bonds <= ?', t):
print row
# print all lines that are purchasable and have <= 7 rotatable bonds
t = ('YES',7,)
c.execute('SELECT * FROM zinc_db1 WHERE purchasable=? AND non_rot_bonds <= ?', t)
rows = c.fetchall()
for r in rows:
print r
# close connection
conn.close()