commit message from python script

This commit is contained in:
2023-08-07 21:28:57 +02:00
parent 41c8a603ed
commit 4ada02f510
2 changed files with 23 additions and 1 deletions

View File

@@ -14,10 +14,32 @@ class db_work:
'''
cursor.execute(sql_code)
con_db.commit()
def add_value_db(self, cooler_typ = str, glueckszahl = int):
with sqlite3.connect(self.db_file) as con_db:
cursor = con_db.cursor()
sql_code = '''
INSERT INTO eggs (cooler_typ, glückszahl)
VALUES('{coolertype}', {eine_zahl});
'''.format(coolertype=cooler_typ,eine_zahl=glueckszahl)
cursor.execute(sql_code)
con_db.commit()
def show_value(self):
with sqlite3.connect(self.db_file) as con_db:
cursor = con_db.cursor()
sql_code = '''
SELECT * FROM eggs;
'''
cursor.execute(sql_code)
ergebnis = cursor.fetchall()
return ergebnis
if __name__ == "__main__":
script_folder = os.path.dirname(os.path.realpath(__file__))
db_file_full = script_folder + os.sep + "spam.db"
my_db = db_work(db_file=db_file_full)
my_db.create_db()
my_db.create_db()
my_db.add_value_db(cooler_typ="daniel-2", glueckszahl=42)
print(my_db.show_value())