From 53d1d209428aac5902432171b4fca7eaea712c0d Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Tue, 1 Aug 2023 18:03:45 -0400 Subject: [PATCH] fix: refactored new_guild_generation --- sugoncredit/sugoncredit.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/sugoncredit/sugoncredit.py b/sugoncredit/sugoncredit.py index f68b6b5..f04ea51 100644 --- a/sugoncredit/sugoncredit.py +++ b/sugoncredit/sugoncredit.py @@ -34,18 +34,13 @@ class SugonCredit(commands.Cog): return word + 's' def new_guild_generation(self, guild_id): - """Adds a new table for a guild to the SQLite databse.""" - con = sqlite3.connect(f'{self.data_path}') + """Adds a new table for a guild to the SQLite database.""" + con = sqlite3.connect(self.data_path) cur = con.cursor() - exist_check = cur.execute(f'''IF EXISTS - (SELECT object_id FROM sys.tables - WHERE name = '{guild_id}' - AND SCHEMA_NAME(schema_id) = 'dbo') - PRINT 'False' - ELSE - PRINT 'True';''') - if exist_check == False: - cur.execute(f'''CREATE TABLE '{guild_id}' (user_id text, balance real)''') + try: + cur.execute(f"SELECT 1 FROM {guild_id} LIMIT 1;") + except sqlite3.OperationalError: + cur.execute(f"CREATE TABLE {guild_id} (user_id TEXT, balance REAL);") con.commit() con.close()