| 1 | #cxx . . $ `<file>/src/sql/RecordingsDB.cpp`/include <kodi/AddonBase.h> |
| 2 | #include "RecordingsDB.h"cxx . . $ `<file>/src/sql/RecordingsDB.h`/ |
| 3 | |
| 4 | const int DB_VERSIONcxx . . $ DB_VERSION. = 1; |
| 5 | |
| 6 | class ProcessRecordingDBInfoRowCallbackcxx . . $ ProcessRecordingDBInfoRowCallback# : public ProcessRowCallbackcxx . . $ ProcessRowCallback# { |
| 7 | public: |
| 8 | virtual ~cxx . . $ ProcessRecordingDBInfoRowCallback#`~ProcessRecordingDBInfoRowCallback`(ced63f7c635d850d).ProcessRecordingDBInfoRowCallbackcxx . . $ ProcessRecordingDBInfoRowCallback#() { } |
| 9 | |
| 10 | void ProcessRowcxx . . $ ProcessRecordingDBInfoRowCallback#ProcessRow(1b656139e683501a).(sqlite3_stmt* stmt) { |
| 11 | m_resultcxx . . $ ProcessRecordingDBInfoRowCallback#m_result..recordingIdcxx . . $ RecordingDBInfo#recordingId. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). stdcxx . . $ std/::stringcxx . . $ std/string#(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0))); |
| 12 | m_resultcxx . . $ ProcessRecordingDBInfoRowCallback#m_result..playCountcxx . . $ RecordingDBInfo#playCount. = sqlite3_column_int(stmt, 1); |
| 13 | m_resultcxx . . $ ProcessRecordingDBInfoRowCallback#m_result..lastPlayedPositioncxx . . $ RecordingDBInfo#lastPlayedPosition. = sqlite3_column_int(stmt, 2); |
| 14 | m_resultcxx . . $ ProcessRecordingDBInfoRowCallback#m_result..lastSeencxx . . $ RecordingDBInfo#lastSeen. = sqlite3_column_int(stmt, 3); |
| 15 | } |
| 16 | |
| 17 | RecordingDBInfocxx . . $ RecordingDBInfo# Resultcxx . . $ ProcessRecordingDBInfoRowCallback#Result(5a96c69663ae12ab).() { |
| 18 | return m_resultcxx . . $ ProcessRecordingDBInfoRowCallback#m_result.; |
| 19 | } |
| 20 | |
| 21 | private: |
| 22 | RecordingDBInfocxx . . $ RecordingDBInfo# m_resultcxx . . $ ProcessRecordingDBInfoRowCallback#m_result.; |
| 23 | }; |
| 24 | |
| 25 | RecordingsDBcxx . . $ RecordingsDB#::RecordingsDBcxx . . $ RecordingsDB#RecordingsDB(8d4ab0a187bf9331).(stdcxx . . $ std/::stringcxx . . $ std/string# folder) |
| 26 | : SQLConnectioncxx . . $ SQLConnection#("REC-DB"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) { |
| 27 | stdcxx . . $ std/::stringcxx . . $ std/string# dbPath = folder +cxx . . $ std/operator+(40fc1db9226233c6). "recordings.sqlite"; |
| 28 | Opencxx . . $ SQLConnection#Open(f38201682fc79d0a).(dbPath); |
| 29 | if (!MigrateDbIfRequiredcxx . . $ RecordingsDB#MigrateDbIfRequired(c9857a73d68e59ba).()) { |
| 30 | 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.); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | RecordingsDBcxx . . $ RecordingsDB#::~cxx . . $ RecordingsDB#`~RecordingsDB`(ced63f7c635d850d).RecordingsDBcxx . . $ RecordingsDB#() { |
| 35 | } |
| 36 | |
| 37 | bool RecordingsDBcxx . . $ RecordingsDB#::MigrateDbIfRequiredcxx . . $ RecordingsDB#MigrateDbIfRequired(c9857a73d68e59ba).() { |
| 38 | int currentVersion = GetVersioncxx . . $ SQLConnection#GetVersion(b126dc7c1de90089).(); |
| 39 | while (currentVersion < DB_VERSIONcxx . . $ DB_VERSION.) { |
| 40 | if (currentVersion < 0) { |
| 41 | return false; |
| 42 | } |
| 43 | switch (currentVersion) { |
| 44 | case 0: |
| 45 | if (!Migrate0To1cxx . . $ RecordingsDB#Migrate0To1(c9857a73d68e59ba).()) { |
| 46 | return false; |
| 47 | } |
| 48 | break; |
| 49 | } |
| 50 | currentVersion = GetVersioncxx . . $ SQLConnection#GetVersion(b126dc7c1de90089).(); |
| 51 | } |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | bool RecordingsDBcxx . . $ RecordingsDB#::Migrate0To1cxx . . $ RecordingsDB#Migrate0To1(c9857a73d68e59ba).() { |
| 56 | 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).()); |
| 57 | stdcxx . . $ std/::stringcxx . . $ std/string# migrationScript = ""cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 58 | migrationScript +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). "create table RECORDING_INFO ("; |
| 59 | migrationScript +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). " RECORDING_ID text not null primary key,"; |
| 60 | migrationScript +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). " PLAY_COUNT integer not null,"; |
| 61 | migrationScript +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). " LAST_PLAYED_POSITION integer not null,"; |
| 62 | migrationScript +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). " LAST_SEEN integer not null"; |
| 63 | migrationScript +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). ")"; |
| 64 | if (!Executecxx . . $ SQLConnection#Execute(c9120223c4466434).(migrationScriptcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).)) { |
| 65 | return false; |
| 66 | } |
| 67 | return SetVersioncxx . . $ SQLConnection#SetVersion(83c267b20bac841a).(1); |
| 68 | } |
| 69 | |
| 70 | void RecordingsDBcxx . . $ RecordingsDB#::Cleanupcxx . . $ RecordingsDB#Cleanup(49f6e7a06ebc5aa8).() { |
| 71 | time_t now; |
| 72 | time(&now); |
| 73 | |
| 74 | if (!Executecxx . . $ SQLConnection#Execute(c9120223c4466434).("delete from RECORDING_INFO where LAST_SEEN < " +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(2c88ed78ff9aa4cf).(now - 3600))) { |
| 75 | kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_ERROR, "%s: Failed to clean db", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | |
| 80 | bool RecordingsDBcxx . . $ RecordingsDB#::Setcxx . . $ RecordingsDB#Set(888bf92eab5adb53).(RecordingDBInfocxx . . $ RecordingDBInfo#& recordingDBInfo) { |
| 81 | time(&recordingDBInfo.lastSeencxx . . $ RecordingDBInfo#lastSeen.); |
| 82 | stdcxx . . $ std/::stringcxx . . $ std/string# insert = "replace into RECORDING_INFO VALUES "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 83 | insert +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). "('" +cxx . . $ std/operator+(42c652dfebe55ad7). recordingDBInfo.recordingIdcxx . . $ RecordingDBInfo#recordingId. +cxx . . $ std/operator+(900ec9581c410ad9). "'," +cxx . . $ std/operator+(aa1c00e85b87da6b). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(3d81e17e7a87eecc).(recordingDBInfo.playCountcxx . . $ RecordingDBInfo#playCount.) +cxx . . $ std/operator+(900ec9581c410ad9). "," +cxx . . $ std/operator+(aa1c00e85b87da6b). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(3d81e17e7a87eecc).(recordingDBInfo.lastPlayedPositioncxx . . $ RecordingDBInfo#lastPlayedPosition.) +cxx . . $ std/operator+(900ec9581c410ad9). "," +cxx . . $ std/operator+(aa1c00e85b87da6b). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(2c88ed78ff9aa4cf).(recordingDBInfo.lastSeencxx . . $ RecordingDBInfo#lastSeen.) +cxx . . $ std/operator+(900ec9581c410ad9). ")"; |
| 84 | |
| 85 | if (!Executecxx . . $ SQLConnection#Execute(c9120223c4466434).(insertcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).)) { |
| 86 | 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).()); |
| 87 | return false; |
| 88 | } |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | RecordingDBInfocxx . . $ RecordingDBInfo# RecordingsDBcxx . . $ RecordingsDB#::Getcxx . . $ RecordingsDB#Get(e63488523ab54805).(stdcxx . . $ std/::stringcxx . . $ std/string# recordingId) { |
| 93 | ProcessRecordingDBInfoRowCallbackcxx . . $ ProcessRecordingDBInfoRowCallback# callback; |
| 94 | if (!Querycxx . . $ SQLConnection#Query(9956b7a086a48e12).("select * from RECORDING_INFO where RECORDING_ID = '" +cxx . . $ std/operator+(42c652dfebe55ad7). recordingId +cxx . . $ std/operator+(900ec9581c410ad9). "'", callback)) { |
| 95 | kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_ERROR, "%s: Failed to get info from db.", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 96 | } |
| 97 | RecordingDBInfocxx . . $ RecordingDBInfo# ret = callback.Resultcxx . . $ ProcessRecordingDBInfoRowCallback#Result(5a96c69663ae12ab).(); |
| 98 | ret.recordingIdcxx . . $ RecordingDBInfo#recordingId. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). recordingId; |
| 99 | return ret; |
| 100 | } |
| 101 |