1 /* 2 * Copyright (c) 2021-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 STATEMENT_H 17 #define STATEMENT_H 18 19 #include <string> 20 21 #include "variant_value.h" 22 23 #include "sqlite3sym.h" 24 25 namespace OHOS { 26 namespace Security { 27 namespace AccessToken { 28 class Statement final { 29 public: 30 enum State { BUSY, ROW, DONE, MISUSE, UNKNOWN }; 31 32 Statement(sqlite3* db, const std::string& sql); 33 virtual ~Statement(); 34 35 void Bind(const int32_t index, const std::string& text); 36 void Bind(const int32_t index, int32_t value); 37 void Bind(const int32_t index, int64_t value); 38 void Bind(const std::string& tableColumnName, const VariantValue& value); 39 40 State Step(); 41 int32_t Reset(); 42 43 std::string GetColumnString(const int32_t column) const; 44 int32_t GetColumnInt(const int32_t column) const; 45 int64_t GetColumnInt64(const int32_t column) const; 46 std::string GetColumnName(const int32_t column) const; 47 int32_t GetParameterIndex(const std::string& name) const; 48 int32_t GetColumnCount() const; 49 VariantValue GetValue(const int32_t column, const bool flagInt64) const; 50 51 private: 52 sqlite3* db_; 53 sqlite3_stmt* statement_; 54 const std::string sql_; 55 }; 56 } // namespace AccessToken 57 } // namespace Security 58 } // namespace OHOS 59 #endif // STATEMENT_H 60