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_sms_mms_callback.h"
17 
18 #include "data_storage_log_wrapper.h"
19 #include "rdb_errno.h"
20 #include "sms_mms_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 RdbSmsMmsCallback::OnUpgrade(NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion)
28 {
29     DATA_STORAGE_LOGI(
30         "Data_Storage RdbSmsMmsCallback::OnUpgrade##oldVersion = %d, "
31         "newVersion = %d\n",
32         oldVersion, newVersion);
33     if (oldVersion < VERSION_2 && newVersion >= VERSION_2) {
34         rdbStore.ExecuteSql("ALTER TABLE " + std::string(TABLE_SMS_MMS_INFO) + " ADD COLUMN " +
35                             std::string(SmsMmsInfo::IS_ADVANCED_SECURITY) + " INTEGER DEFAULT " + "0;");
36         oldVersion = VERSION_2;
37     }
38 
39     if (oldVersion != newVersion) {
40         DATA_STORAGE_LOGE("upgrade error oldVersion = %{public}d, newVersion = %{public}d ", oldVersion, newVersion);
41         return NativeRdb::E_ERROR;
42     }
43     return NativeRdb::E_OK;
44 }
45 
OnDowngrade(NativeRdb::RdbStore & rdbStore,int currentVersion,int targetVersion)46 int RdbSmsMmsCallback::OnDowngrade(NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion)
47 {
48     DATA_STORAGE_LOGI(
49         "Data_Storage RdbSmsMmsCallback::OnDowngrade##currentVersion "
50         "= %d, targetVersion = %d\n",
51         currentVersion, targetVersion);
52     return NativeRdb::E_OK;
53 }
54 
OnOpen(NativeRdb::RdbStore & rdbStore)55 int RdbSmsMmsCallback::OnOpen(NativeRdb::RdbStore &rdbStore)
56 {
57     return NativeRdb::E_OK;
58 }
59 } // namespace Telephony
60 } // namespace OHOS
61