sql command file load

This commit is contained in:
katboi01 2025-01-13 01:14:58 +01:00
parent 50559223ed
commit 2a852388bf
2 changed files with 24 additions and 3 deletions

View File

@ -6,7 +6,7 @@ TABLE_X = "x_posts"
class DatabaseController:
def __init__(self, db_name):
self.conn = sqlite3.connect(db_name, isolation_level="DEFERRED")
self.conn = sqlite3.connect(db_name)
self.cursor = self.conn.cursor()
def run_query(self, query):
@ -18,15 +18,28 @@ class DatabaseController:
print(e)
return None
def run_command(self, commnd):
def run_command(self, command):
try:
self.cursor.execute(commnd)
self.cursor.execute(command)
result = self.cursor.rowcount
self.conn.commit()
return result > 0
except Exception as e:
self.conn.rollback()
print(e)
return False
def run_commands(self, commands):
try:
for command in commands:
self.cursor.execute(command)
result = self.cursor.rowcount
self.conn.commit()
return result > 0
except Exception as e:
self.conn.rollback()
print(e)
return False
def close(self):
self.conn.close()

View File

@ -0,0 +1,8 @@
import sys
from databaseController import DatabaseController
db = DatabaseController("/home/pi/python/Katbots/JapariArchive/database.db")
with open(sys.argv[1], "rt") as file:
lines = [line for line in file.readlines() if line.strip()]
print(db.run_commands(lines))