61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
import sqlite3
|
|
|
|
|
|
class Log:
|
|
def __init__(self, connection : sqlite3.Connection, id = None, username = None, date = None, time = None, description = None, additional_information = None, suspicious = None):
|
|
self.connection = connection
|
|
self.id = id
|
|
self.username = username
|
|
self.date = date
|
|
self.time = time
|
|
self.description = description
|
|
self.additional_information = additional_information
|
|
self.suspicious = suspicious
|
|
|
|
def load_by_id(self):
|
|
cur = self.connection.cursor()
|
|
row = cur.execute("SELECT * FROM logs WHERE id = ?", (self.id,)).fetchone()
|
|
|
|
if row == None:
|
|
return False
|
|
|
|
self._set_row_values(row)
|
|
|
|
cur.close()
|
|
return True
|
|
|
|
def save(self):
|
|
cur = self.connection.cursor()
|
|
cur.execute("""
|
|
INSERT INTO logs
|
|
(id, username, date, time, description, additional_information, suspicious) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
""", (self.id, self.username, self.date, self.time, self.description, self.additional_information, self.suspicious))
|
|
|
|
self.connection.commit()
|
|
cur.close()
|
|
return True
|
|
|
|
def update(self):
|
|
cur = self.connection.cursor()
|
|
cur.execute("""
|
|
UPDATE logs SET
|
|
username = ?,
|
|
date = ?,
|
|
description = ?,
|
|
additional_information = ?,
|
|
suspicious = ?,
|
|
WHERE id = ?
|
|
""", (self.firstname, self.lastname, self.zipcode, self.city_id, self.email, self.phone, self.password, self.role, self.id))
|
|
|
|
self.connection.commit()
|
|
cur.close()
|
|
return True
|
|
|
|
def _set_row_values(self, row):
|
|
self.id = row[0]
|
|
self.username = row[1]
|
|
self.date = row[2]
|
|
self.time = row[3]
|
|
self.description = row[4]
|
|
self.additional_information = row[5]
|
|
self.suspicious = row[6] |