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 #ifndef OHOS_CLOUD_DISK_SERVICE_RDB_UTILS_H
17 #define OHOS_CLOUD_DISK_SERVICE_RDB_UTILS_H
18 
19 #include <vector>
20 
21 #include "cloud_file_utils.h"
22 #include "clouddisk_db_const.h"
23 #include "rdb_store.h"
24 
25 namespace OHOS::FileManagement::CloudDisk {
26 class CloudDiskRdbUtils final {
27 public:
28     CloudDiskRdbUtils() = delete;
29     ~CloudDiskRdbUtils() = delete;
30     static int32_t GetInt(const std::string &key, int32_t &val,
31                           const std::shared_ptr<NativeRdb::ResultSet> resultSet);
32     static int32_t GetLong(const std::string &key, int64_t &val,
33                            const std::shared_ptr<NativeRdb::ResultSet> resultSet);
34     static int32_t GetString(const std::string &key, std::string &val,
35                              const std::shared_ptr<NativeRdb::ResultSet> resultSet);
36     static int32_t ResultSetToFileInfo(const std::shared_ptr<NativeRdb::ResultSet> resultSet, CloudDiskFileInfo &info);
37     static int32_t ResultSetToFileInfos(const std::shared_ptr<NativeRdb::ResultSet> resultSet,
38         std::vector<CloudDiskFileInfo> &infos);
39     static size_t FuseDentryAlignSize(const char *name);
40 };
41 
42 #define RETURN_ON_ERR(ret)    \
43     do {    \
44         if ((ret) != E_OK) {    \
45             return ret;    \
46         }    \
47     } while (0)
48 } // namespace OHOS::FileManagement::CloudDisk
49 
50 #endif // OHOS_CLOUD_DISK_SERVICE_RDB_UTILS_H