1 /*
2  * Copyright (c) 2022 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 PREPARED_STMT_H
17 #define PREPARED_STMT_H
18 
19 #include <string>
20 #include <vector>
21 #include "parcel.h"
22 
23 namespace DistributedDB {
24 class PreparedStmt {
25 public:
26     enum ExecutorOperation { MIN_LIMIT, QUERY, DELETE, UPDATE, INSERT, MAX_LIMIT };
27 
28     PreparedStmt() = default;
29     PreparedStmt(ExecutorOperation opCode, const std::string &sql, const std::vector<std::string> &bindArgs);
30 
31     void SetOpCode(ExecutorOperation opCode);
32     void SetSql(std::string sql);
33     void SetBindArgs(std::vector<std::string> bindArgs);
34 
35     ExecutorOperation GetOpCode() const;
36     const std::string &GetSql() const;
37     const std::vector<std::string> &GetBindArgs() const;
38 
39     bool IsValid() const;
40 
41     uint32_t CalcLength() const;
42     int Serialize(Parcel &parcel) const;
43     int DeSerialize(Parcel &parcel);
44 
45 private:
46     static const int VERSION_1 = 1;
47     static const int CURRENT_VERSION = VERSION_1;
48 
49     ExecutorOperation opCode_ = ExecutorOperation::MIN_LIMIT;
50     std::string sql_;
51     std::vector<std::string> bindArgs_;
52 };
53 } // namespace DistributedDB
54 #endif  // PREPARED_STMT_H