1 /*
2  * Copyright (C) 2024 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 OHOS_MEDIA_ALBUM_PLUGIN_TABLE_EVENT_HANDLER_H
17 #define OHOS_MEDIA_ALBUM_PLUGIN_TABLE_EVENT_HANDLER_H
18 
19 #include <string>
20 
21 #include "rdb_store.h"
22 #include "rdb_open_event.h"
23 
24 namespace OHOS::Media {
25 
26 class AlbumPluginTableEventHandler : public IRdbOpenEvent {
27 public:
28     int32_t OnCreate(NativeRdb::RdbStore &store) override;
29     int32_t OnUpgrade(NativeRdb::RdbStore &store, int oldVersion, int newVersion) override;
30 
31 private:
32     int32_t InitiateData(NativeRdb::RdbStore &store);
33     bool IsTableCreated(NativeRdb::RdbStore &store, const std::string &tableName);
34     int32_t GetAlbumPluginDataCount(NativeRdb::RdbStore &store);
35 
36 private:
37     const std::string TABLE_NAME = "album_plugin";
38     const std::string CREATE_TABLE_SQL = "\
39         CREATE TABLE IF NOT EXISTS album_plugin \
40         ( \
41             lpath TEXT, \
42             album_name TEXT, \
43             album_name_en TEXT, \
44             bundle_name TEXT, \
45             cloud_id TEXT, \
46             dual_album_name TEXT, \
47             priority INT \
48         );";
49     const std::string DROP_TABLE_SQL = "DROP TABLE IF EXISTS album_plugin;";
50     const std::string INSERT_DATA_SQL = "\
51         INSERT INTO album_plugin( \
52                 lpath, \
53                 album_name, \
54                 album_name_en, \
55                 bundle_name, \
56                 cloud_id, \
57                 dual_album_name, \
58                 priority \
59         ) VALUES (?, ?, ?, ?, ?, ?, ?);";
60     const std::string SQL_SELECT_DATA_COUNT = "SELECT COUNT(1) AS count FROM album_plugin;";
61 };
62 }  // namespace OHOS::Media
63 #endif  // OHOS_MEDIA_ALBUM_PLUGIN_TABLE_EVENT_HANDLER_H