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 #define MLOG_TAG "DatabaseAdapter"
17
18 #include "database_adapter.h"
19
20 #include "medialibrary_unistore_manager.h"
21 #include "media_log.h"
22
23 namespace OHOS {
24 namespace Media {
Query(MediaLibraryCommand & cmd,const std::vector<std::string> & columns)25 std::shared_ptr<NativeRdb::ResultSet> DatabaseAdapter::Query(MediaLibraryCommand &cmd,
26 const std::vector<std::string> &columns)
27 {
28 auto uniStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStore();
29 if (uniStore == nullptr) {
30 MEDIA_ERR_LOG("uniStore is nullptr!");
31 return nullptr;
32 }
33
34 return uniStore->Query(cmd, columns);
35 }
36
Update(MediaLibraryCommand & cmd)37 int32_t DatabaseAdapter::Update(MediaLibraryCommand &cmd)
38 {
39 auto uniStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStore();
40 if (uniStore == nullptr) {
41 MEDIA_ERR_LOG("uniStore is nullptr!");
42 return E_HAS_DB_ERROR;
43 }
44
45 int32_t changedRows = E_ERR;
46 auto ret = uniStore->Update(cmd, changedRows);
47 if (ret != NativeRdb::E_OK || changedRows <= 0) {
48 MEDIA_ERR_LOG("Update DB failed. ret: %{public}d", ret);
49 return E_HAS_DB_ERROR;
50 }
51 return E_OK;
52 }
53 } // namespace Media
54 } // namespace OHOS