import sqlite3
from sqlite3 import Error
class database_tasks:
def __init__(self,bookId=0,studentId=0):
self.bookId=bookId
self.studentId=studentId
def create_connection(self):
try:
conn = sqlite3.connect('library Management.db')
return conn
except Error as e:
print(e)
def insert(self, conn,dbname, name, writer='none'):
c = conn.cursor()
if dbname == "Book_database":
self.bookId += 1
#sql= "INSERT INTO Book_database VALUES(" + database_tasks.bookId + "," + name + "," + writer + ")"
c.execute ("INSERT INTO Book_database VALUES(?,?,?)",(database_tasks.bookId, name, writer))
Вы можете инициализировать класс как:
data = database_tasks()
или
data = database_tasks(bookId=<id>,studentId=<id>)
и вставить записи:
data.insert(coon,dbname,name,writer)
, дайте мне знать, если это поможет .