1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "reminder_table.h"
17
18namespace OHOS {
19namespace Notification {
20// reminder base table
21const std::string ReminderBaseTable::TABLE_NAME = "reminder_base";
22const std::string ReminderBaseTable::REMINDER_ID = "reminder_id";
23const std::string ReminderBaseTable::PACKAGE_NAME = "package_name";
24const std::string ReminderBaseTable::USER_ID = "user_id";
25const std::string ReminderBaseTable::UID = "uid";
26const std::string ReminderBaseTable::SYSTEM_APP = "system_app";
27const std::string ReminderBaseTable::REMINDER_TYPE = "reminder_type";
28const std::string ReminderBaseTable::REMINDER_TIME = "reminder_time";
29const std::string ReminderBaseTable::TRIGGER_TIME = "trigger_time";
30const std::string ReminderBaseTable::TIME_INTERVAL = "time_interval";
31const std::string ReminderBaseTable::SNOOZE_TIMES = "snooze_times";
32const std::string ReminderBaseTable::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times";
33const std::string ReminderBaseTable::RING_DURATION = "ring_duration";
34const std::string ReminderBaseTable::IS_EXPIRED = "is_expired";
35const std::string ReminderBaseTable::STATE = "state";
36const std::string ReminderBaseTable::ACTION_BUTTON_INFO = "button_info";
37const std::string ReminderBaseTable::CUSTOM_BUTTON_URI = "custom_button_uri";
38const std::string ReminderBaseTable::SLOT_ID = "slot_id";
39const std::string ReminderBaseTable::SNOOZE_SLOT_ID = "snooze_slot_id";
40const std::string ReminderBaseTable::NOTIFICATION_ID = "notification_id";
41const std::string ReminderBaseTable::TITLE = "title";
42const std::string ReminderBaseTable::CONTENT = "content";
43const std::string ReminderBaseTable::SNOOZE_CONTENT = "snooze_content";
44const std::string ReminderBaseTable::EXPIRED_CONTENT = "expired_content";
45const std::string ReminderBaseTable::WANT_AGENT = "want_agent";
46const std::string ReminderBaseTable::MAX_SCREEN_WANT_AGENT = "max_screen_want_agent";
47const std::string ReminderBaseTable::TAP_DISMISSED = "tap_dismissed";
48const std::string ReminderBaseTable::AUTO_DELETED_TIME = "auto_deleted_time";
49const std::string ReminderBaseTable::GROUP_ID = "group_id";
50const std::string ReminderBaseTable::CUSTOM_RING_URI = "custom_ring_uri";
51const std::string ReminderBaseTable::CREATOR_BUNDLE_NAME = "creator_bundle_name";
52const std::string ReminderBaseTable::CREATOR_UID = "creator_uid";
53
54// reminder alarm table
55const std::string ReminderAlarmTable::TABLE_NAME = "reminder_alarm";
56const std::string ReminderAlarmTable::REMINDER_ID = "reminder_id";
57const std::string ReminderAlarmTable::ALARM_HOUR = "alarm_hour";
58const std::string ReminderAlarmTable::ALARM_MINUTE = "alarm_minute";
59const std::string ReminderAlarmTable::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week";
60
61// reminder calendar table
62const std::string ReminderCalendarTable::TABLE_NAME = "reminder_calendar";
63const std::string ReminderCalendarTable::REMINDER_ID = "reminder_id";
64const std::string ReminderCalendarTable::FIRST_DESIGNATE_YEAR = "first_designate_year";
65const std::string ReminderCalendarTable::FIRST_DESIGNATE_MONTH = "first_designate_month";
66const std::string ReminderCalendarTable::FIRST_DESIGNATE_DAY = "first_designate_day";
67const std::string ReminderCalendarTable::CALENDAR_DATE_TIME = "calendar_date_time";
68const std::string ReminderCalendarTable::CALENDAR_END_DATE_TIME = "calendar_end_date_time";
69const std::string ReminderCalendarTable::REPEAT_DAYS = "repeat_days";
70const std::string ReminderCalendarTable::REPEAT_MONTHS = "repeat_months";
71const std::string ReminderCalendarTable::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week";
72const std::string ReminderCalendarTable::RRULE_WANT_AGENT = "rrule_want_agent";
73const std::string ReminderCalendarTable::EXCLUDE_DATES = "exclude_dates";
74const std::string ReminderCalendarTable::CALENDAR_LAST_DATE_TIME = "calendar_last_date_time";
75
76// reminder timer table
77const std::string ReminderTimerTable::TABLE_NAME = "reminder_timer";
78const std::string ReminderTimerTable::REMINDER_ID = "reminder_id";
79const std::string ReminderTimerTable::TRIGGER_SECOND = "trigger_second";
80const std::string ReminderTimerTable::START_DATE_TIME = "start_date_time";
81const std::string ReminderTimerTable::END_DATE_TIME = "end_date_time";
82
83std::string ReminderBaseTable::ADD_COLUMNS = "";
84std::string ReminderBaseTable::SELECT_COLUMNS = "";
85
86std::string ReminderAlarmTable::ADD_COLUMNS = "";
87std::string ReminderAlarmTable::SELECT_COLUMNS = "";
88
89std::string ReminderCalendarTable::ADD_COLUMNS = "";
90std::string ReminderCalendarTable::SELECT_COLUMNS = "";
91
92std::string ReminderTimerTable::ADD_COLUMNS = "";
93std::string ReminderTimerTable::SELECT_COLUMNS = "";
94
95static inline void AddColumn(const std::string& name, const std::string& type, std::string& sqlOfColumns,
96    std::string& columns)
97{
98    columns.append(name).append(",");
99    sqlOfColumns.append(name).append(" ");
100    sqlOfColumns.append(type).append(", ");
101}
102
103static inline void AddColumnEnd(const std::string& name, const std::string& type, std::string& sqlOfColumns,
104    std::string& columns)
105{
106    columns.append(name);
107    sqlOfColumns.append(name).append(" ");
108    sqlOfColumns.append(type);
109}
110
111void ReminderBaseTable::InitDbColumns()
112{
113    AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", ADD_COLUMNS, SELECT_COLUMNS);
114    AddColumn(PACKAGE_NAME, "TEXT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
115    AddColumn(USER_ID, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
116    AddColumn(UID, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
117    AddColumn(SYSTEM_APP, "TEXT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
118    AddColumn(REMINDER_TYPE, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
119    AddColumn(REMINDER_TIME, "BIGINT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
120    AddColumn(TRIGGER_TIME, "BIGINT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
121    AddColumn(TIME_INTERVAL, "BIGINT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
122    AddColumn(SNOOZE_TIMES, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
123    AddColumn(DYNAMIC_SNOOZE_TIMES, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
124    AddColumn(RING_DURATION, "BIGINT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
125    AddColumn(IS_EXPIRED, "TEXT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
126    AddColumn(STATE, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
127    AddColumn(ACTION_BUTTON_INFO, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
128    AddColumn(CUSTOM_BUTTON_URI, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
129    AddColumn(SLOT_ID, "INT", ADD_COLUMNS, SELECT_COLUMNS);
130    AddColumn(SNOOZE_SLOT_ID, "INT", ADD_COLUMNS, SELECT_COLUMNS);
131    AddColumn(NOTIFICATION_ID, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
132    AddColumn(TITLE, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
133    AddColumn(CONTENT, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
134    AddColumn(SNOOZE_CONTENT, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
135    AddColumn(EXPIRED_CONTENT, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
136    AddColumn(WANT_AGENT, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
137    AddColumn(MAX_SCREEN_WANT_AGENT, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
138    AddColumn(TAP_DISMISSED, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
139    AddColumn(AUTO_DELETED_TIME, "BIGINT", ADD_COLUMNS, SELECT_COLUMNS);
140    AddColumn(GROUP_ID, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
141    AddColumn(CUSTOM_RING_URI, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
142    AddColumn(CREATOR_BUNDLE_NAME, "TEXT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
143    AddColumnEnd(CREATOR_UID, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
144}
145
146void ReminderAlarmTable::InitDbColumns()
147{
148    AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", ADD_COLUMNS, SELECT_COLUMNS);
149    AddColumn(ALARM_HOUR, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
150    AddColumn(ALARM_MINUTE, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
151    AddColumnEnd(REPEAT_DAYS_OF_WEEK, "INT", ADD_COLUMNS, SELECT_COLUMNS);
152}
153
154void ReminderCalendarTable::InitDbColumns()
155{
156    AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", ADD_COLUMNS, SELECT_COLUMNS);
157    AddColumn(FIRST_DESIGNATE_YEAR, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
158    AddColumn(FIRST_DESIGNATE_MONTH, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
159    AddColumn(FIRST_DESIGNATE_DAY, "INT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
160    AddColumn(CALENDAR_DATE_TIME, "BIGINT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
161    AddColumn(CALENDAR_END_DATE_TIME, "BIGINT", ADD_COLUMNS, SELECT_COLUMNS);
162    AddColumn(REPEAT_DAYS, "INT", ADD_COLUMNS, SELECT_COLUMNS);
163    AddColumn(REPEAT_MONTHS, "INT", ADD_COLUMNS, SELECT_COLUMNS);
164    AddColumn(REPEAT_DAYS_OF_WEEK, "INT", ADD_COLUMNS, SELECT_COLUMNS);
165    AddColumn(RRULE_WANT_AGENT, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
166    AddColumn(EXCLUDE_DATES, "TEXT", ADD_COLUMNS, SELECT_COLUMNS);
167    AddColumnEnd(CALENDAR_LAST_DATE_TIME, "BIGINT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
168}
169
170void ReminderTimerTable::InitDbColumns()
171{
172    AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", ADD_COLUMNS, SELECT_COLUMNS);
173    AddColumn(TRIGGER_SECOND, "BIGINT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
174    AddColumn(START_DATE_TIME, "BIGINT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
175    AddColumnEnd(END_DATE_TIME, "BIGINT NOT NULL", ADD_COLUMNS, SELECT_COLUMNS);
176}
177}
178}
179