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 "edm_rdb_open_callback.h"
17 
18 #include "edm_rdb_filed_const.h"
19 #include "edm_log.h"
20 
21 namespace OHOS {
22 namespace EDM {
23 constexpr int32_t EDM_RDB_VERSION_TWO = 2;
24 constexpr int32_t EDM_RDB_VERSION_THREE = 3;
OnCreate(NativeRdb::RdbStore & rdbStore)25 int32_t EdmRdbOpenCallback::OnCreate(NativeRdb::RdbStore &rdbStore)
26 {
27     EDMLOGD("EdmRdbOpenCallback OnCreate : database create.");
28     return NativeRdb::E_OK;
29 }
30 
OnUpgrade(NativeRdb::RdbStore & rdbStore,int currentVersion,int targetVersion)31 int32_t EdmRdbOpenCallback::OnUpgrade(NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion)
32 {
33     EDMLOGD("EdmRdbOpenCallback OnUpgrade : database upgrade. currentVersion = %{public}d, newVersion = %{public}d",
34         currentVersion, targetVersion);
35     if (currentVersion < EDM_RDB_VERSION_TWO && targetVersion >= EDM_RDB_VERSION_TWO) {
36         rdbStore.ExecuteSql("ALTER TABLE " + EdmRdbFiledConst::ADMIN_POLICIES_RDB_TABLE_NAME + " ADD COLUMN " +
37             EdmRdbFiledConst::FILED_IS_DEBUG + " INTEGER DEFAULT 0;");
38     }
39     if (currentVersion < EDM_RDB_VERSION_THREE && targetVersion >= EDM_RDB_VERSION_THREE) {
40         rdbStore.ExecuteSql("ALTER TABLE " + EdmRdbFiledConst::ADMIN_POLICIES_RDB_TABLE_NAME + " ADD COLUMN " +
41             EdmRdbFiledConst::FILED_ACCESSIBLE_POLICIES + " TEXT;");
42     }
43     return NativeRdb::E_OK;
44 }
45 } // namespace EDM
46 } // namespace OHOS