• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SQLITE_SINGLE_VER_DATABASE_UPGRADER_H
17 #define SQLITE_SINGLE_VER_DATABASE_UPGRADER_H
18 
19 #include "macro_utils.h"
20 #include "sqlite_utils.h"
21 #include "single_ver_database_upgrader.h"
22 
23 namespace DistributedDB {
24 class SQLiteSingleVerDatabaseUpgrader : virtual public SingleVerDatabaseUpgrader {
25 public:
26     explicit SQLiteSingleVerDatabaseUpgrader(sqlite3 *db, const SecurityOption &secopt, bool isMemDb);
27     ~SQLiteSingleVerDatabaseUpgrader() override;
28     DISABLE_COPY_ASSIGN_MOVE(SQLiteSingleVerDatabaseUpgrader);
29 
30     // used for transferring db file to new dir while classifycation feature in SOFTWARE_VERSION_RELEASE_3_0
31     static int TransferDatabasePath(const std::string &parentDir, const OpenDbProperties &option);
32 
33     void SetMetaUpgrade(const SecurityOption &currentOpt, const SecurityOption &expectOpt, const std::string &subDir);
34     void SetSubdir(const std::string &subDir);
35     static int SetPathSecOptWithCheck(const std::string &path, const SecurityOption &secOption,
36         const std::string &dbStore, bool isWithChecked = false);
37     static int SetSecOption(const std::string &path, const SecurityOption &secOption, bool isWithChecked);
38 protected:
39     int BeginUpgrade() override;
40     int EndUpgrade(bool isSuccess) override;
41     int GetDatabaseVersion(int &version) const override;
42     int SetDatabaseVersion(int version) override;
43     int UpgradeFromDatabaseVersion(int version) override;
44     void SetUpgradeSqls(int version, std::vector<std::string> &sqls, bool &isCreateUpgradeFile) const;
45     static int MoveDatabaseToNewDir(const std::string &parentDir, const std::string &upgradeLockFile);
46     static int GetDbVersion(const std::string &dbPath, const OpenDbProperties &option, int &version);
47 
48     sqlite3 *db_ = nullptr;
49     SecurityOption secOpt_;
50     bool isMemDB_;
51     bool isMetaUpgrade_;
52     std::string subDir_;
53 };
54 } // namespace DistributedDB
55 #endif // SQLITE_SINGLE_VER_DATABASE_UPGRADER_H
56