save img in db

This commit is contained in:
2023-12-15 17:09:59 +03:00
parent ddce8f7c90
commit ad7754b38b
3 changed files with 28 additions and 18 deletions

View File

@@ -7,12 +7,12 @@ class Record:
id: int | None = None
name: str | None = ""
description: str | None = ""
img_path: str | None = ""
img: str | None = ""
def __init__(self, id, name, img_path, description):
def __init__(self, id, name, img, description):
self.id = id
self.name = name
self.img_path = img_path
self.img = img
self.description = description
@@ -29,17 +29,17 @@ class DB:
"""CREATE TABLE IF NOT EXISTS records (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
path TEXT NOT NULL,
description BLOB
img BLOB NOT NULL,
description TEXT NOT NULL
)""")
self.path = path
def add_record(self, name="", description="", img_path=""):
def add_record(self, name="", description="", img=""):
self.cur.execute(
'''INSERT INTO records (name, path, description) VALUES (?, ?, ?)''', (name, img_path, description))
'''INSERT INTO records (name, img, description) VALUES (?, ?, ?)''', (name, img, description))
self.con.commit()
def edit_record(self, old_name, name="", img_path="", description=""):
def edit_record(self, old_name, name="", img="", description=""):
record = self.get_record_by_name(old_name)
if record.name != name:
self.cur.execute(
@@ -47,9 +47,9 @@ class DB:
if record.description != description:
self.cur.execute(
'UPDATE records SET description = ? WHERE name = ?', (description, old_name))
if record.img_path != img_path:
if record.img != img:
self.cur.execute(
'UPDATE records SET path = ? WHERE name = ?', (img_path, old_name))
'UPDATE records SET img = ? WHERE name = ?', (img, old_name))
self.con.commit()
def get_record_by_name(self, name):