Upload files to "source/DataBank"
This commit is contained in:
parent
f937978ecb
commit
237b9a7467
BIN
source/DataBank/__init__.py
Normal file
BIN
source/DataBank/__init__.py
Normal file
Binary file not shown.
55
source/DataBank/createDatabank.py
Normal file
55
source/DataBank/createDatabank.py
Normal file
@ -0,0 +1,55 @@
|
||||
import sqlalchemy as db #somehow pyodbc does not work in container
|
||||
from sqlalchemy.sql import text
|
||||
from sqlalchemy_utils import database_exists, create_database
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
creates the table Mitarbeiter
|
||||
IN:
|
||||
the cursor/engine which is the connection object to the db
|
||||
'''
|
||||
def createMitarbeiter(cursor):
|
||||
#write the SQL command to create the table
|
||||
create = text('''CREATE TABLE IF NOT EXISTS "Mitarbeiter"
|
||||
(
|
||||
kuerzel varchar(50) primary key,
|
||||
vorName varchar(50),
|
||||
nachName varchar(50),
|
||||
geschaeftsStelle varchar(50),
|
||||
eintrittsDatum date,
|
||||
eMail varchar(50),
|
||||
telefonNummer int
|
||||
)''')
|
||||
cursor.execute(create)
|
||||
cursor.commit()
|
||||
|
||||
|
||||
'''
|
||||
deletes the table Mitarbeiter
|
||||
IN:
|
||||
the cursor/engine which is the connection object to the db
|
||||
'''
|
||||
def dropMitarbeiter(cursor):
|
||||
#write the SQL command to create the table
|
||||
create = text('''DROP TABLE IF EXISTS "Mitarbeiter" ''')
|
||||
cursor.execute(create)
|
||||
cursor.commit()
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
71
source/DataBank/fillDatabank.py
Normal file
71
source/DataBank/fillDatabank.py
Normal file
@ -0,0 +1,71 @@
|
||||
import sqlalchemy as db #somehow pyodbc does not work in container
|
||||
from sqlalchemy.sql import text
|
||||
from sqlalchemy_utils import database_exists, create_database
|
||||
import numpy as np
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
inputs a new Mitarbeiter into our databank
|
||||
IN:
|
||||
cursor: the cursor/engine which is the connection object to the db
|
||||
newMitarbeiter: Array(7) with kuerzel, vorName, nachName, geschaeftstelle, eintrittsdatum
|
||||
'''
|
||||
def inputMitarbeiter(cursor, newMitarbeiter):
|
||||
#write the SQL command to add data to our table
|
||||
#sqlalchemy needs text(SQL command), and ' around the values
|
||||
#tableName (attributes) values (of attributes)
|
||||
input = text("""INSERT INTO "Mitarbeiter"
|
||||
(kuerzel, vorName, nachName, geschaeftsStelle, eintrittsDatum, eMail, telefonNummer)
|
||||
VALUES ('{}', '{}', '{}', '{}', '{}', '{}', '{}')""" #need ' ' around string for SQL. Python does not preserve '' from string input!
|
||||
.format(newMitarbeiter[0], newMitarbeiter[1], newMitarbeiter[2], newMitarbeiter[3], newMitarbeiter[4], newMitarbeiter[5], newMitarbeiter[6]))
|
||||
cursor.execute(input)
|
||||
cursor.commit()
|
||||
|
||||
|
||||
|
||||
'''
|
||||
deletes a Mitarbeiter who is not working at crossnative anymore
|
||||
IN:
|
||||
cursor: the cursor/engine which is the connection object to the db
|
||||
oldMitarbeiter: scalar string
|
||||
'''
|
||||
def deleteMitarbeiter(cursor, oldMitarbeiter):
|
||||
input = text("""DELETE
|
||||
FROM "Mitarbeiter"
|
||||
WHERE kuerzel = '{}'""".format(oldMitarbeiter))
|
||||
cursor.execute(input)
|
||||
cursor.commit()
|
||||
|
||||
|
||||
|
||||
'''
|
||||
checks which Mitarbeiter in DB are not in list of Mitarbeiter anymore
|
||||
IN:
|
||||
cursor: the cursor/engine which is the connection object to the db
|
||||
currentMitarbeiter: Array(n)
|
||||
OUT:
|
||||
oldMitarbeiter. Array(m)
|
||||
'''
|
||||
def checkMitarbeiter(cursor, currentMitarbeiter):
|
||||
oldMitarbeiter = []
|
||||
|
||||
input = text("""Select kuerzel
|
||||
FROM "Mitarbeiter" """)
|
||||
inDbMitarbeiter = cursor.execute(input)
|
||||
|
||||
#boolean array with True in [n] if inDbMitarbeiter[n] is in currentMitarbeiter
|
||||
isIn = np.isin(inDbMitarbeiter, currentMitarbeiter)
|
||||
#adds kurzel to oldMitarbeiter if in DB but not in Dobby(currentMitarbeiter)
|
||||
for i in range(len(inDbMitarbeiter)):
|
||||
if not (isIn[i]):
|
||||
oldMitarbeiter.append(inDbMitarbeiter[i])
|
||||
|
||||
return oldMitarbeiter
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
Loading…
x
Reference in New Issue
Block a user