This commit is contained in:
parent
7655c068f4
commit
0768bb7782
27
database.py
27
database.py
|
@ -4,29 +4,34 @@ import mysql.connector
|
||||||
|
|
||||||
|
|
||||||
# Create Database or Table
|
# Create Database or Table
|
||||||
def create(db_cursor, name, _type):
|
def create(db_cursor, name, type_):
|
||||||
query = f'CREATE {_type} {name}'
|
query = f'CREATE {type_} {name}'
|
||||||
try:
|
try:
|
||||||
db_cursor.execute(query)
|
db_cursor.execute(query)
|
||||||
except mysql.connector.Error as err:
|
except mysql.connector.Error as err:
|
||||||
print('Something went wrong', err)
|
print('Something went wrong', err)
|
||||||
|
|
||||||
|
|
||||||
def add(db_cursor):
|
def add(db_cursor, name, type_):
|
||||||
# TODO Frage / Antwort hinzufügen
|
# TODO
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def read(db_cursor):
|
def read(db_cursor, name, type_):
|
||||||
# TODO Frage / Antwort auslesen
|
# TODO
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def update(db_cursor):
|
def update(db_cursor, name, type_):
|
||||||
# TODO Frage / Antwort Aktualisieren
|
# TODO
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def del_(db_cursor):
|
def del_(db_cursor, name, type_):
|
||||||
# TODO Frage / Antwort löschen
|
query = f'DROP if exists {type_} {name}'
|
||||||
return
|
try:
|
||||||
|
db_cursor.execute(query)
|
||||||
|
except mysql.connector.Error as err:
|
||||||
|
print('Something went wrong', err)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,13 @@ import config
|
||||||
import main_menu
|
import main_menu
|
||||||
|
|
||||||
|
|
||||||
# Auskommentieren falls Server offline
|
|
||||||
|
|
||||||
|
|
||||||
# Datenbank Menü
|
# Datenbank Menü
|
||||||
def menu():
|
def menu():
|
||||||
enable_menu = True
|
enable_menu = True
|
||||||
selection = {0: 'Datenbanken anzeigen', 1: 'Datenbank erstellen', 2: 'Datenbank löschen', 3: 'Datenbank umbenennen',
|
selection = {0: 'Datenbanken anzeigen', 1: 'Datenbank erstellen', 2: 'Datenbank löschen', 3: 'Datenbank umbenennen',
|
||||||
4: 'Datenbank auselesen',
|
4: 'Datenbank auselesen',
|
||||||
5: 'Tabelle erstellen', 6: 'Tabelle umbenennen', 7: 'Tabelle löschen', 8: 'Tabelle auselsen',
|
5: 'Tabelle erstellen', 6: 'Tabelle umbenennen', 7: 'Tabelle löschen', 8: 'Tabelle auslesen',
|
||||||
9: 'In Tabelle einfügen', 10: 'Tabellen anzeigen', 11: 'Zurück zum Hauptmenü'}
|
9: 'In Tabelle einfügen', 10: 'Tabellen anzeigen', 11: 'Zurück zum Hauptmenü', 12 : 'Frage/Antwort hinzufügen'}
|
||||||
|
|
||||||
print('#Datenbank Menü# \n'
|
print('#Datenbank Menü# \n'
|
||||||
'\nWas möchtest du tun?\n')
|
'\nWas möchtest du tun?\n')
|
||||||
|
@ -31,8 +28,10 @@ def menu():
|
||||||
database_name = input('Wie soll die Datenbank heißen?')
|
database_name = input('Wie soll die Datenbank heißen?')
|
||||||
database.create(cursor, database_name, _type)
|
database.create(cursor, database_name, _type)
|
||||||
case 2:
|
case 2:
|
||||||
# TODO Funktion
|
_type = 'DATABASE'
|
||||||
print('Datenbank löschen') # Platzhalter für die Funktion
|
print('#Datenbank löschen#') # Platzhalter für die Funktion
|
||||||
|
database_name = input('Welche Datenbank soll gelöscht werden?')
|
||||||
|
database.del_(cursor, database_name, _type)
|
||||||
case 3:
|
case 3:
|
||||||
# TODO Funktion
|
# TODO Funktion
|
||||||
return
|
return
|
||||||
|
@ -61,5 +60,8 @@ def menu():
|
||||||
return
|
return
|
||||||
case 11:
|
case 11:
|
||||||
main_menu.main_menu()
|
main_menu.main_menu()
|
||||||
|
case 12:
|
||||||
|
# TODO Funktion
|
||||||
|
return
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue
Block a user