diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/extras/sos-html-logs/lib/database.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/extras/sos-html-logs/lib/database.py b/src/extras/sos-html-logs/lib/database.py new file mode 100644 index 00000000..d1082f52 --- /dev/null +++ b/src/extras/sos-html-logs/lib/database.py @@ -0,0 +1,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 |