1 /* 2 * Copyright (c) 2021 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 NATIVE_RDB_RDB_OPEN_CALLBACK_H 17 #define NATIVE_RDB_RDB_OPEN_CALLBACK_H 18 19 #include "rdb_store.h" 20 21 namespace OHOS { 22 namespace NativeRdb { 23 24 class RdbOpenCallback { 25 public: 26 /** 27 * Called when the database associate whit this RdbStore is created with the first time. 28 * This is where the creation of tables and insert the initial data of tables should happen. 29 * 30 * param store The RdbStore object. 31 */ 32 virtual int OnCreate(RdbStore &rdbStore) = 0; 33 34 /** 35 * Called when the database associate whit this RdbStore needs to be upgrade. 36 * 37 * param store The RdbStore object. 38 * param oldVersion The old database version. 39 * param newVersion The new database version. 40 */ 41 virtual int OnUpgrade(RdbStore &rdbStore, int currentVersion, int targetVersion) = 0; 42 43 /** 44 * Called when the database associate whit this RdbStore needs to be downgrade. 45 * 46 * param store The RdbStore object. 47 * param oldVersion The old database version. 48 * param newVersion The new database version. 49 */ OnDowngrade(RdbStore & rdbStore,int currentVersion,int targetVersion)50 virtual int OnDowngrade(RdbStore &rdbStore, int currentVersion, int targetVersion) 51 { 52 return 0; 53 } 54 55 /** 56 * Called when the RdbStore has been opened. 57 * 58 * param store The RdbStore object. 59 */ OnOpen(RdbStore & rdbStore)60 virtual int OnOpen(RdbStore &rdbStore) 61 { 62 return 0; 63 } 64 onCorruption(std::string databaseFile)65 virtual int onCorruption(std::string databaseFile) 66 { 67 return 0; 68 } 69 }; 70 71 } // namespace NativeRdb 72 } // namespace OHOS 73 #endif 74