1 /*
2 * Copyright (C) 2022 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 "medialibrary_dir_db.h"
17 #include "media_log.h"
18 #include "medialibrary_errno.h"
19 #include "medialibrary_tracer.h"
20
21 using namespace std;
22 using namespace OHOS::NativeRdb;
23
24 namespace OHOS {
25 namespace Media {
26 static const std::string DIR_DB_COND = MEDIA_DATA_DB_ID + " = ?";
DeleteDirInfo(const int32_t dirId,const shared_ptr<RdbStore> & rdbStore)27 int32_t MediaLibraryDirDb::DeleteDirInfo(const int32_t dirId, const shared_ptr<RdbStore> &rdbStore)
28 {
29 CHECK_AND_RETURN_RET_LOG((rdbStore != nullptr) && (dirId > 0), E_DIR_OPER_ERR, "Invalid input");
30 int32_t deletedRows(E_ALBUM_OPER_ERR);
31 vector<string> whereArgs = { std::to_string(dirId)};
32 int32_t deleteResult = rdbStore->Delete(deletedRows, MEDIALIBRARY_TABLE, DIR_DB_COND, whereArgs);
33 CHECK_AND_RETURN_RET_LOG(deleteResult == E_OK, E_DIR_OPER_ERR, "Delete failed");
34 return (deletedRows > 0) ? E_SUCCESS : E_FAIL;
35 }
36 } // namespace Media
37 } // namespace OHOS
38