• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_FUNCTION_REGISTRY_H
17 #define SQLITE_FUNCTION_REGISTRY_H
18 
19 #include <sqlite3.h>
20 
21 #include <map>
22 
23 #include "value_object.h"
24 
25 namespace OHOS {
26 namespace NativeRdb {
27 struct SqliteFunction {
28     const char *name;
29     int numArgs;
30     void (*function)(sqlite3_context *, int, sqlite3_value **);
31 };
32 
33 class SqliteFunctionRegistry {
34 private:
35     static void MergeAssets(sqlite3_context *ctx, int argc, sqlite3_value **argv);
36     static void MergeAsset(sqlite3_context *ctx, int argc, sqlite3_value **argv);
37     static void CompAssets(
38         std::map<std::string, ValueObject::Asset> &oldAssets, std::map<std::string, ValueObject::Asset> &newAssets);
39     static void MergeAsset(ValueObject::Asset &oldAsset, ValueObject::Asset &newAsset);
40     static void ImportDB(sqlite3_context *ctx, int argc, sqlite3_value **argv);
41     static void SqliteResultError(sqlite3_context *ctx, const int &errCode, const std::string &msg);
42     static int32_t IntegrityCheck(sqlite3 *dbHandle);
43     static int32_t BackUpDB(sqlite3 *source, sqlite3 *dest);
44     static constexpr SqliteFunction FUNCTIONS[] = {
45         { "merge_assets", 2, &SqliteFunctionRegistry::MergeAssets },
46         { "merge_asset", 2, &SqliteFunctionRegistry::MergeAsset },
47         { "import_db_from_path", 1, &SqliteFunctionRegistry::ImportDB },
48     };
49 
50 public:
GetFunctions()51     static constexpr std::pair<const SqliteFunction*, size_t> GetFunctions()
52     {
53         return { FUNCTIONS, sizeof(FUNCTIONS) / sizeof(FUNCTIONS[0]) };
54     };
55 };
56 
57 } // namespace NativeRdb
58 } // namespace OHOS
59 #endif
60