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 16 #ifndef NATIVE_RDB_STEP_RESULT_SET_H 17 #define NATIVE_RDB_STEP_RESULT_SET_H 18 19 #include <memory> 20 #include <thread> 21 #include <vector> 22 23 #include "rdb_store_impl.h" 24 #include "abs_result_set.h" 25 #include "sqlite_statement.h" 26 27 namespace OHOS { 28 namespace NativeRdb { 29 30 class StepResultSet : public AbsResultSet { 31 public: 32 StepResultSet(std::shared_ptr<RdbStoreImpl> rdb, const std::string &sql, 33 const std::vector<std::string> &selectionArgs); 34 ~StepResultSet() override; 35 36 int GetAllColumnNames(std::vector<std::string> &columnNames) override; 37 int GetColumnType(int columnIndex, ColumnType &columnType) override; 38 int GetRowCount(int &count) override; 39 int GoToRow(int position) override; 40 int GoToNextRow() override; 41 int IsStarted(bool &result) const override; 42 int IsAtFirstRow(bool &result) const override; 43 int IsEnded(bool &result) override; 44 int GetBlob(int columnIndex, std::vector<uint8_t> &blob) override; 45 int GetString(int columnIndex, std::string &value) override; 46 int GetInt(int columnIndex, int &value) override; 47 int GetLong(int columnIndex, int64_t &value) override; 48 int GetDouble(int columnIndex, double &value) override; 49 int IsColumnNull(int columnIndex, bool &isNull) override; 50 bool IsClosed() const override; 51 int Close() override; 52 int FinishStep(); 53 int PrepareStep(); 54 55 private: 56 int CheckSession(); 57 void Reset(); 58 std::shared_ptr<RdbStoreImpl> rdb; 59 std::string sql; 60 std::vector<std::string> selectionArgs; 61 // Whether reach the end of this result set or not 62 bool isAfterLast; 63 // The value indicates the row count of the result set 64 int rowCount; 65 std::thread::id tid; 66 std::shared_ptr<SqliteStatement> sqliteStatement; 67 static const int INIT_POS = -1; 68 // Max times of retrying step query 69 static const int STEP_QUERY_RETRY_MAX_TIMES = 50; 70 // Interval of retrying step query in millisecond 71 static const int STEP_QUERY_RETRY_INTERVAL = 1000; 72 }; 73 74 } // namespace NativeRdb 75 } // namespace OHOS 76 #endif 77