diff --git a/database.py b/database.py deleted file mode 100644 index 3eacba0..0000000 --- a/database.py +++ /dev/null @@ -1,87 +0,0 @@ -# TODO: Datenbank Klasse (CRUD) -# -# TODO: Tabellen und Spaltennamen selbst bestimmen - - -import mysql.connector - - -# Create Database or Table -def create(db_cursor, name, type_): - # TODO Fix nötig - query = f'CREATE {type_} {name};' - if type_ == 'TABLE': - query = f'CREATE {type_} {name} (ID integer primary key auto_increment, question varchar(255), answers varchar(255));' - try: - db_cursor.execute(query) - except mysql.connector.Error as err: - print('Something went wrong', err) - - -def read(db_cursor, name): - query = f'SELECT * FROM {name}' - try: - db_cursor.execute(query) - except mysql.connector.Error as err: - print('Something went wrong', err) - - -def update(db_cursor, name, type_): - # TODO - return - - -def del_(db_cursor, name, type_): - query = f'DROP {type_} IF EXISTS {name};' - try: - db_cursor.execute(query) - except mysql.connector.Error as err: - print('Something went wrong', err) - -# TODO hier die Spaltennamen selbst bestimmen -def add(db_cursor, name, question, answer): - query = f'INSERT INTO {name} (question, answer) VALUES ({question}, {answer});' - try: - db_cursor.execute(query) - except mysql.connector.Error as err: - print('Something went wrong', err) - - -def show(db_cursor, type_): - query = f'SHOW {type_};' - try: - db_cursor.execute(query) - except mysql.connector.Error as err: - print('Something went wrong', err) - - -def use(db_cursor, name): - query = f'USE {name};' - try: - db_cursor.execute(query) - except mysql.connector.Error as err: - print('Something went wrong', err) - - -def show_tables(db_cursor): - query = 'show tables;' - try: - db_cursor.execute(query) - except mysql.connector.Error as err: - print('Something went wrong', err) - - -def show(db_cursor, use_type): - query = f'show {use_type}' - try: - db_cursor.execute(query) - for i in db_cursor.fetchall(): - print(str(i).replace(',','').replace('(', '').replace(')', '')) - print('\n') - except mysql.connector.Error as err: - print('Something went wrong', err) - - -def string_formater(_string): - _string.replace(',','').replace('(', '').replace(')', '') - return str(_string) \ No newline at end of file