From b9f10402edb4a42d091a18ffec93819243175e55 Mon Sep 17 00:00:00 2001 From: starnakin Date: Sun, 4 Jun 2023 12:31:08 +0200 Subject: [PATCH] fix: database --- Database.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Database.py b/Database.py index b36ebc2..63b4784 100644 --- a/Database.py +++ b/Database.py @@ -1,6 +1,12 @@ import mysql.connector import User +def is_in(lst: list, name: str): + for i in lst: + if (i[0] == name): + return (1); + return (0); + class Database: def __init__(self, host, port, user, password): """ @@ -21,7 +27,7 @@ class Database: ) self.cursor = self.mydb.cursor() self.cursor.execute("SHOW DATABASES"); - if (not "zeolak" in self.cursor): + if (not is_in(self.cursor, "zeolak")): self.cursor.execute("CREATE DATABASE zeolak") self.mydb = mysql.connector.connect( host = host, @@ -34,14 +40,16 @@ class Database: def _create_table(self, name: str, content: dict): command: str = f"CREATE TABLE {name} (" - for item in content.keys(): - command += f"{item[0]} {item[1]}, " + for key, value in content.items(): + command += f"{key} {value}, " + command = command[:-2] command += ")" + print (command) self.cursor.execute(command) def create_user_table(self): self.cursor.execute("SHOW TABLES"); - if (not "users" in self.cursor): + if (not is_in(self.cursor, "users")): data = { "email": "VARCHAR(255)", "username": "VARCHAR(255)",