'How to drop a sqlite table in python according to a variable name passed through a function [duplicate]
def refreshDatabase(table):
c.execute("DROP TABLE ?", (table,))
conn.commit()
createNewTable(table)
Hey, how can I drop the Table that is declared as a parameter when calling the function? It doesn't seem to work with this syntax. thanks in advance!
Solution 1:[1]
Take a look here
You can't substitute table name at SQL side, so change it from Python (which is not safe of course)
def refreshDatabase(table):
c.execute(f"DROP TABLE {table}")
conn.commit()
createNewTable(table)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alex Kosh |
