• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "rdb_sim_callback.h"
17 
18 #include "data_storage_log_wrapper.h"
19 #include "rdb_errno.h"
20 #include "sim_data.h"
21 
22 namespace OHOS {
23 namespace NativeRdb {
24 class RdbStore;
25 }
26 namespace Telephony {
OnUpgrade(NativeRdb::RdbStore & rdbStore,int oldVersion,int newVersion)27 int RdbSimCallback::OnUpgrade(NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion)
28 {
29     DATA_STORAGE_LOGI("upgrade start oldVersion = %{public}d, newVersion = %{public}d ", oldVersion, newVersion);
30     if (oldVersion < VERSION_2 && newVersion >= VERSION_2) {
31         rdbStore.ExecuteSql(
32             "ALTER TABLE " + std::string(TABLE_SIM_INFO) + " DROP COLUMN " + std::string(SimData::IS_ACTIVE) + ";");
33         rdbStore.ExecuteSql("ALTER TABLE " + std::string(TABLE_SIM_INFO) + " ADD COLUMN " +
34                             std::string(SimData::IS_ACTIVE) + " INTEGER DEFAULT " + "1;");
35         oldVersion = VERSION_2;
36     }
37 
38     if (oldVersion != newVersion) {
39         DATA_STORAGE_LOGE("upgrade error oldVersion = %{public}d, newVersion = %{public}d ", oldVersion, newVersion);
40         return NativeRdb::E_ERROR;
41     }
42     return NativeRdb::E_OK;
43 }
44 
OnDowngrade(NativeRdb::RdbStore & rdbStore,int currentVersion,int targetVersion)45 int RdbSimCallback::OnDowngrade(NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion)
46 {
47     DATA_STORAGE_LOGI(
48         "Data_Storage RdbSimCallback::OnDowngrade##currentVersion = "
49         "%d, targetVersion = %d\n",
50         currentVersion, targetVersion);
51     return NativeRdb::E_OK;
52 }
53 
OnOpen(NativeRdb::RdbStore & rdbStore)54 int RdbSimCallback::OnOpen(NativeRdb::RdbStore &rdbStore)
55 {
56     return NativeRdb::E_OK;
57 }
58 } // namespace Telephony
59 } // namespace OHOS
60