-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
57 lines (50 loc) · 1.25 KB
/
db.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sqlite3
from sqlite3 import Error
from datetime import datetime
today = datetime.today()
def connect(dbname):
conn = None
try:
conn = sqlite3.connect(dbname)
except Error as e:
print(e)
return conn
def create_db(dbname, sql_text):
conn = connect(dbname)
# delete table for testing purposes
conn.execute('''DROP TABLE IF EXISTS vocabulary''')
conn.execute(sql_text)
def close(conn):
conn.commit()
conn.close()
max_cards = 100
# TODO: set default date?
def init_db():
sql_text = '''CREATE TABLE IF NOT EXISTS vocabulary (id INTEGER PRIMARY KEY AUTOINCREMENT,
chars TEXT,
pinyin TEXT,
english TEXT,
example_ch0 TEXT,
example_eng0 TEXT,
example_ch1 TEXT,
example_eng1 TEXT,
example_ch2 TEXT,
example_eng2 TEXT,
alpha FLOAT DEFAULT 3.0,
beta FLOAT DEFAULT 3.0,
t SMALLINT DEFAULT 1,
last DATE,
interval SMALLINT,
ease TINYINT,
next DATE,
learning BOOLEAN DEFAULT false,
audiopath STRING,
audioblob BLOB,
field1,
field2,
field3);'''
create_db('vocab.db', sql_text)
command = '''CREATE TABLE IF NOT EXISTS vocabulary2 (id INTEGER PRIMARY KEY AUTOINCREMENT,
chars TEXT);'''
conn = connect('vocab.db')
conn.execute(command)