commit message from python script
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS eggs(
|
|
||||||
cooler_typ TEXT PRIMARY KEY,
|
|
||||||
glückszahl INTEGER
|
|
||||||
);
|
|
||||||
|
|
||||||
@@ -7,38 +7,51 @@ class db_work:
|
|||||||
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()
|
||||||
fd = open(self.script_folder + os.sep + "create_db.sql", "r")
|
sql_code = """
|
||||||
sql_code = fd.read()
|
CREATE TABLE IF NOT EXISTS movies(
|
||||||
#sql_code = '''
|
'id' INTEGER AUTOINCREMENT,
|
||||||
# CREATE TABLE IF NOT EXISTS eggs(
|
'name' TEXT PRIMARY KEY,
|
||||||
# cooler_typ TEXT,
|
'filmgenres' TEXT,
|
||||||
# glückszahl INTEGER
|
'year' TEXT,
|
||||||
# );
|
'persönlich' TEXT
|
||||||
# '''
|
); """
|
||||||
|
|
||||||
cursor.execute(sql_code)
|
cursor.execute(sql_code)
|
||||||
|
|
||||||
|
sql_code = """
|
||||||
|
CREATE TABLE IF NOT EXISTS filmgenres(
|
||||||
|
'genre' TEXT PRIMARY KEY,
|
||||||
|
'beschreibung' TEXT
|
||||||
|
); """
|
||||||
|
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):
|
||||||
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()
|
||||||
fd = open(self.script_folder + os.sep + "add_value.sql", "r")
|
while True:
|
||||||
sql_code = fd.read().format(coolertype=cooler_typ,eine_zahl=glueckszahl)
|
name = input("Name des Films: ")
|
||||||
|
if not name:
|
||||||
|
break
|
||||||
|
movie_genre = input("Genre: ")
|
||||||
|
movie_year = input("Jahr: ")
|
||||||
|
per_info = input("Meinung : ")
|
||||||
|
sql = """Select * from movies WHERE name = '{name}';""".format(name=name)
|
||||||
|
cursor.execute(sql)
|
||||||
|
if not cursor.fetchone():
|
||||||
|
print("Film wird angelgt ")
|
||||||
|
#self.speicher_aktion(name, ort, vorfall)
|
||||||
|
else:
|
||||||
|
print("Film bereits vorhanden !")
|
||||||
|
print("Eingabevorgang wurde beendet.")
|
||||||
|
|
||||||
try:
|
def speicher_aktion():
|
||||||
cursor.execute(sql_code)
|
pass
|
||||||
except sqlite3.IntegrityError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
con_db.commit()
|
def show_value(self, sql_query = str):
|
||||||
return True
|
|
||||||
|
|
||||||
def show_value(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 = '''
|
sql_code = sql_query
|
||||||
SELECT * FROM eggs;
|
|
||||||
'''
|
|
||||||
cursor.execute(sql_code)
|
cursor.execute(sql_code)
|
||||||
ergebnis = cursor.fetchall()
|
ergebnis = cursor.fetchall()
|
||||||
return ergebnis
|
return ergebnis
|
||||||
@@ -46,9 +59,9 @@ class db_work:
|
|||||||
|
|
||||||
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 + "spam.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()
|
my_db.create_db()
|
||||||
add_value_to_db = my_db.add_value_db(cooler_typ="daniel-5", glueckszahl=42)
|
add_value_to_db = my_db.add_value_db()
|
||||||
print (add_value_to_db)
|
#print (add_value_to_db)
|
||||||
print(my_db.show_value())
|
print(my_db.show_value(sql_query="""SELECT * FROM movies;"""))
|
||||||
0
my_movies/my_moviedb.db
Normal file
0
my_movies/my_moviedb.db
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user