• 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 #ifndef SQLITE_SINGLE_VER_RELATIONAL_CONTINUE_TOKEN_H
16 #define SQLITE_SINGLE_VER_RELATIONAL_CONTINUE_TOKEN_H
17 #ifdef RELATIONAL_STORE
18 #include <map>
19 #include <string>
20 
21 #include "db_types.h"
22 #include "query_object.h"
23 #include "cloud/cloud_db_types.h"
24 #include "cloud/cloud_store_types.h"
25 
26 namespace DistributedDB {
27 class SQLiteSingleVerRelationalContinueToken {
28 public:
29     SQLiteSingleVerRelationalContinueToken(const SyncTimeRange &timeRange, const QueryObject &queryObject);
30     ~SQLiteSingleVerRelationalContinueToken() = default;
31 
32     // Check the magic number at the beginning and end of the SQLiteSingleVerRelationalContinueToken.
33     bool CheckValid() const;
34     // The statement should be release by the caller.
35     int GetStatement(sqlite3 *db, sqlite3_stmt *&queryStmt, sqlite3_stmt *&fullStmt, bool &isGettingDeletedData);
36     void SetNextBeginTime(const DataItem &theLastItem);
37     void FinishGetData();
38     bool IsGetAllDataFinished() const;
39     const QueryObject &GetQuery() const;
40     void SetFieldNames(const std::vector<std::string> &fieldNames);
41     void UpdateNextSyncOffset(int addOffset);
42     void SetCloudTableSchema(const TableSchema &schema);
43     int GetCloudStatement(sqlite3 *db, CloudSyncData &cloudDataResult, sqlite3_stmt *&queryStmt, bool &isFirstTime);
44     void GetCloudTableSchema(TableSchema &tableSchema) const;
45     int ReleaseCloudStatement();
46     bool IsUseLocalSchema() const;
47     std::string GetRemoteDev() const;
48 private:
49     std::string GetDeletedDataSQL() const;
50     int GetQuerySyncStatement(sqlite3 *db, sqlite3_stmt *&stmt);
51     int GetDeletedDataStmt(sqlite3 *db, sqlite3_stmt *&stmt) const;
52     int GetMissQueryStatement(sqlite3 *db, sqlite3_stmt *&stmt);
53 
54     static const unsigned int MAGIC_BEGIN = 0x600D0AC7;  // for token guard
55     static const unsigned int MAGIC_END = 0x0AC7600D;    // for token guard
56     unsigned int magicBegin_ = MAGIC_BEGIN;
57     int isGettingDeletedData_ = false;
58     QueryObject queryObj_;
59     const std::string &tableName_;
60     SyncTimeRange timeRange_;
61     std::vector<std::string> fieldNames_;
62     unsigned int magicEnd_ = MAGIC_END;
63     TableSchema tableSchema_;
64     sqlite3_stmt *queryStmt_ = nullptr;
65 };
66 }  // namespace DistributedDB
67 #endif  // RELATIONAL_STORE
68 #endif  // SQLITE_SINGLE_VER_RELATIONAL_CONTINUE_TOKEN_H