replace old db connections
This commit is contained in:
19
timeTrack.py
19
timeTrack.py
@@ -27,7 +27,6 @@ class TimeTrack:
|
||||
self.CATEGORIES = False
|
||||
self.REFERENCES = False
|
||||
self.LOGFILE = 'timetrack.log'
|
||||
self.DBCON = sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
|
||||
logging.basicConfig(
|
||||
filename=self.LOGFILE,
|
||||
level=logging.DEBUG,
|
||||
@@ -37,9 +36,6 @@ class TimeTrack:
|
||||
self.db_setup()
|
||||
self.load_config()
|
||||
|
||||
def __del__(self):
|
||||
self.DBCON.close()
|
||||
|
||||
## Prepartation
|
||||
#==============
|
||||
### Check OS and clear screen
|
||||
@@ -146,7 +142,7 @@ class TimeTrack:
|
||||
|
||||
logging.debug('Create initial database tables')
|
||||
try:
|
||||
with self.DBCON as con:
|
||||
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||
for SQL in sql:
|
||||
con.execute(SQL)
|
||||
except sqlite3.Error as err:
|
||||
@@ -290,8 +286,11 @@ class TimeTrack:
|
||||
logging.debug('Accepted username: {}'.format(username))
|
||||
|
||||
sql = "INSERT INTO users ( name ) values ( ? )"
|
||||
|
||||
|
||||
|
||||
try:
|
||||
with self.DBCON as con:
|
||||
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||
con.execute(sql, [username])
|
||||
except sqlite3.Error as err:
|
||||
logging.error('User could not be saved in database')
|
||||
@@ -316,7 +315,7 @@ class TimeTrack:
|
||||
sql = "SELECT * FROM users"
|
||||
|
||||
try:
|
||||
with self.DBCON as con:
|
||||
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||
cur = con.cursor()
|
||||
if data:
|
||||
cur.execute(sql, [data])
|
||||
@@ -357,7 +356,7 @@ class TimeTrack:
|
||||
|
||||
sql = "INSERT INTO active_events ( starttime, user_id ) VALUES ( ?, ? )"
|
||||
try:
|
||||
with self.DBCON as con:
|
||||
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||
con.execute(sql, [TIME, self.USERID])
|
||||
except sqlite3.Error as err:
|
||||
logging.error('Event could not be created')
|
||||
@@ -390,7 +389,7 @@ class TimeTrack:
|
||||
return 0
|
||||
|
||||
try:
|
||||
with self.DBCON as con:
|
||||
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||
con.execute(sql, [data])
|
||||
except sqlite3.Error as err:
|
||||
logging.error('Event could not be deleted')
|
||||
@@ -493,7 +492,7 @@ class TimeTrack:
|
||||
|
||||
sql = "INSERT INTO time_entries ( starttime, endtime, user_id, activity ) VALUES ( ?, ?, ?, ? )"
|
||||
try:
|
||||
with self.DBCON as con:
|
||||
with sqlite3.connect(self.DATABASE, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
|
||||
con.execute(sql, [data[1], endtime, self.USERID, action])
|
||||
except sqlite3.Error as err:
|
||||
logging.error('Time entry could not be created')
|
||||
|
||||
Reference in New Issue
Block a user