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 #ifndef OMIT_MULTI_VER
17 #include "sqlite_local_kvdb_snapshot.h"
18 #include "sqlite_local_kvdb_connection.h"
19 
20 namespace DistributedDB {
SQLiteLocalKvDBSnapshot(IKvDBConnection * connect)21 SQLiteLocalKvDBSnapshot::SQLiteLocalKvDBSnapshot(IKvDBConnection *connect)
22     : connect_(connect)
23 {}
24 
~SQLiteLocalKvDBSnapshot()25 SQLiteLocalKvDBSnapshot::~SQLiteLocalKvDBSnapshot()
26 {
27     connect_ = nullptr;
28 }
29 
Get(const Key & key,Value & value) const30 int SQLiteLocalKvDBSnapshot::Get(const Key &key, Value &value) const
31 {
32     if (connect_ == nullptr) {
33         return -E_INVALID_DB;
34     }
35     IOption option;
36     return connect_->Get(option, key, value);
37 }
38 
GetEntries(const Key & keyPrefix,std::vector<Entry> & entries) const39 int SQLiteLocalKvDBSnapshot::GetEntries(const Key &keyPrefix, std::vector<Entry> &entries) const
40 {
41     if (connect_ == nullptr) {
42         return -E_INVALID_DB;
43     }
44     IOption option;
45     return connect_->GetEntries(option, keyPrefix, entries);
46 }
47 
Close()48 void SQLiteLocalKvDBSnapshot::Close()
49 {
50     if (connect_ != nullptr) {
51         connect_->Close();
52         connect_ = nullptr;
53     }
54 }
55 } // namespace DistributedDB
56 #endif // OMIT_MULTI_VER
57