blob: d1082f52502371ab2b6ded74bf2544c2e82f2514 (
plain) (
blame)
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
|
try: from pysqlite2 import dbapi2 as sqlite
except: print "python-sqlite is missing. Exiting."; sys.exit(1)
from threading import Lock
class myDB_class:
def __init__(self):
self.dbcon = sqlite.connect(":memory:", check_same_thread=False)
self.dbcon.row_factory = sqlite.Row
# self.dbcur = dbcon.cursor()
self.dblock = Lock()
self.execute("create table events(eid INTEGER PRIMARY KEY AUTOINCREMENT, date KEY, host, position, parser, message, css_style, tooltip BLOB)")
def execute(self, query):
self.dblock.acquire()
toret = self.dbcon.execute(query)
self.dblock.release()
return toret
def execute_and_fetch(self, query):
self.dblock.acquire()
dbcur = self.dbcon.execute(query)
toret = dbcur.fetchall()
self.dblock.release()
return toret
|