aircraft.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. *openPilot Log - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020 Felix Turowsky
  4. *
  5. *This program is free software: you can redistribute it and/or modify
  6. *it under the terms of the GNU General Public License as published by
  7. *the Free Software Foundation, either version 3 of the License, or
  8. *(at your option) any later version.
  9. *
  10. *This program is distributed in the hope that it will be useful,
  11. *but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. *GNU General Public License for more details.
  14. *
  15. *You should have received a copy of the GNU General Public License
  16. *along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #include "aircraft.h"
  19. // Debug Makro
  20. #define DEB(expr) \
  21. qDebug() << __PRETTY_FUNCTION__ << "\t" << expr
  22. Aircraft::Aircraft(int tail_id)
  23. {
  24. //retreive database layout
  25. const auto dbContent = DbInfo();
  26. auto table = QLatin1String("tails");
  27. //Check database for row id
  28. QString statement = "SELECT COUNT(*) FROM " + table + " WHERE _rowid_=" + QString::number(tail_id);
  29. QSqlQuery q(statement);
  30. q.next();
  31. int rows = q.value(0).toInt();
  32. if (rows == 0) {
  33. DEB("No Entry found for row id: " << tail_id );
  34. position.second = 0;
  35. } else {
  36. DEB("Retreiving data for row id: " << tail_id);
  37. QString statement = "SELECT * FROM " + table + " WHERE _rowid_=" + QString::number(tail_id);
  38. DEB("Executing SQL...");
  39. DEB(statement);
  40. QSqlQuery q(statement);
  41. q.exec();
  42. q.next();
  43. for (int i = 0; i < dbContent.format.value(table).length(); i++) {
  44. data.insert(dbContent.format.value(table)[i], q.value(i).toString());
  45. }
  46. QString error = q.lastError().text();
  47. if (error.length() > 2) {
  48. DEB("Error: " << q.lastError().text());
  49. position.second = 0;
  50. position.first = "invalid";
  51. } else {
  52. position.second = tail_id;
  53. position.first = "tails";
  54. }
  55. }
  56. }