table initializing and dbservice minor fixes

This commit is contained in:
Volkan Şahin 2016-03-18 18:40:44 +02:00
parent 28967bd639
commit 8fabf0d47b

View file

@ -17,6 +17,15 @@ class AhenkDbService(object):
self.connection=None self.connection=None
self.cursor = None self.cursor = None
def initialize_table(self):
self.check_and_create_table('task',['task TEXT','timestamp TEXT'])
self.check_and_create_table('policy',['id INTEGER PRIMARY KEY AUTOINCREMENT','type TEXT','version TEXT','name TEXT'])
self.check_and_create_table('profile',['id INTEGER','create_date TEXT','label TEXT','description TEXT','overridable INTEGER','active INTEGER','deleted INTEGER','profile_data BLOB','modify_date TEXT'])
self.check_and_create_table('plugin',['version TEXT','name TEXT','description TEXT'])
def connect(self): def connect(self):
try: try:
self.connection=sqlite3.connect(self.db_path, check_same_thread=False) self.connection=sqlite3.connect(self.db_path, check_same_thread=False)
@ -29,7 +38,7 @@ class AhenkDbService(object):
cols = ', '.join([str(x) for x in cols]) cols = ', '.join([str(x) for x in cols])
self.cursor.execute('create table if not exists '+table_name+' ('+cols+')') self.cursor.execute('create table if not exists '+table_name+' ('+cols+')')
else: else:
self.warn("Could not create table cursor is None! Table Name : " + str(table_name)) self.logger.warning("Could not create table cursor is None! Table Name : " + str(table_name))
def drop_table(self,table_name): def drop_table(self,table_name):
sql = "DROP TABLE "+table_name sql = "DROP TABLE "+table_name
@ -53,7 +62,7 @@ class AhenkDbService(object):
self.cursor.execute(sql, tuple(args)) self.cursor.execute(sql, tuple(args))
self.connection.commit() self.connection.commit()
else: else:
self.warn("Could not update table cursor is None! Table Name : " + str(table_name)) self.logger.warning("Could not update table cursor is None! Table Name : " + str(table_name))
except Exception as e: except Exception as e:
self.logger.error("Updating table error ! Table Name : " + str(table_name) + " " + str(e)) self.logger.error("Updating table error ! Table Name : " + str(table_name) + " " + str(e))
@ -87,7 +96,7 @@ class AhenkDbService(object):
except Exception as e: except Exception as e:
raise raise
else: else:
self.warn("Could not select table cursor is None! Table Name : " + str(table_name)) self.logger.warning("Could not select table cursor is None! Table Name : " + str(table_name))
def close(self): def close(self):
try: try: