Skip to content
Snippets Groups Projects
Commit 5451822b authored by Joona Erkkilä's avatar Joona Erkkilä
Browse files

Update setup.py

parent 254d20b0
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,18 @@ def create_tables():
)
'''
)
### Fix for the broken access control:
# connection.execute(
# '''
# CREATE TABLE IF NOT EXISTS Users (
# id INTEGER PRIMARY KEY AUTOINCREMENT,
# username TEXT NOT NULL,
# password TEXT NOT NULL,
# role TEXT NOT NULL
# )
# '''
# )
###
connection.execute(
'''
CREATE TABLE IF NOT EXISTS Users (
......@@ -65,6 +76,32 @@ def register_users():
finally:
connection.close()
def register_products():
connection = sqlite3.connect(database)
try:
with connection:
cursor = connection.cursor()
products = [
{'name': 'Product1', 'price': "5.5"},
{'name': 'Product2', 'price': "19.99"},
{'name': 'Product3', 'price': "8.0"}
]
for product in products:
cursor.execute("SELECT COUNT(*) FROM Products WHERE name = ?", (product['name'],))
count = cursor.fetchone()[0]
if count > 0:
print("Product already exists.")
else:
cursor.execute("INSERT INTO Products (name, price) VALUES (?, ?)",
(product['name'], product['price']))
finally:
connection.close()
if __name__ == '__main__':
create_tables()
register_users()
register_products()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment