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 RELATIONAL_MODIFY_TIME_CURSOR_H
17 #define RELATIONAL_MODIFY_TIME_CURSOR_H
18 #include "relational_cursor.h"
19 #include "rdb_store.h"
20 #include "result_set.h"
21 namespace OHOS::RdbNdk {
22 class ModifyTimeCursor : public RelationalCursor {
23 public:
24     using ResultSet = OHOS::NativeRdb::ResultSet;
25     using ModifyTime = OHOS::NativeRdb::RdbStore::ModifyTime;
26     using PRIKey = OHOS::NativeRdb::RdbStore::PRIKey;
27     explicit ModifyTimeCursor(ModifyTime &&modifyTime);
28     ~ModifyTimeCursor() override = default;
29 
30 protected:
31     int GetSize(int32_t columnIndex, size_t *size) override;
32     int GetText(int32_t columnIndex, char *value, int length) override;
33     int GetInt64(int32_t columnIndex, int64_t *value) override;
34     int GetReal(int32_t columnIndex, double *value) override;
35 
36 private:
ConvertPRIKey()37     inline PRIKey ConvertPRIKey()
38     {
39         std::vector<uint8_t> hash;
40         std::shared_ptr<ResultSet> result = modifyTime_;
41         if (result == nullptr) {
42             return PRIKey();
43         }
44         result->GetBlob(0, hash);
45         return modifyTime_.GetOriginKey(hash);
46     }
47 
48     ModifyTime modifyTime_;
49 };
50 } // namespace OHOS::RdbNdk
51 #endif // RELATIONAL_MODIFY_TIME_CURSOR_H
52