-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
35 lines (27 loc) · 1.06 KB
/
database.py
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
34
35
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
def create_db():
# Name, price, seats total, seats first class, cruise (knots), range, fuel (us gal, usable), runway (ft)
c.execute("""CREATE TABLE planes (
manufacturer text,
type text,
price real,
seats integer,
fcseats integer,
cruise integer,
range integer,
fuel integer,
runway integer
)""")
create_db()
def insert_plane(plane):
with conn:
c.execute("INSERT INTO planes VALUES (:manufacturer, :type, :price, :seats, :fcseats, :cruise, :range, :fuel, :runway)",
{'manufacturer': plane.manufacturer, 'type': plane.type, 'price': plane.price, 'seats': plane.seats, 'fcseats': plane.fcseats, 'cruise': plane.cruise, 'range': plane.range, 'fuel': plane.fuel, 'runway': plane.runway})
def list_planes(q):
if q == 0:
c.execute("SELECT * FROM planes")
return c.fetchall()
def close_connection():
conn.close()