fixes
This commit is contained in:
19
script.sql
19
script.sql
@@ -34,6 +34,11 @@ END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE TABLE Uhrzeit (
|
||||
ID SERIAL PRIMARY KEY,
|
||||
anfangszeit TIME NOT NULL,
|
||||
endzeit TIME NOT NULL );
|
||||
|
||||
CREATE TABLE Veranstalter (
|
||||
ID INTEGER PRIMARY KEY DEFAULT nextval('global_id_seq'),
|
||||
name VARCHAR(30),
|
||||
@@ -42,7 +47,9 @@ CREATE TABLE Veranstalter (
|
||||
arbeitszeit INTEGER DEFAULT 0,
|
||||
standort VARCHAR(30) DEFAULT random_between_two(),
|
||||
krank BOOLEAN DEFAULT FALSE,
|
||||
admin BOOLEAN NOT NULL DEFAULT FALSE
|
||||
admin BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
uhrzeit_id INTEGER REFERENCES Uhrzeit(ID),
|
||||
tag INTEGER
|
||||
);
|
||||
|
||||
|
||||
@@ -68,10 +75,6 @@ CREATE TABLE Veranstalter (
|
||||
|
||||
|
||||
|
||||
CREATE TABLE Uhrzeit (
|
||||
ID SERIAL PRIMARY KEY,
|
||||
anfangszeit TIME NOT NULL,
|
||||
endzeit TIME NOT NULL );
|
||||
|
||||
|
||||
|
||||
@@ -91,6 +94,8 @@ CREATE TABLE Veranstalter (
|
||||
PRIMARY KEY(uhrzeit_ID, tag)
|
||||
);
|
||||
|
||||
|
||||
|
||||
INSERT INTO Veranstalter (name, email, passwort, admin) VALUES
|
||||
('Davids', 'admin@example.com', 'password123', TRUE),
|
||||
('Dalitz', 'user1@example.com', 'password1', FALSE),
|
||||
@@ -117,3 +122,7 @@ INSERT INTO Veranstaltung (ort, raum, name, dauer) VALUES
|
||||
('B', '208', 'WEB', 2),
|
||||
('A', '109', 'BVA', 2),
|
||||
('B', '210', 'MA1', 2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,11 +30,13 @@ void DBPlan::vertretung(std::string tag, std::string stunde) {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = "
|
||||
"(SELECT ID FROM Veranstalter WHERE ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2) "
|
||||
"AND ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $3 AND tag = $4) LIMIT 1) WHERE uhrzeit_id = $5 AND tag = $6; ";
|
||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID =
|
||||
(SELECT ID FROM Veranstalter WHERE ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2 LIMIT 1)
|
||||
AND ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $3 AND tag = $4 LIMIT 1)
|
||||
AND ID IN (SELECT ID FROM Veranstalter WHERE ID != $5 AND ID != $6 LIMIT 1))
|
||||
WHERE uhrzeit_id = $7 AND tag = $8;)";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, prevStunde, prevTag, nextStunde, nextTag, stunde, tag);
|
||||
pqxx::result response = worker.exec_params(query, prevStunde, prevTag, nextStunde, nextTag, stunde, tag, stunde, tag);
|
||||
|
||||
worker.commit( );
|
||||
if (response.affected_rows( ) == 0) {
|
||||
@@ -64,13 +66,12 @@ void DBPlan::meldeKrank(std::string id, std::string tag, std::string stunde) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter SET krank = TRUE WHERE ID = $1;";
|
||||
"UPDATE Veranstalter SET krank = TRUE, tag = $1, uhrzeit_id = $2 WHERE ID = $3;";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
pqxx::result response = worker.exec_params(query, tag, stunde, id);
|
||||
worker.commit( );
|
||||
|
||||
vertretung(tag, stunde);
|
||||
meldeGesund(id);
|
||||
versendeEmails( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
@@ -94,10 +95,8 @@ void DBPlan::meldeGesund(std::string id) {
|
||||
void DBPlan::deleteVeranstalterForeign(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query = "SELECT tag, uhrzeit_id FROM Veranstalter_Veranstaltung_Uhrzeit WHERE Veranstalter_ID = $1; ";
|
||||
|
||||
//get times where id in plan
|
||||
//for each search vertretung
|
||||
std::string query =
|
||||
"SELECT tag, uhrzeit_id FROM Veranstalter_Veranstaltung_Uhrzeit WHERE Veranstalter_ID = $1; ";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit( );
|
||||
@@ -107,6 +106,11 @@ void DBPlan::deleteVeranstalterForeign(std::string id) {
|
||||
for (int i = 0; i < response.affected_rows( ); i++) {
|
||||
tag = response[i][0].c_str( );
|
||||
stunde = response[i][1].c_str( );
|
||||
std::string query2 =
|
||||
"UPDATE Veranstalter SET krank = TRUE, tag = $1, uhrzeit_id = $2 WHERE ID = $3;";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, tag, stunde, id);
|
||||
worker.commit( );
|
||||
vertretung(tag, stunde);
|
||||
if (getDauer(tag, stunde) == "4")
|
||||
i++;
|
||||
@@ -118,9 +122,8 @@ void DBPlan::deleteVeranstalterForeign(std::string id) {
|
||||
}
|
||||
|
||||
void DBPlan::deleteVeranstalter(std::string id) {
|
||||
deleteVeranstalterForeign(id);
|
||||
|
||||
try {
|
||||
deleteVeranstalterForeign(id);
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query = "DELETE FROM Veranstalter WHERE ID = $1;";
|
||||
|
||||
@@ -163,7 +166,7 @@ void DBPlan::hinzufuegenVeranstalter(std::string email, std::string name, std::s
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"INSERT INTO Veranstaltung (email, name, pw, admin) VALUES ($1, $2, $3, $4);";
|
||||
"INSERT INTO Veranstalter (email, name, passwort, admin) VALUES ($1, $2, $3, $4);";
|
||||
worker.exec_params(query, email, name, pw, admin);
|
||||
worker.commit( );
|
||||
}
|
||||
@@ -445,11 +448,11 @@ std::vector<std::string> DBPlan::getPlan( ) {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
R"(SELECT tag, u.anfangszeit, u.endzeit, o.ort, o.name, v.name, o.raum, v.ID FROM Veranstalter_Veranstaltung_Uhrzeit
|
||||
R"(SELECT Veranstalter_Veranstaltung_Uhrzeit.tag, u.anfangszeit, u.endzeit, o.ort, o.name, v.name, o.raum, v.ID FROM Veranstalter_Veranstaltung_Uhrzeit
|
||||
JOIN Veranstalter v ON Veranstalter_Veranstaltung_Uhrzeit.veranstalter_ID = v.ID
|
||||
JOIN Uhrzeit u ON Veranstalter_Veranstaltung_Uhrzeit.uhrzeit_ID = u.ID
|
||||
JOIN Veranstaltung o ON Veranstalter_Veranstaltung_Uhrzeit.veranstaltung_ID = o.ID
|
||||
ORDER BY tag, uhrzeit_ID;)";
|
||||
ORDER BY Veranstalter_Veranstaltung_Uhrzeit.tag, Veranstalter_Veranstaltung_Uhrzeit.uhrzeit_ID;)";
|
||||
|
||||
pqxx::result response = worker.exec(query);
|
||||
worker.commit( );
|
||||
|
||||
@@ -10,7 +10,11 @@ inline static const std::map<std::string, std::string>& load_config( ) {
|
||||
static bool is_loaded{ false };
|
||||
static std::string fn{ "" };
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
std::string filename = std::string(std::getenv("USER")) + "\\config.cfg";
|
||||
#elif defined(__unix__) || defined(__APPLE__)
|
||||
std::string filename = std::string(std::getenv("HOME")) + "/Dokumente/git/EinsatzplanQT/config.cfg";
|
||||
#endif
|
||||
|
||||
if (!is_loaded || fn != filename) {
|
||||
std::ifstream file(filename);
|
||||
|
||||
Reference in New Issue
Block a user