Debian Codegraph @

src/sql/SQLConnection.cpp

raw symbols SCIP
1 #cxx . . $ `<file>/src/sql/SQLConnection.cpp`/include <kodi/AddonBase.h>
2 #include "SQLConnection.h"cxx . . $ `<file>/src/sql/SQLConnection.h`/
3
4 class ProcessSingleIntRowCallbackcxx . . $ ProcessSingleIntRowCallback# : public ProcessRowCallbackcxx . . $ ProcessRowCallback# {
5 public:
6 virtual ~cxx . . $ ProcessSingleIntRowCallback#`~ProcessSingleIntRowCallback`(ced63f7c635d850d).ProcessSingleIntRowCallbackcxx . . $ ProcessSingleIntRowCallback#() { }
7
8 void ProcessRowcxx . . $ ProcessSingleIntRowCallback#ProcessRow(1b656139e683501a).(sqlite3_stmt* stmt) {
9 m_resultcxx . . $ ProcessSingleIntRowCallback#m_result. = sqlite3_column_int(stmt, 0);
10 }
11
12 int GetResultcxx . . $ ProcessSingleIntRowCallback#GetResult(b126dc7c1de90089).() {
13 return m_resultcxx . . $ ProcessSingleIntRowCallback#m_result.;
14 }
15
16 private:
17 int m_resultcxx . . $ ProcessSingleIntRowCallback#m_result. = -1;
18 };
19
20 class NoopRowCallbackcxx . . $ NoopRowCallback# : public ProcessRowCallbackcxx . . $ ProcessRowCallback# {
21 public:
22 void ProcessRowcxx . . $ NoopRowCallback#ProcessRow(1b656139e683501a).(sqlite3_stmt* stmt) {
23 }
24 };
25
26
27 SQLConnectioncxx . . $ SQLConnection#::SQLConnectioncxx . . $ SQLConnection#SQLConnection(8d4ab0a187bf9331).(stdcxx . . $ std/::stringcxx . . $ std/string# name):
28 m_dbcxx . . $ SQLConnection#m_db.(nullptr),
29 m_namecxx . . $ SQLConnection#m_name.(name) {
30 }
31
32 SQLConnectioncxx . . $ SQLConnection#::~cxx . . $ SQLConnection#`~SQLConnection`(ced63f7c635d850d).SQLConnectioncxx . . $ SQLConnection#() {
33 sqlite3_close(m_dbcxx . . $ SQLConnection#m_db.);
34 }
35
36 bool SQLConnectioncxx . . $ SQLConnection#::Opencxx . . $ SQLConnection#Open(f38201682fc79d0a).(stdcxx . . $ std/::stringcxx . . $ std/string#& file) {
37 int rc = sqlite3_open(file.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), &m_dbcxx . . $ SQLConnection#m_db.);
38 if(rc) {
39 kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_ERROR, "%s: Can't open database: %s", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), sqlite3_errmsg(m_dbcxx . . $ SQLConnection#m_db.));
40 return false;
41 }
42 sqlite3_exec(m_dbcxx . . $ SQLConnection#m_db., "PRAGMA synchronous = OFF;", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
43 sqlite3_exec(m_dbcxx . . $ SQLConnection#m_db., "PRAGMA journal_mode = OFF;", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
44 EnsureVersionTablecxx . . $ SQLConnection#EnsureVersionTable(c9857a73d68e59ba).();
45 return true;
46 }
47
48 bool SQLConnectioncxx . . $ SQLConnection#::Querycxx . . $ SQLConnection#Query(9956b7a086a48e12).(stdcxx . . $ std/::stringcxx . . $ std/string# query, ProcessRowCallbackcxx . . $ ProcessRowCallback#& callback) {
49 sqlite3_stmt* stmt;
50 int ret = sqlite3_prepare(m_dbcxx . . $ SQLConnection#m_db., query.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), query.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).(), &stmt, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
51
52 if (ret != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) {
53 sqlite3_finalize(stmt);
54 kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_ERROR, "%s: Query failed: %s", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), sqlite3_errmsg(m_dbcxx . . $ SQLConnection#m_db.));
55 return false;
56 }
57
58 bool err = false;
59 bool done = false;
60 while (!done) {
61 switch (sqlite3_step(stmt)) {
62 case SQLITE_ROWcxx . . $ `<external>/2400532043262193228/sqlite3.h:479:9`!:
63 callback.ProcessRowcxx . . $ ProcessRowCallback#ProcessRow(1b656139e683501a).(stmt);
64 break;
65
66 case SQLITE_DONEcxx . . $ `<external>/2400532043262193228/sqlite3.h:480:9`!:
67 done = true;
68 break;
69
70 default:
71 kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_ERROR, "%s: Query failed.", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
72 err = true;
73 done = true;
74 }
75 }
76
77 sqlite3_finalize(stmt);
78 return !err;
79 }
80
81 bool SQLConnectioncxx . . $ SQLConnection#::Executecxx . . $ SQLConnection#Execute(c9120223c4466434).(stdcxx . . $ std/::stringcxx . . $ std/string# query) {
82 NoopRowCallbackcxx . . $ NoopRowCallback# callback;
83 return Querycxx . . $ SQLConnection#Query(9956b7a086a48e12).(querycxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)., callback);
84 }
85
86 bool SQLConnectioncxx . . $ SQLConnection#::EnsureVersionTablecxx . . $ SQLConnection#EnsureVersionTable(c9857a73d68e59ba).() {
87 ProcessSingleIntRowCallbackcxx . . $ ProcessSingleIntRowCallback# callback;
88 if (!Querycxx . . $ SQLConnection#Query(9956b7a086a48e12).("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='SCHEMA_VERSION'"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., callback)) {
89 return false;
90 }
91
92 if (callback.GetResultcxx . . $ ProcessSingleIntRowCallback#GetResult(b126dc7c1de90089).() == 0) {
93 kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_INFO, "%s: SCHEMA_VERSION does not exist. Creating Table.", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
94 if (!Executecxx . . $ SQLConnection#Execute(c9120223c4466434).("create table SCHEMA_VERSION (VERSION integer NOT NULL)"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) {
95 return false;
96 }
97 return Executecxx . . $ SQLConnection#Execute(c9120223c4466434).("insert into SCHEMA_VERSION VALUES (0)"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
98 }
99
100 return true;
101 }
102
103 int SQLConnectioncxx . . $ SQLConnection#::GetVersioncxx . . $ SQLConnection#GetVersion(b126dc7c1de90089).() {
104 ProcessSingleIntRowCallbackcxx . . $ ProcessSingleIntRowCallback# callback;
105 if (!Querycxx . . $ SQLConnection#Query(9956b7a086a48e12).("select VERSION from SCHEMA_VERSION"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., callback)) {
106 kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_INFO, "%s: Failed to get current version.", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).());
107 return -1;
108 }
109 int currentVersion = callback.GetResultcxx . . $ ProcessSingleIntRowCallback#GetResult(b126dc7c1de90089).();
110 kodicxx . . $ kodi/::Logcxx . . $ kodi/Log(f92fde7d03deae81).(ADDON_LOG_INFO, "%s: Current version: %d", m_namecxx . . $ SQLConnection#m_name..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), currentVersion);
111 return currentVersion;
112 }
113
114 bool SQLConnectioncxx . . $ SQLConnection#::SetVersioncxx . . $ SQLConnection#SetVersion(83c267b20bac841a).(int newVersion) {
115 return Executecxx . . $ SQLConnection#Execute(c9120223c4466434).("update SCHEMA_VERSION set VERSION = " +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(3d81e17e7a87eecc).(newVersion));
116 }
117
118 void SQLConnectioncxx . . $ SQLConnection#::BeginTransactioncxx . . $ SQLConnection#BeginTransaction(49f6e7a06ebc5aa8).() {
119 sqlite3_exec(m_dbcxx . . $ SQLConnection#m_db., "BEGIN TRANSACTION;", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
120 }
121
122 void SQLConnectioncxx . . $ SQLConnection#::EndTransactioncxx . . $ SQLConnection#EndTransaction(49f6e7a06ebc5aa8).() {
123 sqlite3_exec(m_dbcxx . . $ SQLConnection#m_db., "END TRANSACTION;", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
124 }
125