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