-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_table.py
More file actions
33 lines (28 loc) · 963 Bytes
/
Copy pathcreate_table.py
File metadata and controls
33 lines (28 loc) · 963 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
import os
import sqlite3 as db
baseDir = os.path.abspath(os.path.dirname(__file__))
datapath = os.path.join(baseDir, 'data.sqlite')
connection = db.connect(datapath)
def drop_tables():
with connection:
connection.execute("DROP TABLE IF EXISTS user")
def create_tables():
with connection:
connection.execute("""
CREATE TABLE user(
previousScore INT NOT NULL,
highScore INT NOT NULL,
CONSTRAINT invalidHigh CHECK(highScore >= previousScore)
);
""")
def insert_into():
with connection:
connection.execute("""
INSERT INTO user
VALUES
(?,?);
""",
(0,0))
drop_tables()
create_tables()
insert_into()