|
@@ -95,221 +95,6 @@ public:
|
|
|
* QVariant::toString() and QVariant::toInt() to convert variants to QString and int.
|
|
|
*/
|
|
|
}
|
|
|
-
|
|
|
- /*
|
|
|
- * Flights Database Related Functions
|
|
|
- */
|
|
|
- /*!
|
|
|
- * \brief SelectFlightById Retreives a single flight from the database.
|
|
|
- * \param flight_id Primary Key of flights database
|
|
|
- * \return Flight details of selected flight.
|
|
|
- */
|
|
|
- static QVector<QString> 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 empty
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- /*!
|
|
|
- * \brief CreateFlightVectorFromInput Converts input from NewFlight Window into database format
|
|
|
- * \param doft Date of flight
|
|
|
- * \param dept Place of Departure
|
|
|
- * \param tofb Time Off Blocks (UTC)
|
|
|
- * \param dest Place of Destination
|
|
|
- * \param tonb Time On Blocks (UTC)
|
|
|
- * \param tblk Total Block Time
|
|
|
- * \param pic Pilot in command
|
|
|
- * \param acft Aircraft
|
|
|
- * \return Vector of values ready for committing
|
|
|
- */
|
|
|
- static QVector<QString> CreateFlightVectorFromInput(QString doft, QString dept, QTime tofb, QString dest, QTime tonb, QTime tblk, QString pic, QString acft)
|
|
|
- {
|
|
|
-
|
|
|
- QVector<QString> flight;
|
|
|
- flight.insert(0, ""); // ID, created as primary key during commit
|
|
|
- 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); // lookup and matching tbd
|
|
|
- flight.insert(8, acft);// lookup and matching tbd
|
|
|
- //qDebug() << flight;
|
|
|
- return flight;
|
|
|
- }
|
|
|
- /*!
|
|
|
- * \brief CommitFlight Inserts prepared flight vector into database. Also creates
|
|
|
- * a corresponding entry in the extras database to ensure matching IDs.
|
|
|
- * \param flight a Vector of values in database format
|
|
|
- */
|
|
|
- static void CommitFlight(QVector<QString> flight)// flight vector shall always have length 9
|
|
|
- {
|
|
|
- QSqlQuery query;
|
|
|
- query.prepare("INSERT INTO flights (doft, dept, tofb, dest, tonb, tblk, pic, acft) "
|
|
|
- "VALUES (:doft, :dept, :tofb, :dest, :tonb, :tblk, :pic, :acft)");
|
|
|
- //flight[0] is primary key, not required for commit
|
|
|
- query.bindValue(":doft", flight[1]); //string
|
|
|
- query.bindValue(":dept", flight[2]);
|
|
|
- query.bindValue(":tofb", flight[3].toInt()); //int
|
|
|
- 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();
|
|
|
- }
|
|
|
- /*!
|
|
|
- * \brief CommitToScratchpad Commits the inputs of the NewFlight window to a scratchpad
|
|
|
- * to make them available for restoring entries when the input fields are being reloaded.
|
|
|
- * \param flight The input data, which was not accepted for commiting to the flights table.
|
|
|
- */
|
|
|
- static void CommitToScratchpad(QVector<QString> flight)// to store input mask
|
|
|
- {
|
|
|
- //qDebug() << "Saving invalid flight to scratchpad";
|
|
|
- QSqlQuery query;
|
|
|
- query.prepare("INSERT INTO scratchpad (doft, dept, tofb, dest, tonb, tblk, pic, acft) "
|
|
|
- "VALUES (:doft, :dept, :tofb, :dest, :tonb, :tblk, :pic, :acft)");
|
|
|
- //flight[0] is primary key, not required for commit
|
|
|
- query.bindValue(":doft", flight[1]); //string
|
|
|
- query.bindValue(":dept", flight[2]);
|
|
|
- query.bindValue(":tofb", flight[3].toInt()); //int
|
|
|
- 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();
|
|
|
- }
|
|
|
- /*!
|
|
|
- * \brief CheckScratchpad Verifies if the scratchpad contains data
|
|
|
- * \return true if scratchpad contains data
|
|
|
- */
|
|
|
- static bool CheckScratchpad() // see if scratchpad is empty
|
|
|
- {
|
|
|
- //qDebug() << "Checking if scratchpad contains data";
|
|
|
- QSqlQuery query;
|
|
|
- query.prepare("SELECT * FROM scratchpad");
|
|
|
- query.exec();
|
|
|
-
|
|
|
- if(query.first())
|
|
|
- {
|
|
|
- //qDebug() << "Scratchpad contains data";
|
|
|
- return 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //qDebug() << ("Scratchpad contains NO data");
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
- /*!
|
|
|
- * \brief ClearScratchpad Deletes data contained in the scratchpad
|
|
|
- */
|
|
|
- static void ClearScratchpad()
|
|
|
- {
|
|
|
- qDebug() << "Deleting scratchpad";
|
|
|
- QSqlQuery query;
|
|
|
- query.prepare("DELETE FROM scratchpad;");
|
|
|
- query.exec();
|
|
|
- }
|
|
|
- /*!
|
|
|
- * \brief RetreiveScratchpad Selects data from scratchpad
|
|
|
- * \return Vector of data contained in scratchpad
|
|
|
- */
|
|
|
- static QVector<QString> RetreiveScratchpad()
|
|
|
- {
|
|
|
- //qDebug() << "Retreiving invalid flight from scratchpad";
|
|
|
- QSqlQuery query;
|
|
|
- query.prepare("SELECT * FROM scratchpad");
|
|
|
- query.exec();
|
|
|
-
|
|
|
- if(query.first());
|
|
|
- else
|
|
|
- {
|
|
|
- //qDebug() << ("scratchpad empty");
|
|
|
- QVector<QString> flight; //return empty
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- /*!
|
|
|
- * \brief deleteFlightById Deletes a Flight from the database.
|
|
|
- * Entries in the basic flights table as well as in the extras table are deleted.
|
|
|
- * \param flight_id The primary key of the entry in the database
|
|
|
- * \return True if no errors, otherwise false
|
|
|
- */
|
|
|
- static bool 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;
|
|
|
- }
|
|
|
- }
|
|
|
/*
|
|
|
* Pilots Database Related Functions
|
|
|
*/
|
|
@@ -906,65 +691,7 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- * Settings Database Related Functions
|
|
|
- */
|
|
|
|
|
|
- /*!
|
|
|
- * \brief retreiveSetting Looks up a setting in the database and returns its value
|
|
|
- * \param setting_id
|
|
|
- * \return setting value
|
|
|
- */
|
|
|
- static QString retreiveSetting(QString setting_id)
|
|
|
- {
|
|
|
- QSqlQuery query;
|
|
|
- query.prepare("SELECT setting FROM settings WHERE setting_id = ?");
|
|
|
- query.addBindValue(setting_id);
|
|
|
- query.exec();
|
|
|
-
|
|
|
- QString setting = "-1";
|
|
|
-
|
|
|
- while(query.next()){
|
|
|
- setting = query.value(0).toString();
|
|
|
- }
|
|
|
- return setting;
|
|
|
- }
|
|
|
- /*!
|
|
|
- * \brief retreiveSettingInfo Looks up a setting in the database and returns its value and description
|
|
|
- * \param setting_id
|
|
|
- * \return {setting_id, setting, description}
|
|
|
- */
|
|
|
- static QVector<QString> retreiveSettingInfo(QString setting_id)
|
|
|
- {
|
|
|
- QSqlQuery query;
|
|
|
- query.prepare("SELECT * FROM settings WHERE setting_id = ?");
|
|
|
- query.addBindValue(setting_id);
|
|
|
- query.exec();
|
|
|
-
|
|
|
- QVector<QString> setting;
|
|
|
-
|
|
|
- while(query.next()){
|
|
|
- setting.append(query.value(0).toString());
|
|
|
- setting.append(query.value(1).toString());
|
|
|
- setting.append(query.value(2).toString());
|
|
|
- }
|
|
|
- return setting;
|
|
|
- }
|
|
|
- /*!
|
|
|
- * \brief storesetting Updates a stored setting in the database
|
|
|
- * \param setting_id
|
|
|
- * \param setting_value
|
|
|
- */
|
|
|
- static void storesetting(int setting_id, QString setting_value)
|
|
|
- {
|
|
|
- QSqlQuery query;
|
|
|
- query.prepare("UPDATE settings "
|
|
|
- "SET setting = ? "
|
|
|
- "WHERE setting_id = ?");
|
|
|
- query.addBindValue(setting_value);
|
|
|
- query.addBindValue(setting_id);
|
|
|
- query.exec();
|
|
|
- }
|
|
|
/*
|
|
|
* Obsolete Functions
|
|
|
*/
|