Upload New File

parent 9c337acb
import sqlite3
import model
class DB:
def __init__(self):
self._conn = sqlite3.connect('database.db', check_same_thread=False)
self._c = self._conn.cursor()
# run this method only once
def create_table_feedback(self):
self._c.execute("""CREATE TABLE feedbacks(
id integer PRIMARY KEY,
leave_date text,
real_reason text,
comment text
)""")
self._conn.commit()
def select_feedbacks(self):
self._c.execute("SELECT * FROM feedbacks")
feedbacks = self._c.fetchall()
returnFeedbackList = []
for i in range(0, len(feedbacks)):
returnFeedbackList.append(
model.Feedback(feedbacks[i][0], feedbacks[i][1], feedbacks[i][2], feedbacks[i][3]))
return returnFeedbackList
def save_feedback(self, id, leave_date, real_reason, comment):
try:
sql = "INSERT INTO feedbacks (id, leave_date, real_reason, comment) " \
"VALUES (?, ?, ?, ?)"
val = (id, leave_date, real_reason, comment)
self._c.execute(sql, val)
self._conn.commit()
except:
pass
def delete_feedback(self, id):
sql = 'DELETE FROM feedbacks WHERE id = ' + str(id)
self._c.execute(sql)
self._conn.commit()
# db = DB()
# db.create_table_feedback()
# db.save_feedback(2, '2022-11-10', 'salary', 'some')
# print(db.select_feedbacks())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment