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