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 SQLITE_META_EXECUTOR_H
17 #define SQLITE_META_EXECUTOR_H
18 
19 #include "sqlite_utils.h"
20 
21 namespace DistributedDB {
22 class SqliteMetaExecutor {
23 public:
24     enum class MetaMode {
25         KV = 0,
26         KV_ATTACH = 1,
27         RDB = 2
28     };
29     static int GetMetaKeysByKeyPrefix(const std::string &keyPre, sqlite3 *dbHandle, MetaMode metaMode, bool isMemDb,
30         std::set<std::string> &outKeys);
31 
32     static int GetAllKeys(sqlite3_stmt *statement, bool isMemDb, std::vector<Key> &keys);
33 
34     static int GetExistsDevicesFromMeta(sqlite3 *dbHandle, MetaMode metaMode,
35         bool isMemDb, std::set<std::string> &devices);
36 private:
37     static constexpr const char *SELECT_ATTACH_META_KEYS_BY_PREFIX =
38         "SELECT key FROM meta.meta_data where key like ?;";
39 
40     static constexpr const char *SELECT_META_KEYS_BY_PREFIX =
41         "SELECT key FROM meta_data where key like ?;";
42 
43     static constexpr const char *SELECT_RDB_META_KEYS_BY_PREFIX =
44         "SELECT key FROM naturalbase_rdb_aux_metadata where key like ?;";
45 };
46 } // DistributedDB
47 #endif // SQLITE_META_EXECUTOR_H
48