• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef DATA_STORAGE_RDB_SMS_MMS_HELPER_H
17 #define DATA_STORAGE_RDB_SMS_MMS_HELPER_H
18 
19 #include <stdint.h>
20 
21 #include "iosfwd"
22 #include "memory"
23 #include "datashare_values_bucket.h"
24 #include "rdb_base_helper.h"
25 #include "string"
26 #include "vector"
27 
28 namespace OHOS {
29 namespace NativeRdb {
30 class ResultSet;
31 class ValuesBucket;
32 } // namespace NativeRdb
33 namespace Telephony {
34 class RdbSmsMmsHelper : public RdbBaseHelper {
35 public:
36     RdbSmsMmsHelper();
37     ~RdbSmsMmsHelper() = default;
38 
39     /**
40      * Delete sms_mms_info table data of the previous 30 days
41      *
42      * @return 0 is succeed else failed
43      */
44     int32_t DeleteDataByThirty();
45 
46     /**
47      * Insert sms_mms_info table data
48      *
49      * @param id id
50      * @param value Table field data
51      * @return 0 is succeed else failed
52      */
53     int32_t InsertSmsMmsInfo(int64_t &id, const NativeRdb::ValuesBucket &value);
54 
55     /**
56      * Batch Insert sms_mms_info table data
57      *
58      * @param id id
59      * @param values Table field data
60      * @return 0 is succeed else failed
61      */
62     int32_t BatchInsertSmsMmsInfo(int64_t &id, const std::vector<DataShare::DataShareValuesBucket> &values);
63 
64     /**
65      * Commit the transaction action
66      *
67      * @return 0 is succeed else failed
68      */
69     int CommitTransactionAction();
70 
71     /**
72      * Statistics sms_mms_info table unread quantity
73      *
74      * @return unique_ptr<NativeRdb::ResultSet>
75      */
76     std::shared_ptr<NativeRdb::ResultSet> StatisticsUnRead();
77 
78     /**
79      * Query sms_mms_info table max group_id
80      *
81      * @return  unique_ptr<NativeRdb::ResultSet>
82      */
83     std::shared_ptr<NativeRdb::ResultSet> QueryMaxGroupId();
84 
85     /**
86      * Update dataBase path
87      *
88      * @param path path
89      */
90     void UpdateDbPath(const std::string &path);
91 
92     /**
93      * Init dataBase
94      *
95      * @return 0 is succeed else failed
96      */
97     int Init();
98 
99 private:
100     /**
101      * Create SmsMmsInfo table
102      *
103      * @param createTableStr Create table statement
104      */
105     void CreateSmsMmsInfoTableStr(std::string &createTableStr);
106 
107     /**
108      * Create SmsSubsection table
109      *
110      * @param createTableStr Create table statement
111      */
112     void CreateSmsSubsectionTableStr(std::string &createTableStr);
113 
114     /**
115      * Create MmsProtocol table
116      *
117      * @param createTableStr Create table statement
118      */
119     void CreateMmsProtocolTableStr(std::string &createTableStr);
120 
121     /**
122      * Create MmsPart table
123      *
124      * @param createTableStr Create table statement
125      */
126     void CreateMmsPartTableStr(std::string &createTableStr);
127 
128     /**
129      * Create Session table
130      *
131      * @param createTableStr Create table statement
132      */
133     void CreateSessionTableStr(std::string &createTableStr);
134 
135     /**
136      * Create MmsPdu table
137      * @param createTableStr indicates Create table statement
138      */
139     void CreateMmsPduTableStr(std::string &createTableStr);
140 
141 private:
142     const std::string DB_NAME = "sms_mms.db";
143     std::string dbPath_ = FOLDER_PATH + DB_NAME;
144     const int VERSION = 1;
145 };
146 } // namespace Telephony
147 } // namespace OHOS
148 #endif // DATA_STORAGE_RDB_SMS_MMS_HELPER_H
149