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 NET_STATS_SQLITE_STATEMENT_H
17 #define NET_STATS_SQLITE_STATEMENT_H
18 
19 #include <climits>
20 #include <functional>
21 #include <string>
22 
23 #ifndef USE_SQLITE_SYMBOLS
24 #include "sqlite3.h"
25 #else
26 #include "sqlite3sym.h"
27 #endif
28 
29 namespace OHOS {
30 namespace NetManagerStandard {
31 class NetStatsSqliteStatement {
32 public:
33     NetStatsSqliteStatement() = default;
34     ~NetStatsSqliteStatement();
35     int32_t Prepare(sqlite3 *dbHandle, const std::string &sql);
36     int32_t BindInt32(int32_t index, int32_t value) const;
37     int32_t BindInt64(int32_t index, int64_t value) const;
38     int32_t BindText(int32_t index, std::string value) const;
39     void Finalize();
40     void ResetStatementAndClearBindings() const;
41     int32_t Step();
42     int32_t GetColumnString(int32_t index, std::string &value) const;
43     int32_t GetColumnLong(int32_t index, uint64_t &value) const;
44     int32_t GetColumnInt(int32_t index, uint32_t &value) const;
GetColumnCount()45     int32_t GetColumnCount() const
46     {
47         return columnCount_;
48     }
49 
50 private:
51     std::string sqlCmd_;
52     sqlite3_stmt *stmtHandle_ = nullptr;
53     int32_t columnCount_ = 0;
54 };
55 } // namespace NetManagerStandard
56 } // namespace OHOS
57 #endif