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