From 416fc525a2c366fd21f7dfaaa32794793493e761 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sat, 8 Jul 2023 01:10:24 -0700 Subject: fix: make all cursors buffered to avoid lazy loading --- sql/sql_handler.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'sql') diff --git a/sql/sql_handler.py b/sql/sql_handler.py index 7260b0e..9d1c10d 100644 --- a/sql/sql_handler.py +++ b/sql/sql_handler.py @@ -33,7 +33,7 @@ class SQLHandler: exit(1) def _load_database(self, database_name: str): - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: cursor.execute(f"USE {database_name}") print(f"Database {database_name} loaded successfully") @@ -48,7 +48,7 @@ class SQLHandler: exit(1) def create_table(self, name: str, column: str): - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: cursor.execute(f"CREATE TABLE {name} ({column})") print(f"Table {name} created successfully") @@ -56,7 +56,7 @@ class SQLHandler: print(err) def insert_row(self, name: str, column: str, data: tuple): - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: placeholders = ', '.join(['%s'] * len(data)) query = f"INSERT INTO {name} ({column}) VALUES ({placeholders})" @@ -69,7 +69,7 @@ class SQLHandler: def clear_table(self, name: str): - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: cursor.execute(f"DELETE FROM {name}") self.connection.commit() @@ -79,7 +79,7 @@ class SQLHandler: print(err) def reset_auto_increment(self, name: str): - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: cursor.execute(f"ALTER TABLE {name} AUTO_INCREMENT = 1") self.connection.commit() @@ -89,7 +89,7 @@ class SQLHandler: print(err) def copy_rows_to_new_table(self, name: str, new_name: str, column: str): - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: cursor.execute( f"INSERT INTO {new_name} ({column}) SELECT {column} FROM {name}") @@ -102,7 +102,7 @@ class SQLHandler: print(err) def drop_table(self, name: str): - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: cursor.execute(f"DROP TABLE {name}") self.connection.commit() @@ -115,7 +115,7 @@ class SQLHandler: """ Checks if a row exists in a table """ - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: cursor.execute(f"SELECT * FROM {name} WHERE {column_name} = '{value}'") result = cursor.fetchone() @@ -131,7 +131,7 @@ class SQLHandler: """ Updates a row in a table """ - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: cursor.execute(f"UPDATE {name} SET {replace_col} = '{new_value}' WHERE {column_name} = '{search_val}'") self.connection.commit() @@ -141,7 +141,7 @@ class SQLHandler: print(err) def execute_query(self, query: str): - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: cursor.execute(query) result = cursor.fetchall() @@ -151,7 +151,7 @@ class SQLHandler: print(err) def get_query_result(self, query: str): - cursor = self.connection.cursor() + cursor = self.connection.cursor(buffered=True) try: cursor.execute(query) result = cursor.fetchall() -- cgit v1.2.3