dbsettings.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "dbsettings.h"
  19. #include "dbman.cpp"
  20. /*
  21. * Settings Database Related Functions
  22. */
  23. /*!
  24. * \brief storesetting Updates a stored setting in the database
  25. * \param setting_id
  26. * \param setting_value
  27. */
  28. void dbSettings::storeSetting(int setting_id, QString setting_value)
  29. {
  30. QSqlQuery query;
  31. query.prepare("UPDATE settings "
  32. "SET setting = ? "
  33. "WHERE setting_id = ?");
  34. query.addBindValue(setting_value);
  35. query.addBindValue(setting_id);
  36. query.exec();
  37. }
  38. /*!
  39. * \brief retreiveSetting Looks up a setting in the database and returns its value
  40. * \param setting_id
  41. * \return setting value
  42. */
  43. QString dbSettings::retreiveSetting(int setting_id)
  44. {
  45. QSqlQuery query;
  46. query.prepare("SELECT setting FROM settings WHERE setting_id = ?");
  47. query.addBindValue(setting_id);
  48. query.exec();
  49. QString setting = "-1";
  50. while(query.next()){
  51. setting = query.value(0).toString();
  52. }
  53. return setting;
  54. }
  55. /*!
  56. * \brief retreiveSettingInfo Looks up a setting in the database and returns its value and description
  57. * \param setting_id
  58. * \return {setting_id, setting, description}
  59. */
  60. QVector<QString> dbSettings::retreiveSettingInfo(QString setting_id)
  61. {
  62. QSqlQuery query;
  63. query.prepare("SELECT * FROM settings WHERE setting_id = ?");
  64. query.addBindValue(setting_id);
  65. query.exec();
  66. QVector<QString> setting;
  67. while(query.next()){
  68. setting.append(query.value(0).toString());
  69. setting.append(query.value(1).toString());
  70. setting.append(query.value(2).toString());
  71. }
  72. return setting;
  73. }