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