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_TAB_OLD_PHOTOS_EVENT_HANDLER_H 17 #define OHOS_MEDIA_TAB_OLD_PHOTOS_EVENT_HANDLER_H 18 19 #include <string> 20 #include <vector> 21 22 #include "rdb_store.h" 23 #include "rdb_open_event.h" 24 25 namespace OHOS::Media { 26 class TabOldPhotosTableEventHandler : 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 CreateTable(NativeRdb::RdbStore &store); 33 int32_t CreateIndex(NativeRdb::RdbStore &store); 34 int32_t CreateTrigger(NativeRdb::RdbStore &store); 35 36 private: 37 const std::string TABLE_NAME = "tab_old_photos"; 38 const std::string CREATE_TABLE_SQL = "\ 39 CREATE TABLE IF NOT EXISTS tab_old_photos ( \ 40 file_id INTEGER PRIMARY KEY, \ 41 data TEXT, \ 42 old_file_id INTEGER, \ 43 old_data TEXT \ 44 );"; 45 const std::string TRIGGER_DELETE_CLEAR_TAB_OLD_PHOTOS = "\ 46 CREATE TRIGGER IF NOT EXISTS delete_clear_tab_photos \ 47 AFTER DELETE \ 48 ON Photos \ 49 BEGIN \ 50 DELETE FROM tab_old_photos \ 51 WHERE file_id = OLD.file_id; \ 52 END;"; 53 const std::string INDEX_OLD_FILE_ID = "\ 54 CREATE INDEX IF NOT EXISTS idx_old_file_id_on_tab_old_photos ON tab_old_photos ( \ 55 old_file_id \ 56 );"; 57 const std::string INDEX_OLD_DATA = "\ 58 CREATE INDEX IF NOT EXISTS idx_old_data_on_tab_old_photos ON tab_old_photos ( \ 59 old_data \ 60 );"; 61 const std::string INDEX_FILE_ID = "\ 62 CREATE INDEX IF NOT EXISTS idx_file_id_on_tab_old_photos ON tab_old_photos ( \ 63 file_id \ 64 );"; 65 const std::vector<std::string> CREATE_INDEX_SQLS = {INDEX_OLD_FILE_ID, INDEX_OLD_DATA, INDEX_FILE_ID}; 66 }; 67 } // namespace OHOS::Media 68 #endif // OHOS_MEDIA_TAB_OLD_PHOTOS_EVENT_HANDLER_H