| 1 | #cxx . . $ `<file>/src/sql/ParameterDB.cpp`/include <kodi/AddonBase.h> |
| 2 | #include "ParameterDB.h"cxx . . $ `<file>/src/sql/ParameterDB.h`/ |
| 3 | |
| 4 | const int DB_VERSIONcxx . . $ DB_VERSION. = 1; |
| 5 | |
| 6 | class ProcessParameterRowCallbackcxx . . $ ProcessParameterRowCallback# : public ProcessRowCallbackcxx . . $ ProcessRowCallback# { |
| 7 | public: |
| 8 | virtual ~cxx . . $ ProcessParameterRowCallback#`~ProcessParameterRowCallback`(ced63f7c635d850d).ProcessParameterRowCallbackcxx . . $ ProcessParameterRowCallback#() { } |
| 9 | |
| 10 | void ProcessRowcxx . . $ ProcessParameterRowCallback#ProcessRow(1b656139e683501a).(sqlite3_stmt* stmt) { |
| 11 | m_resultcxx . . $ ProcessParameterRowCallback#m_result. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). stdcxx . . $ std/::stringcxx . . $ std/string#(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0))); |
| 12 | } |
| 13 | |
| 14 | stdcxx . . $ std/::stringcxx . . $ std/string# Resultcxx . . $ ProcessParameterRowCallback#Result(efd28698952f529a).() { |
| 15 | return m_resultcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).; |
| 16 | } |
| 17 | |
| 18 | private: |
| 19 | stdcxx . . $ std/::stringcxx . . $ std/string# m_resultcxx . . $ ProcessParameterRowCallback#m_result. = ""cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 20 | }; |
| 21 | |
| 22 | ParameterDBcxx . . $ ParameterDB#::ParameterDBcxx . . $ ParameterDB#ParameterDB(8d4ab0a187bf9331).(stdcxx . . $ std/::stringcxx . . $ std/string# folder) |
| 23 | : SQLConnectioncxx . . $ SQLConnection#("PARAMS-DB"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) { |
| 24 | stdcxx . . $ std/::stringcxx . . $ std/string# dbPath = folder +cxx . . $ std/operator+(40fc1db9226233c6). "parameter.sqlite"; |
| 25 | Opencxx . . $ SQLConnection#Open(f38201682fc79d0a).(dbPath); |
| 26 | if (!MigrateDbIfRequiredcxx . . $ ParameterDB#MigrateDbIfRequired(c9857a73d68e59ba).()) { |
| 27 | kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_ERROR, "%s: Failed to migrate DB to version: %i", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), DB_VERSIONcxx . . $ DB_VERSION.); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | ParameterDBcxx . . $ ParameterDB#::~cxx . . $ ParameterDB#`~ParameterDB`(ced63f7c635d850d).ParameterDBcxx . . $ ParameterDB#() { |
| 32 | } |
| 33 | |
| 34 | bool ParameterDBcxx . . $ ParameterDB#::MigrateDbIfRequiredcxx . . $ ParameterDB#MigrateDbIfRequired(c9857a73d68e59ba).() { |
| 35 | int currentVersion = GetVersioncxx . . $ SQLConnection#GetVersion(b126dc7c1de90089).(); |
| 36 | while (currentVersion < DB_VERSIONcxx . . $ DB_VERSION.) { |
| 37 | if (currentVersion < 0) { |
| 38 | return false; |
| 39 | } |
| 40 | switch (currentVersion) { |
| 41 | case 0: |
| 42 | if (!Migrate0To1cxx . . $ ParameterDB#Migrate0To1(c9857a73d68e59ba).()) { |
| 43 | return false; |
| 44 | } |
| 45 | break; |
| 46 | } |
| 47 | currentVersion = GetVersioncxx . . $ SQLConnection#GetVersion(b126dc7c1de90089).(); |
| 48 | } |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | bool ParameterDBcxx . . $ ParameterDB#::Migrate0To1cxx . . $ ParameterDB#Migrate0To1(c9857a73d68e59ba).() { |
| 53 | kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_INFO, "%s: Migrate to version 1.", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 54 | stdcxx . . $ std/::stringcxx . . $ std/string# migrationScript = ""cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 55 | migrationScript +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). "create table PARAMETER ("; |
| 56 | migrationScript +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). " KEY text not null primary key,"; |
| 57 | migrationScript +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). " VALUE text not null"; |
| 58 | migrationScript +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). ")"; |
| 59 | if (!Executecxx . . $ SQLConnection#Execute(c9120223c4466434).(migrationScriptcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).)) { |
| 60 | return false; |
| 61 | } |
| 62 | return SetVersioncxx . . $ SQLConnection#SetVersion(83c267b20bac841a).(1); |
| 63 | } |
| 64 | |
| 65 | bool ParameterDBcxx . . $ ParameterDB#::Setcxx . . $ ParameterDB#Set(bcc390dd55b8c29d).(stdcxx . . $ std/::stringcxx . . $ std/string# key, stdcxx . . $ std/::stringcxx . . $ std/string# value) { |
| 66 | stdcxx . . $ std/::stringcxx . . $ std/string# insert = "replace into PARAMETER VALUES "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 67 | insert +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). "('" +cxx . . $ std/operator+(42c652dfebe55ad7). key +cxx . . $ std/operator+(900ec9581c410ad9). "','" +cxx . . $ std/operator+(db5dc2ea912c6495). value +cxx . . $ std/operator+(900ec9581c410ad9). "')"; |
| 68 | |
| 69 | if (!Executecxx . . $ SQLConnection#Execute(c9120223c4466434).(insertcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).)) { |
| 70 | kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_ERROR, "%s: Failed to insert", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 71 | return false; |
| 72 | } |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | stdcxx . . $ std/::stringcxx . . $ std/string# ParameterDBcxx . . $ ParameterDB#::Getcxx . . $ ParameterDB#Get(265576c0e07c2ac8).(stdcxx . . $ std/::stringcxx . . $ std/string# key) { |
| 77 | ProcessParameterRowCallbackcxx . . $ ProcessParameterRowCallback# callback; |
| 78 | if (!Querycxx . . $ SQLConnection#Query(9956b7a086a48e12).("select VALUE from PARAMETER where KEY = '" +cxx . . $ std/operator+(42c652dfebe55ad7). key +cxx . . $ std/operator+(900ec9581c410ad9). "'", callback)) { |
| 79 | kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_ERROR, "%s: Failed to get parameter from db.", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 80 | } |
| 81 | return callback.Resultcxx . . $ ProcessParameterRowCallback#Result(efd28698952f529a).(); |
| 82 | } |
| 83 |