• 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     int GetSize(int index, size_t &size) const;
44     int GetColumn(int index, ValueObject &value) const;
45     bool IsReadOnly() const;
46     int GetNumParameters(int &numParams) const;
GetSql3Stmt()47     sqlite3_stmt *GetSql3Stmt() const
48     {
49         return stmtHandle;
50     }
51 
52 private:
53     using Asset = ValueObject::Asset;
54     using Assets = ValueObject::Assets;
55 
56     int InnerBindArguments(const std::vector<ValueObject> &bindArgs) const;
57     int IsValid(int index) const;
58     std::string sql;
59     sqlite3_stmt *stmtHandle;
60     bool readOnly;
61     int columnCount;
62     int numParameters;
63 };
64 
65 } // namespace NativeRdb
66 } // namespace OHOS
67 #endif