diff --git a/my_movies/create_db.sql b/my_movies/create_db.sql deleted file mode 100644 index 872dde5..0000000 --- a/my_movies/create_db.sql +++ /dev/null @@ -1,5 +0,0 @@ - CREATE TABLE IF NOT EXISTS eggs( - cooler_typ TEXT PRIMARY KEY, - glückszahl INTEGER - ); - \ No newline at end of file diff --git a/my_movies/database.py b/my_movies/database.py index b76f23a..bb7c41e 100644 --- a/my_movies/database.py +++ b/my_movies/database.py @@ -7,38 +7,51 @@ class db_work: def create_db(self): with sqlite3.connect(self.db_file) as con_db: cursor = con_db.cursor() - fd = open(self.script_folder + os.sep + "create_db.sql", "r") - sql_code = fd.read() - #sql_code = ''' - # CREATE TABLE IF NOT EXISTS eggs( - # cooler_typ TEXT, - # glückszahl INTEGER - # ); - # ''' - + sql_code = """ + CREATE TABLE IF NOT EXISTS movies( + 'id' INTEGER AUTOINCREMENT, + 'name' TEXT PRIMARY KEY, + 'filmgenres' TEXT, + 'year' TEXT, + 'persönlich' TEXT + ); """ 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() - def add_value_db(self, cooler_typ = str, glueckszahl = int): + def add_value_db(self): with sqlite3.connect(self.db_file) as con_db: cursor = con_db.cursor() - fd = open(self.script_folder + os.sep + "add_value.sql", "r") - sql_code = fd.read().format(coolertype=cooler_typ,eine_zahl=glueckszahl) - - try: - cursor.execute(sql_code) - except sqlite3.IntegrityError: - return False - - con_db.commit() - return True + while True: + 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.") + + def speicher_aktion(): + pass - def show_value(self): + def show_value(self, sql_query = str): with sqlite3.connect(self.db_file) as con_db: cursor = con_db.cursor() - sql_code = ''' - SELECT * FROM eggs; - ''' + sql_code = sql_query cursor.execute(sql_code) ergebnis = cursor.fetchall() return ergebnis @@ -46,9 +59,9 @@ class db_work: if __name__ == "__main__": 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.create_db() - add_value_to_db = my_db.add_value_db(cooler_typ="daniel-5", glueckszahl=42) - print (add_value_to_db) - print(my_db.show_value()) \ No newline at end of file + add_value_to_db = my_db.add_value_db() + #print (add_value_to_db) + print(my_db.show_value(sql_query="""SELECT * FROM movies;""")) \ No newline at end of file diff --git a/my_movies/my_moviedb.db b/my_movies/my_moviedb.db new file mode 100644 index 0000000..e69de29 diff --git a/my_movies/spam.db b/my_movies/spam.db deleted file mode 100644 index c510326..0000000 Binary files a/my_movies/spam.db and /dev/null differ diff --git a/play_with_sqllite/startegie.db b/play_with_sqllite/startegie.db index 37b75c8..83b5884 100644 Binary files a/play_with_sqllite/startegie.db and b/play_with_sqllite/startegie.db differ