commit message from python script

This commit is contained in:
2023-11-16 18:23:25 +01:00
parent 728abc4a77
commit 465d1e927b

View File

@@ -1,4 +1,4 @@
import sqlite3, os import sqlite3, os, argv
class db_work: class db_work:
def __init__(self,db_file = str ) -> None: def __init__(self,db_file = str ) -> None:
@@ -22,8 +22,8 @@ class db_work:
'genre' TEXT PRIMARY KEY, 'genre' TEXT PRIMARY KEY,
'beschreibung' TEXT 'beschreibung' TEXT
); """ ); """
cursor.execute(sql_code cursor.execute(sql_code)
)
con_db.commit() con_db.commit()
def add_value_db(self): def add_value_db(self):
@@ -57,20 +57,31 @@ class db_work:
cursor.execute(sql) cursor.execute(sql)
def show_value(self, sql_query = str): def ausgabe_abfrage(self, sql_abfrage):
with sqlite3.connect(self.db_file) as con_db: with sqlite3.connect(self.db_file) as daten:
cursor = con_db.cursor() try:
sql_code = sql_query zeiger = daten.cursor()
cursor.execute(sql_code) zeiger.execute(sql_abfrage)
ergebnis = cursor.fetchall() for datensatz in zeiger:
return ergebnis for wert in datensatz:
wert = str(wert)
print('| ', wert, " " * (9 - len(wert)), end="")
print("|")
except sqlite3.OperationalError:
print("Tabelle nicht gefunden!")
except:
print("Daten konnten nicht bearbeitet werden!")
if __name__ == "__main__": if __name__ == "__main__":
script_folder = os.path.dirname(os.path.realpath(__file__)) script_folder = os.path.dirname(os.path.realpath(__file__))
db_file_full = script_folder + os.sep + "my_moviedb.db" db_file_full = script_folder + os.sep + "my_moviedb.db"
my_db = db_work(db_file=db_file_full) my_db = db_work(db_file=db_file_full)
my_db.create_db()
add_value_to_db = my_db.add_value_db() for query in argv.sys.argv[1:]:
if query == '-q':
my_db.ausgabe_abfrage(sql_abfrage="""SELECT * FROM movies;""")
#my_db.create_db()
#add_value_to_db = my_db.add_value_db()
#print (add_value_to_db) #print (add_value_to_db)
print(my_db.show_value(sql_query="""SELECT * FROM movies;"""))