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;
25 constexpr int32_t EDM_RDB_VERSION_FOUR = 4;
OnCreate(NativeRdb::RdbStore & rdbStore)26 int32_t EdmRdbOpenCallback::OnCreate(NativeRdb::RdbStore &rdbStore)
27 {
28 EDMLOGD("EdmRdbOpenCallback OnCreate : database create.");
29 return NativeRdb::E_OK;
30 }
31
OnUpgrade(NativeRdb::RdbStore & rdbStore,int currentVersion,int targetVersion)32 int32_t EdmRdbOpenCallback::OnUpgrade(NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion)
33 {
34 EDMLOGD("EdmRdbOpenCallback OnUpgrade : database upgrade. currentVersion = %{public}d, newVersion = %{public}d",
35 currentVersion, targetVersion);
36 if (currentVersion < EDM_RDB_VERSION_TWO && targetVersion >= EDM_RDB_VERSION_TWO) {
37 rdbStore.ExecuteSql("ALTER TABLE " + EdmRdbFiledConst::ADMIN_POLICIES_RDB_TABLE_NAME + " ADD COLUMN " +
38 EdmRdbFiledConst::FILED_IS_DEBUG + " INTEGER DEFAULT 0;");
39 }
40 if (currentVersion < EDM_RDB_VERSION_THREE && targetVersion >= EDM_RDB_VERSION_THREE) {
41 rdbStore.ExecuteSql("ALTER TABLE " + EdmRdbFiledConst::ADMIN_POLICIES_RDB_TABLE_NAME + " ADD COLUMN " +
42 EdmRdbFiledConst::FILED_ACCESSIBLE_POLICIES + " TEXT;");
43 }
44 if (currentVersion < EDM_RDB_VERSION_FOUR && targetVersion >= EDM_RDB_VERSION_FOUR) {
45 rdbStore.ExecuteSql("ALTER TABLE " + EdmRdbFiledConst::ADMIN_POLICIES_RDB_TABLE_NAME + " ADD COLUMN " +
46 EdmRdbFiledConst::FILED_RUNNING_MODE + " INTEGER DEFAULT 0;");
47 }
48 return NativeRdb::E_OK;
49 }
50 } // namespace EDM
51 } // namespace OHOS