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 "table_info.h" 24 25 namespace DistributedDB { 26 class SQLiteRelationalUtils { 27 public: 28 static int GetDataValueByType(sqlite3_stmt *statement, int cid, DataValue &value); 29 30 static std::vector<DataValue> GetSelectValues(sqlite3_stmt *stmt); 31 32 static int GetCloudValueByType(sqlite3_stmt *statement, int type, int cid, Type &cloudValue); 33 34 static void CalCloudValueLen(Type &cloudValue, uint32_t &totalSize); 35 36 static int BindStatementByType(sqlite3_stmt *statement, int cid, Type &typeVal); 37 38 static int GetSelectVBucket(sqlite3_stmt *stmt, VBucket &bucket); 39 40 static bool GetDbFileName(sqlite3 *db, std::string &fileName); 41 42 static int SelectServerObserver(sqlite3 *db, const std::string &tableName, bool isChanged); 43 44 static void AddUpgradeSqlToList(const TableInfo &tableInfo, 45 const std::vector<std::pair<std::string, std::string>> &fieldList, std::vector<std::string> &sqlList); 46 47 static int AnalysisTrackerTable(sqlite3 *db, const TrackerTable &trackerTable, TableInfo &tableInfo); 48 49 static int QueryCount(sqlite3 *db, const std::string &tableName, int64_t &count); 50 private: 51 static int BindExtendStatementByType(sqlite3_stmt *statement, int cid, Type &typeVal); 52 53 static int GetTypeValByStatement(sqlite3_stmt *stmt, int cid, Type &typeVal); 54 static int GetBlobByStatement(sqlite3_stmt *stmt, int cid, Type &typeVal); 55 }; 56 } // namespace DistributedDB 57 #endif // SQLITE_RELATIONAL_UTILS_H 58