Skip to content

Commit

Permalink
Uploaded all files
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazza1996 committed Oct 6, 2024
1 parent 416a5ba commit b69f492
Show file tree
Hide file tree
Showing 6 changed files with 1,091 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The database should mirror **Selected Aspects** of a commercial employment agenc
- A python script to connect and send commands to the database
- This will not work for public users as it needs to be run on a specific network.
- 12 Normalised Entities
- 5 Unique Views
- An Entity Relationship (ER) Diagram
- A Data Dictionary

Expand Down
Binary file added dataDictionary.docx
Binary file not shown.
116 changes: 116 additions & 0 deletions databaseConnection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import mysql.connector;
from prettytable import PrettyTable

HOST = "#######"
USER = "#######"
PASSWORD = "#######"
DATABASE = "#######"
TABLE_NAME = "jobSeekers"
VIEW_NAME = "employerHireRejectionStats"

def connectToDatabase():
global connectionError
connectionError = False

try:
global db
db = mysql.connector.connect(
host = HOST,
user = USER,
password = PASSWORD,
database = DATABASE
)
except:
connectionError = True

global cursor
cursor = db.cursor()

def executeCommandVal(sql, val):
cursor.execute(sql, val)

def executeCommand(command):
cursor.execute(command)
return cursor.fetchall()

def getColumnNames(name):
result = executeCommand("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '"+ name +"' ORDER BY ORDINAL_POSITION")
columnNames = []
for x in result:
for i in x:
columnNames.append(i)
return columnNames

def listTables():
result = executeCommand("SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema = 'nwatkins02'")
tables = []
for x in result:
for i in x:
tables.append(i)
counter = 0
tables.sort()
for table in tables:
counter += 1
print(str(counter) + ". " + table)

def addRecord():
print("Adding to " + TABLE_NAME)
forename = input("\nForename: ")
surname = input("Surname: ")
dob = input("DOB: ")
email = input("Email Address: ")
phoneNo = input("Phone Number: ")
address = input("Address: ")
city = input("City: ")
county = input("County: ")
postcode = input("Postcode: ")
cvFile = input("CV File: ")

val = (forename, surname, dob, email, phoneNo, address, city, county, postcode, cvFile)

error = False
try:
executeCommandVal("INSERT INTO jobSeekers (forename, surname, dob, email, phoneNo, address, city, county, postcode, cvFile) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", val)
except:
print("Error. Could not create record.")
error = True

if error == False:
db.commit()
print("Record Inserted")

columnNames = getColumnNames(TABLE_NAME)
records = executeCommand("SELECT * FROM " + TABLE_NAME)

table = PrettyTable()
table.field_names = columnNames
table.add_rows(records)
print(table)

def viewTable():
columnNames = getColumnNames(VIEW_NAME)
records = executeCommand("SELECT * FROM " + VIEW_NAME)

table = PrettyTable()
table.field_names = columnNames
table.add_rows(records)
print(table)
print()

connectToDatabase()

finished = False

while finished == False:
print("Welcome!\n")
print("1. Add a record to jobSeekers")
print("2. View employer hire rejection stats")
print("3. Exit\n")
choice = input("Select an option: ")

if choice == "1":
addRecord()
elif choice == "2":
viewTable()
elif choice == "3":
finished = True
Binary file added erd.docx
Binary file not shown.
Binary file added query.docx
Binary file not shown.
Loading

0 comments on commit b69f492

Please sign in to comment.