This commit is contained in:
parent
35bf0accdb
commit
cf6abeaeb0
|
@ -1,6 +1,6 @@
|
||||||
# TODO Database verbindung herstellen
|
# TODO Database verbindung herstellen
|
||||||
|
|
||||||
# Database
|
# Database Verbinungsdaten
|
||||||
|
|
||||||
user = 'root'
|
user = 'root'
|
||||||
password = ''
|
password = ''
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
|
||||||
|
|
||||||
def create(db_cursor, name):
|
# Create Database or Table
|
||||||
query = f'CREATE DATABASE {name}'
|
def create(db_cursor, name, _type):
|
||||||
|
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:
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
|
||||||
|
|
||||||
|
# Aufbau der verbindung zum Mysql Server
|
||||||
def db_connection(user, password, host):
|
def db_connection(user, password, host):
|
||||||
connection = ''
|
connection = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Verbindung mit die in der Config festgelegt werden
|
||||||
connection = mysql.connector.connect(user=user, password=password, host=host)
|
connection = mysql.connector.connect(user=user, password=password, host=host)
|
||||||
except mysql.connector.Error as err:
|
except mysql.connector.Error as err:
|
||||||
print('Something went wrong', err)
|
print('Something went wrong', err)
|
||||||
|
|
46
database_menu.py
Normal file
46
database_menu.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import database
|
||||||
|
import database_connection
|
||||||
|
import config
|
||||||
|
|
||||||
|
# Auskommentieren falls Server offline
|
||||||
|
cursor = database_connection.db_connection(config.user, config.password, config.host)
|
||||||
|
|
||||||
|
|
||||||
|
# Datenbank Menü
|
||||||
|
def menu():
|
||||||
|
enable_menu = True
|
||||||
|
selection = {0: 'Datenbanken anzeigen', 1: 'Datenbank erstellen', 2: 'Datenbank löschen', 3: 'Datenbank umbenennen',
|
||||||
|
4: 'Datenbank auselesen',
|
||||||
|
5: 'Tabelle erstellen', 6: 'Tabelle umbenennen', 7: 'Tabelle löschen', 8: 'Tabelle auselsen',
|
||||||
|
9: 'In Tabelle einfügen', 10: 'Tabellen anzeigen'}
|
||||||
|
|
||||||
|
print('#Datenbank Menü# \n'
|
||||||
|
'\nWas möchtest du tun?\n')
|
||||||
|
|
||||||
|
while enable_menu:
|
||||||
|
for key, value in selection.items():
|
||||||
|
print(key, value)
|
||||||
|
selection_number = int(input('Bitte Auswahl treffen'))
|
||||||
|
|
||||||
|
match selection_number:
|
||||||
|
case 1:
|
||||||
|
_type = 'DATABASE'
|
||||||
|
print('#Datenbank erstellen#')
|
||||||
|
database_name = input('Wie soll die Datenbank heißen?')
|
||||||
|
database.create(cursor, database_name, _type)
|
||||||
|
case 2:
|
||||||
|
# TODO Funktion
|
||||||
|
print('Datenbank löschen') # Platzhalter für die Funktion
|
||||||
|
case 3:
|
||||||
|
# TODO Funktion
|
||||||
|
return
|
||||||
|
case 4:
|
||||||
|
# TODO Funktion
|
||||||
|
return
|
||||||
|
case 5:
|
||||||
|
_type = 'TABLE'
|
||||||
|
print('#Tabelle erstellen#')
|
||||||
|
table_name = input('Wie soll die Datenbank heißen?')
|
||||||
|
database.create(cursor, table_name, _type)
|
||||||
|
|
||||||
|
break
|
6
main.py
6
main.py
|
@ -3,11 +3,13 @@
|
||||||
# Ein und Ausgabe der Fragen/Antworten
|
# Ein und Ausgabe der Fragen/Antworten
|
||||||
# Datenbanken (CRUD) Tabellen (CRUD)
|
# Datenbanken (CRUD) Tabellen (CRUD)
|
||||||
|
|
||||||
import selection_menu
|
import main_menu
|
||||||
|
|
||||||
|
|
||||||
|
# Aufruf des Main Menüse
|
||||||
def main():
|
def main():
|
||||||
selection_menu.menu()
|
main_menu.main_menu()
|
||||||
|
|
||||||
|
|
||||||
|
# Starten der Main
|
||||||
main()
|
main()
|
||||||
|
|
24
main_menu.py
Normal file
24
main_menu.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import database_menu
|
||||||
|
|
||||||
|
|
||||||
|
# Main Menu
|
||||||
|
|
||||||
|
def main_menu():
|
||||||
|
enable_menu = True
|
||||||
|
selection = {0: 'Datenbank Menü', 1: 'Zufallsfrage', 2: 'Programm beenden'}
|
||||||
|
|
||||||
|
print('# Main Menü #\n')
|
||||||
|
while enable_menu:
|
||||||
|
for key, value in selection.items():
|
||||||
|
print(key, value)
|
||||||
|
selection_number = int(input('Bitte Auswahl treffen\n'))
|
||||||
|
match selection_number:
|
||||||
|
case 0:
|
||||||
|
database_menu.menu()
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
# TODO Starte Zufallsfragenausgabe
|
||||||
|
return
|
||||||
|
case 2:
|
||||||
|
# TODO Programm Beenden
|
||||||
|
return
|
|
@ -1,28 +0,0 @@
|
||||||
import database
|
|
||||||
import database_connection
|
|
||||||
import config
|
|
||||||
|
|
||||||
cursor = database_connection.db_connection(config.user, config.password, config.host)
|
|
||||||
|
|
||||||
|
|
||||||
def menu():
|
|
||||||
enable_menu = True
|
|
||||||
selection = {1: 'Datenbank erstellen', 2: 'Datenbank löschen', 3: 'Datenbank umbenennen', 4: 'Datenbank auselesen',
|
|
||||||
5: 'Tabelle erstellen'}
|
|
||||||
|
|
||||||
print('Was möchtest du tun?')
|
|
||||||
|
|
||||||
while enable_menu:
|
|
||||||
for key, value in selection.items():
|
|
||||||
print(key, value)
|
|
||||||
selection_number = int(input('Bitte Auswahl treffen'))
|
|
||||||
|
|
||||||
match selection_number:
|
|
||||||
case 1:
|
|
||||||
print('#Datenbank erstellen#') # Platzhalter für die Funktion
|
|
||||||
database_name = input('Wie soll die Datenbank heißen?')
|
|
||||||
database.create(cursor, database_name)
|
|
||||||
case 2:
|
|
||||||
# TODO Funktion
|
|
||||||
print('Datenbank löschen') # Platzhalter für die Funktion
|
|
||||||
break
|
|
Loading…
Reference in New Issue
Block a user