コード例 #1
0
    except (mysql.connector.Error, Exception) as e:
        print("Error while deleting data!")
        print(e)


##### Driver execution.....
from database import DB

print("Setting up the database......\n")

# DB API object
db = DB(config_file="sqlconfig.conf")

# create a database (must be the same as the one is in your config file)
database = "EventManagementDB"
if db.create_database(database=database, drop_database_first=True):
    print("Created database {}".format(database))
else:
    print("An error occurred while creating database {} ".format(database))

# create all the tables from databasemodel.sql
db.run_sql_file("EventManagementDB.sql")

# insert sample data from insert.sql
db.run_sql_file("insert.sql")

db.encrypt_passwords()

if int(db._transactions) == 1:
    db.run_sql_file("transactions.sql")
    print("\nSet up process finished with queries from transactions.sql")
コード例 #2
0
state_of_database = True
tables = []
drop_database = input(
    "Do you want to drop and recreate the database, enter y for yes or n for no?\nThis will delete all existing data!\nIf this is your first time running the program then choose y: "
)
drop_database.lower()

if drop_database == "y":
    state_of_database = True
elif drop_database == "n":
    state_of_database = False
else:
    print("Wrong input!")
    exit()

if db.create_database(database=database,
                      drop_database_first=state_of_database):
    print("Created database {}".format(database))
else:
    print("An error occurred while creating database {} ".format(database))

if state_of_database:
    # create all the tables from WholesaleDB.sql
    db.run_sql_file("WholesaleDB.sql")
    # insert sample data from insert.sql
    db.run_sql_file("insert.sql")

tables = db.get_table_names()
db.PROGRAME_STARTED = True
print("\nSet up process finished\n")
show_menu()
option = int(input("Select one option from the menu: "))