• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_RD_STATEMENT_H
17 #define NATIVE_RDB_RD_STATEMENT_H
18 
19 #include <memory>
20 #include <vector>
21 
22 #include "connection.h"
23 #include "rd_connection.h"
24 #include "rd_utils.h"
25 #include "rdb_store_config.h"
26 #include "statement.h"
27 #include "value_object.h"
28 
29 namespace OHOS {
30 namespace NativeRdb {
31 class RdStatement final : public Statement {
32 public:
33     RdStatement();
34     ~RdStatement();
35     int Finalize() override;
36     int32_t Prepare(const std::string &sql) override;
37     int32_t Bind(const std::vector<ValueObject> &args) override;
38     std::pair<int32_t, int32_t> Count() override;
39     int32_t Step() override;
40     int32_t Reset() override;
41     int32_t Execute(const std::vector<ValueObject> &args) override;
42     int32_t Execute(const std::vector<std::reference_wrapper<ValueObject>> &args) override;
43     std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject> &args) override;
44     int32_t Changes() const override;
45     int64_t LastInsertRowId() const override;
46     int32_t GetColumnCount() const override;
47     std::pair<int32_t, std::string> GetColumnName(int32_t index) const override;
48     std::pair<int32_t, int32_t> GetColumnType(int32_t index) const override;
49     std::pair<int32_t, size_t> GetSize(int32_t index) const override;
50     std::pair<int32_t, ValueObject> GetColumn(int32_t index) const override;
51     bool ReadOnly() const override;
52     bool SupportBlockInfo() const override;
53     int32_t FillBlockInfo(SharedBlockInfo *info) const override;
54     void GetProperties();
55 
56 private:
57     friend class RdConnection;
58     int Prepare(GRD_DB *db, const std::string &sql);
59     int32_t Bind(const std::vector<std::reference_wrapper<ValueObject>> &args);
60     int InnerBindBlobTypeArgs(const ValueObject &bindArg, uint32_t index) const;
61     int IsValid(int index) const;
62     int PreGetColCount();
63 
64     bool readOnly_ = false;
65     bool isStepInPrepare_ = false;
66     int stepCnt_ = 0;
67     std::string sql_ = "";
68     GRD_SqlStmt *stmtHandle_ = nullptr;
69     GRD_DB *dbHandle_ = nullptr;
70     std::shared_ptr<Connection> conn_;
71     int columnCount_ = 0;
72 
73     std::map<std::string, std::function<int32_t(const int &value)>> setPragmas_;
74     std::map<std::string, std::function<int32_t(int &version)>> getPragmas_;
75     const RdbStoreConfig *config_ = nullptr;
76 };
77 } // namespace NativeRdb
78 } // namespace OHOS
79 #endif // NATIVE_RDB_RD_STATEMENT_H
80