-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
42 lines (37 loc) · 1.26 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
36
37
38
39
40
41
42
import sqlite3
class database:
def __init__(self):
self.conn = sqlite3.connect(":memory:",check_same_thread=False)
self.__create_table()
def __create_table(self):
self.conn.execute("""
CREATE TABLE IF NOT EXISTS notes(
id PRIMARY KEY,
start real ,
length real,
key integer
);""")
def insert(self,start,key,length):
print(key,start,length)
self.conn.execute("""
INSERT INTO notes (start,key,length) values(?,?,?);
""", ( start, key, length ) )
def getnotes(self, start, range, keys=(0,128)):
c = self.conn.cursor()
print(start)
c.execute("""
SELECT start, key, length FROM notes
WHERE start BETWEEN ? AND ? AND key BETWEEN ? AND ?;
""",( start, start + range, keys[0], keys[1] ) )
r = c.fetchall()
print("fetched from database",start, range, r)
return set(r)
def drop(self,*n):
c = []
for x in n :
c += x
print(c)
condition = " OR ".join( ["( key = ? AND start = ? AND length = ? )",] * len(n) )
self.conn.execute("""
DELETE FROM notes WHERE ({0})
""".format(condition), c)