1 /* 2 * Copyright (c) 2022 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_RELATIONAL_UTILS_H 17 #define SQLITE_RELATIONAL_UTILS_H 18 19 #include <vector> 20 #include "cloud/cloud_store_types.h" 21 #include "data_value.h" 22 #include "sqlite_import.h" 23 #include "sqlite_single_ver_relational_storage_executor.h" 24 #include "table_info.h" 25 26 namespace DistributedDB { 27 class SQLiteRelationalUtils { 28 public: 29 static int GetDataValueByType(sqlite3_stmt *statement, int cid, DataValue &value); 30 31 static std::vector<DataValue> GetSelectValues(sqlite3_stmt *stmt); 32 33 static int GetCloudValueByType(sqlite3_stmt *statement, int type, int cid, Type &cloudValue); 34 35 static void CalCloudValueLen(Type &cloudValue, uint32_t &totalSize); 36 37 static int BindStatementByType(sqlite3_stmt *statement, int cid, Type &typeVal); 38 39 static int GetSelectVBucket(sqlite3_stmt *stmt, VBucket &bucket); 40 41 static bool GetDbFileName(sqlite3 *db, std::string &fileName); 42 43 static int SelectServerObserver(sqlite3 *db, const std::string &tableName, bool isChanged); 44 45 static void AddUpgradeSqlToList(const TableInfo &tableInfo, 46 const std::vector<std::pair<std::string, std::string>> &fieldList, std::vector<std::string> &sqlList); 47 48 static int AnalysisTrackerTable(sqlite3 *db, const TrackerTable &trackerTable, TableInfo &tableInfo); 49 50 static int QueryCount(sqlite3 *db, const std::string &tableName, int64_t &count); 51 52 static int GetCursor(sqlite3 *db, const std::string &tableName, uint64_t &cursor); 53 54 static int CheckDistributedSchemaValid(const RelationalSchemaObject &schemaObj, const DistributedSchema &schema, 55 bool isForceUpgrade, SQLiteSingleVerRelationalStorageExecutor *executor); 56 57 static DistributedSchema FilterRepeatDefine(const DistributedSchema &schema); 58 59 static DistributedTable FilterRepeatDefine(const DistributedTable &table); 60 61 static int GetLogData(sqlite3_stmt *logStatement, LogInfo &logInfo); 62 63 static int GetLogInfoPre(sqlite3_stmt *queryStmt, DistributedTableMode mode, const DataItem &dataItem, 64 LogInfo &logInfoGet); 65 private: 66 static int BindExtendStatementByType(sqlite3_stmt *statement, int cid, Type &typeVal); 67 68 static int GetTypeValByStatement(sqlite3_stmt *stmt, int cid, Type &typeVal); 69 static int GetBlobByStatement(sqlite3_stmt *stmt, int cid, Type &typeVal); 70 }; 71 } // namespace DistributedDB 72 #endif // SQLITE_RELATIONAL_UTILS_H 73