123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- #include "dbflight.h"
- void dbFlight::verifyInput(flight object)
- {
- object.printFlight();
-
- }
- QVector<QString> dbFlight::selectFlightById(QString flight_id)
- {
- QSqlQuery query;
- query.prepare("SELECT * FROM flights WHERE id = ?");
- query.addBindValue(flight_id);
- query.exec();
- if(query.first());
- else
- {
- qDebug() << "db::SelectFlightById - No Flight with this ID found";
- QVector<QString> flight;
- return flight;
- }
- QVector<QString> flight;
- flight.append(query.value(0).toString());
- flight.append(query.value(1).toString());
- flight.append(query.value(2).toString());
- flight.append(query.value(3).toString());
- flight.append(query.value(4).toString());
- flight.append(query.value(5).toString());
- flight.append(query.value(6).toString());
- flight.append(query.value(7).toString());
- flight.append(query.value(8).toString());
- qDebug() << "db::SelectFlightById - retreived flight: " << flight;
- return flight;
- }
- bool dbFlight::deleteFlightById(QString flight_id)
- {
- QSqlQuery query;
- query.prepare("DELETE FROM flights WHERE id = ?");
- query.addBindValue(flight_id);
- query.exec();
- QString error = query.lastError().text();
- QSqlQuery query2;
- query2.prepare("DELETE FROM extras WHERE extras_id = ?");
- query2.addBindValue(flight_id);
- query2.exec();
- QString error2 = query2.lastError().text();
- qDebug() << "db::deleteFlightById: Removing flight with ID#: " << flight_id;
- if(error.length() > 0 || error2.length() > 0)
- {
- qWarning() << "db::deleteFlightsById: Errors have occured: " << error << " " << error2;
- return false;
- }else
- {
- return true;
- }
- }
- QVector<QString> dbFlight::createFlightVectorFromInput(QString doft, QString dept, QTime tofb, QString dest,
- QTime tonb, QTime tblk, QString pic, QString acft)
- {
- QVector<QString> flight;
- flight.insert(0, "");
- flight.insert(1, doft);
- flight.insert(2, dept);
- flight.insert(3, QString::number(calc::time_to_minutes(tofb)));
- flight.insert(4, dest);
- flight.insert(5, QString::number(calc::time_to_minutes(tonb)));
- flight.insert(6, QString::number(calc::time_to_minutes(tblk)));
- flight.insert(7, pic);
- flight.insert(8, acft);
-
- return flight;
- }
- void dbFlight::commitFlight(QVector<QString> flight)
- {
- QSqlQuery query;
- query.prepare("INSERT INTO flights (doft, dept, tofb, dest, tonb, tblk, pic, acft) "
- "VALUES (:doft, :dept, :tofb, :dest, :tonb, :tblk, :pic, :acft)");
-
- query.bindValue(":doft", flight[1]);
- query.bindValue(":dept", flight[2]);
- query.bindValue(":tofb", flight[3].toInt());
- query.bindValue(":dest", flight[4]);
- query.bindValue(":tonb", flight[5].toInt());
- query.bindValue(":tblk", flight[6].toInt());
- query.bindValue(":pic", flight[7].toInt());
- query.bindValue(":acft", flight[8].toInt());
- query.exec();
- qDebug() << "Error message for commiting flight: " << query.lastError().text();
- QSqlQuery query2;
- query2.prepare("INSERT INTO extras DEFAULT VALUES");
- query2.exec();
- qDebug() << "Creating extras entry" << query2.lastError().text();
- }
- void dbFlight::commitToScratchpad(QVector<QString> flight)
- {
-
- QSqlQuery query;
- query.prepare("INSERT INTO scratchpad (doft, dept, tofb, dest, tonb, tblk, pic, acft) "
- "VALUES (:doft, :dept, :tofb, :dest, :tonb, :tblk, :pic, :acft)");
-
- query.bindValue(":doft", flight[1]);
- query.bindValue(":dept", flight[2]);
- query.bindValue(":tofb", flight[3].toInt());
- query.bindValue(":dest", flight[4]);
- query.bindValue(":tonb", flight[5].toInt());
- query.bindValue(":tblk", flight[6].toInt());
- query.bindValue(":pic", flight[7].toInt());
- query.bindValue(":acft", flight[8].toInt());
- query.exec();
- qDebug() << query.lastError().text();
- }
- QVector<QString> dbFlight::retreiveScratchpad()
- {
-
- QSqlQuery query;
- query.prepare("SELECT * FROM scratchpad");
- query.exec();
- if(query.first());
- else
- {
-
- QVector<QString> flight;
- return flight;
- }
- query.previous();
- QVector<QString> flight;
- while (query.next()) {
- flight.append(query.value(0).toString());
- flight.append(query.value(1).toString());
- flight.append(query.value(2).toString());
- flight.append(calc::minutes_to_string((query.value(3).toString())));
- flight.append(query.value(4).toString());
- flight.append(calc::minutes_to_string((query.value(5).toString())));
- flight.append(calc::minutes_to_string((query.value(6).toString())));
- flight.append(query.value(7).toString());
- flight.append(query.value(8).toString());
- }
- clearScratchpad();
- return flight;
- }
- bool dbFlight::checkScratchpad()
- {
-
- QSqlQuery query;
- query.prepare("SELECT * FROM scratchpad");
- query.exec();
- if(query.first())
- {
-
- return 1;
- }
- else
- {
-
- return 0;
- }
- }
- void dbFlight::clearScratchpad()
- {
- qDebug() << "Deleting scratchpad";
- QSqlQuery query;
- query.prepare("DELETE FROM scratchpad;");
- query.exec();
- }
|