commit message from python script
This commit is contained in:
2
my_movies/add_value.sql
Normal file
2
my_movies/add_value.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
INSERT INTO eggs (cooler_typ, glückszahl)
|
||||||
|
VALUES('{coolertype}', {eine_zahl});
|
||||||
5
my_movies/create_db.sql
Normal file
5
my_movies/create_db.sql
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS eggs(
|
||||||
|
cooler_typ TEXT,
|
||||||
|
glückszahl INTEGER
|
||||||
|
);
|
||||||
|
|
||||||
@@ -3,25 +3,32 @@ import sqlite3, os
|
|||||||
class db_work:
|
class db_work:
|
||||||
def __init__(self,db_file = str ) -> None:
|
def __init__(self,db_file = str ) -> None:
|
||||||
self.db_file = db_file
|
self.db_file = db_file
|
||||||
|
self.script_folder = os.path.dirname(os.path.realpath(__file__))
|
||||||
def create_db(self):
|
def create_db(self):
|
||||||
with sqlite3.connect(self.db_file) as con_db:
|
with sqlite3.connect(self.db_file) as con_db:
|
||||||
cursor = con_db.cursor()
|
cursor = con_db.cursor()
|
||||||
sql_code = '''
|
fd = open(self.script_folder + os.sep + "create_db.sql", "r")
|
||||||
CREATE TABLE IF NOT EXISTS eggs(
|
sql_code = fd.read()
|
||||||
cooler_typ TEXT,
|
#sql_code = '''
|
||||||
glückszahl INTEGER
|
# CREATE TABLE IF NOT EXISTS eggs(
|
||||||
);
|
# cooler_typ TEXT,
|
||||||
'''
|
# glückszahl INTEGER
|
||||||
|
# );
|
||||||
|
# '''
|
||||||
|
|
||||||
cursor.execute(sql_code)
|
cursor.execute(sql_code)
|
||||||
con_db.commit()
|
con_db.commit()
|
||||||
|
|
||||||
def add_value_db(self, cooler_typ = str, glueckszahl = int):
|
def add_value_db(self, cooler_typ = str, glueckszahl = int):
|
||||||
with sqlite3.connect(self.db_file) as con_db:
|
with sqlite3.connect(self.db_file) as con_db:
|
||||||
cursor = con_db.cursor()
|
cursor = con_db.cursor()
|
||||||
sql_code = '''
|
fd = open(self.script_folder + os.sep + "add_value.sql", "r")
|
||||||
INSERT INTO eggs (cooler_typ, glückszahl)
|
sql_code = fd.read().format(coolertype=cooler_typ,eine_zahl=glueckszahl)
|
||||||
VALUES('{coolertype}', {eine_zahl});
|
#sql_code = '''
|
||||||
'''.format(coolertype=cooler_typ,eine_zahl=glueckszahl)
|
# INSERT INTO eggs (cooler_typ, glückszahl)
|
||||||
|
# VALUES('{coolertype}', {eine_zahl});
|
||||||
|
# '''.format(coolertype=cooler_typ,eine_zahl=glueckszahl)
|
||||||
|
|
||||||
cursor.execute(sql_code)
|
cursor.execute(sql_code)
|
||||||
con_db.commit()
|
con_db.commit()
|
||||||
|
|
||||||
@@ -41,5 +48,5 @@ if __name__ == "__main__":
|
|||||||
db_file_full = script_folder + os.sep + "spam.db"
|
db_file_full = script_folder + os.sep + "spam.db"
|
||||||
my_db = db_work(db_file=db_file_full)
|
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)
|
my_db.add_value_db(cooler_typ="daniel-3", glueckszahl=42)
|
||||||
print(my_db.show_value())
|
print(my_db.show_value())
|
||||||
Binary file not shown.
Reference in New Issue
Block a user