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