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 private: 47 std::string GetDeletedDataSQL() const; 48 int GetQuerySyncStatement(sqlite3 *db, sqlite3_stmt *&stmt); 49 int GetDeletedDataStmt(sqlite3 *db, sqlite3_stmt *&stmt) const; 50 int GetMissQueryStatement(sqlite3 *db, sqlite3_stmt *&stmt); 51 52 static const unsigned int MAGIC_BEGIN = 0x600D0AC7; // for token guard 53 static const unsigned int MAGIC_END = 0x0AC7600D; // for token guard 54 unsigned int magicBegin_ = MAGIC_BEGIN; 55 int isGettingDeletedData_ = false; 56 QueryObject queryObj_; 57 const std::string &tableName_; 58 SyncTimeRange timeRange_; 59 std::vector<std::string> fieldNames_; 60 unsigned int magicEnd_ = MAGIC_END; 61 TableSchema tableSchema_; 62 sqlite3_stmt *queryStmt_ = nullptr; 63 }; 64 } // namespace DistributedDB 65 #endif // RELATIONAL_STORE 66 #endif // SQLITE_SINGLE_VER_RELATIONAL_CONTINUE_TOKEN_H