• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <vector>
20 
21 #include "sqlite3sym.h"
22 #include "value_object.h"
23 
24 namespace OHOS {
25 namespace NativeRdb {
26 class SqliteStatement {
27 public:
28     SqliteStatement();
29     ~SqliteStatement();
30     int Prepare(sqlite3 *dbHandle, const std::string &sql);
31     int Finalize();
32     int BindArguments(const std::vector<ValueObject> &bindArgs) const;
33     int ResetStatementAndClearBindings() const;
34     int Step() const;
35 
36     int GetColumnCount(int &count) const;
37     int GetColumnName(int index, std::string &columnName) const;
38     int GetColumnType(int index, int &columnType) const;
39     int GetColumnBlob(int index, std::vector<uint8_t> &value) const;
40     int GetColumnString(int index, std::string &value) const;
41     int GetColumnLong(int index, int64_t &value) const;
42     int GetColumnDouble(int index, double &value) const;
43     bool IsReadOnly() const;
44     int GetNumParameters(int &numParams) const;
GetSql3Stmt()45     sqlite3_stmt *GetSql3Stmt() const
46     {
47         return stmtHandle;
48     }
49 
50 private:
51     int InnerBindArguments(const std::vector<ValueObject> &bindArgs) const;
52     std::string sql;
53     sqlite3_stmt *stmtHandle;
54     bool readOnly;
55     int columnCount;
56     int numParameters;
57 };
58 
59 } // namespace NativeRdb
60 } // namespace OHOS
61 #endif