~aleteoryx/muditaos

ref: d558e60a4d5bc26a982f0ba85f20631d7efac5df muditaos/module-services/service-db/agents/settings/Settings_queries.hpp -rw-r--r-- 3.7 KiB
d558e60a — Lefucjusz [CP-2013] Add time sync endpoint 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

namespace settings::Statements
{
    constexpr auto getValue = R"sql(
                         SELECT value
                         FROM settings_tab  AS ST
                         WHERE ST.path = '%q'
                         COLLATE NOCASE;
                         )sql";

    constexpr auto getAllValues = R"sql(
                                        SELECT path, value
                                        FROM settings_tab;
                                        )sql";

    constexpr auto checkPathExists = R"sql(
                        SELECT COUNT(value) AS PATH_EXISTS FROM  settings_tab AS ST
                        WHERE ST.path = '%q'
                        COLLATE NOCASE;
                        )sql";

    constexpr auto CheckValueExistsInDictionary = R"sql(
                        SELECT COUNT(value) AS VALUE_EXISTS_IN_DICT FROM  dictionary_tab AS DT
                        WHERE DT.path = '%q'
                        AND DT.value = '%q'
                        COLLATE NOCASE;
                        )sql";

    constexpr auto getDictValue = R"sql(
                        SELECT value
                        FROM dictionary_tab
                        WHERE path = '%q'
                        COLLATE NOCASE;
                        )sql";

    // no duplicates in dictionary (PK = path + value)
    constexpr auto addDictValue = R"sql(
                        INSERT OR IGNORE INTO dictionary_tab (path, value)
                        VALUES ( '%q', '%q')
                        )sql";

    constexpr auto checkSettingModified = R"sql(
                        SELECT COUNT(value) AS DATA_CHANGED FROM  settings_tab AS ST
                        WHERE ST.path = '%q'
                        AND ST.value != '%q' COLLATE NOCASE ;
                        )sql";

    constexpr auto insertValue = R"sql(
                        INSERT OR REPLACE INTO settings_tab (path, value) VALUES
                        ( '%q', '%q' ) ;
                        )sql";

    constexpr auto updateValue = R"sql(
                        UPDATE settings_tab SET value = '%q' WHERE path = '%q' ;
                        )sql";

    constexpr auto clearSettingsChangedTable = R"sql(
                        DELETE FROM settings_changed_tab;
                        )sql";

    constexpr auto clearSettingsChangedRow = R"sql(
                        DELETE FROM settings_changed_tab
                        WHERE path = '%q' ;
                        )sql";

    constexpr auto getSettingsChangeTable = R"sql(
                        SELECT path, value FROM settings_changed_tab
                        COLLATE NOCASE;
                        )sql";

    constexpr auto getSettingsChangeRow = R"sql(
                        SELECT path, value FROM settings_changed_tab
                        WHERE path = '%q'
                        COLLATE NOCASE;
                        )sql";

    constexpr auto setNotification = R"sql(
                        INSERT OR REPLACE INTO notifications_tab (path, service) VALUES
                        ( '%q' , '%q' ) ;
                        )sql";

    constexpr auto getAllNotifications = R"sql(
                        SELECT path, service
                        FROM notifications_tab  AS NT;
                        )sql";

    constexpr auto clearNotificationTable = R"sql(
                        DELETE FROM notifications_tab;
                        )sql";

    constexpr auto clearNotificationdRow = R"sql(
                        DELETE FROM notifications_tab
                        WHERE path = '%q' AND service = '%q';
                        )sql";

} // namespace settings::Statements