• 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     if (oldVersion < VERSION_3 && newVersion >= VERSION_3) {
38         rdbStore.ExecuteSql("ALTER TABLE " + std::string(TABLE_SIM_INFO) + " ADD COLUMN " +
39                             std::string(SimData::OPKEY) + " TEXT DEFAULT " + " '' ;");
40         rdbStore.ExecuteSql("ALTER TABLE " + std::string(TABLE_SIM_INFO) + " ADD COLUMN " +
41                             std::string(SimData::MCC) + " TEXT DEFAULT " + " '' ;");
42         rdbStore.ExecuteSql("ALTER TABLE " + std::string(TABLE_SIM_INFO)+ " ADD COLUMN " +
43                             std::string(SimData::MNC) + " TEXT DEFAULT " + " '' ;");
44         oldVersion = VERSION_3;
45     }
46     if (oldVersion < VERSION_4 && newVersion >= VERSION_4) {
47         rdbStore.ExecuteSql("ALTER TABLE " + std::string(TABLE_SIM_INFO) + " ADD COLUMN " +
48                             std::string(SimData::IS_ESIM) + " INTEGER DEFAULT " + "0;");
49         rdbStore.ExecuteSql("ALTER TABLE " + std::string(TABLE_SIM_INFO) + " ADD COLUMN " +
50                             std::string(SimData::SIM_LABEL_INDEX) + " INTEGER DEFAULT " + "1;");
51         rdbStore.ExecuteSql("ALTER TABLE " + std::string(TABLE_SIM_INFO)+ " ADD COLUMN " +
52                             std::string(SimData::OPERATOR_NAME) + " TEXT DEFAULT " + " '' ;");
53         oldVersion = VERSION_4;
54     }
55     if (oldVersion != newVersion) {
56         DATA_STORAGE_LOGE("upgrade error oldVersion = %{public}d, newVersion = %{public}d ", oldVersion, newVersion);
57         return NativeRdb::E_ERROR;
58     }
59     return NativeRdb::E_OK;
60 }
61 
OnDowngrade(NativeRdb::RdbStore & rdbStore,int currentVersion,int targetVersion)62 int RdbSimCallback::OnDowngrade(NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion)
63 {
64     DATA_STORAGE_LOGI(
65         "Data_Storage RdbSimCallback::OnDowngrade##currentVersion = "
66         "%d, targetVersion = %d\n",
67         currentVersion, targetVersion);
68     return NativeRdb::E_OK;
69 }
70 
OnOpen(NativeRdb::RdbStore & rdbStore)71 int RdbSimCallback::OnOpen(NativeRdb::RdbStore &rdbStore)
72 {
73     return NativeRdb::E_OK;
74 }
75 } // namespace Telephony
76 } // namespace OHOS
77