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_SQLITE_STATEMENT_H 17 #define NATIVE_RDB_SQLITE_STATEMENT_H 18 19 #include <memory> 20 #include <vector> 21 22 #include "sqlite3sym.h" 23 #include "value_object.h" 24 25 namespace OHOS { 26 namespace NativeRdb { 27 class SqliteConnection; 28 29 class SqliteStatement { 30 public: 31 SqliteStatement(); 32 ~SqliteStatement(); 33 static std::shared_ptr<SqliteStatement> CreateStatement( 34 std::shared_ptr<SqliteConnection>connection, const std::string &sql); 35 int Prepare(sqlite3 *dbHandle, const std::string &sql); 36 int Finalize(); 37 int BindArguments(const std::vector<ValueObject> &bindArgs) const; 38 int ResetStatementAndClearBindings() const; 39 int Step() const; 40 41 int GetColumnCount(int &count) const; 42 int GetColumnName(int index, std::string &columnName) const; 43 int GetColumnType(int index, int &columnType) const; 44 int GetColumnBlob(int index, std::vector<uint8_t> &value) const; 45 int GetColumnString(int index, std::string &value) const; 46 int GetColumnLong(int index, int64_t &value) const; 47 int GetColumnDouble(int index, double &value) const; 48 int GetSize(int index, size_t &size) const; 49 int GetColumn(int index, ValueObject &value) const; 50 bool IsReadOnly() const; GetSql3Stmt()51 sqlite3_stmt *GetSql3Stmt() const 52 { 53 return stmtHandle; 54 } 55 56 static constexpr int COLUMN_TYPE_ASSET = 1000; 57 static constexpr int COLUMN_TYPE_ASSETS = 1001; 58 private: 59 using Asset = ValueObject::Asset; 60 using Assets = ValueObject::Assets; 61 62 int InnerBindArguments(const std::vector<ValueObject> &bindArgs) const; 63 int IsValid(int index) const; 64 std::string sql; 65 sqlite3_stmt *stmtHandle; 66 bool readOnly; 67 int columnCount; 68 int numParameters; 69 }; 70 71 } // namespace NativeRdb 72 } // namespace OHOS 73 #endif