sql command file load
This commit is contained in:
parent
50559223ed
commit
2a852388bf
|
@ -6,7 +6,7 @@ TABLE_X = "x_posts"
|
||||||
|
|
||||||
class DatabaseController:
|
class DatabaseController:
|
||||||
def __init__(self, db_name):
|
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()
|
self.cursor = self.conn.cursor()
|
||||||
|
|
||||||
def run_query(self, query):
|
def run_query(self, query):
|
||||||
|
@ -18,13 +18,26 @@ class DatabaseController:
|
||||||
print(e)
|
print(e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def run_command(self, commnd):
|
def run_command(self, command):
|
||||||
try:
|
try:
|
||||||
self.cursor.execute(commnd)
|
self.cursor.execute(command)
|
||||||
result = self.cursor.rowcount
|
result = self.cursor.rowcount
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
return result > 0
|
return result > 0
|
||||||
except Exception as e:
|
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)
|
print(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -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