this is the code I would like to have, where I do not have to exactly specify the howtodothis variable during database creation. I want it to be dynamic instead.
class DbHandler():
def __init__(self, howtodothis):
self.database = sqlite3.connect('api_data.db')
self.cursor = self.database.cursor()
self.cursor.execute("CREATE TABLE IF NOT EXISTS ? (test)",(howtodothis,))
def insert(self):
self.cursor.execute("INSERT INTO ? VALUES (?)",(howtodothis,))
I now have this, but I wonder if it is safe
class DbHandler():
def __init__(self, thisworks):
self.database = sqlite3.connect('api_data.db')
self.cursor = self.database.cursor()
self.cursor.execute(f"CREATE TABLE IF NOT EXISTS {thisworks} (test)")
def insert(self):
self.cursor.execute(f"INSERT INTO {thisworks} VALUES (?)")