aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPinapelz <donaldshan1@outlook.com>2023-07-08 01:10:24 -0700
committerPinapelz <donaldshan1@outlook.com>2023-07-08 01:10:24 -0700
commit416fc525a2c366fd21f7dfaaa32794793493e761 (patch)
treee6d137e6d9906ee443d756bb534afad307224664
parenta434be1cbe53d2d6e3e6b3870a15c7f33934a3a6 (diff)
fix: make all cursors buffered to avoid lazy loading
-rw-r--r--sql/sql_handler.py22
1 files changed, 11 insertions, 11 deletions
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()
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage