sql command file load
This commit is contained in:
parent
50559223ed
commit
1489354ed6
|
@ -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()
|
|
@ -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))
|
Loading…
Reference in New Issue