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_TRANS_DB_H
17 #define NATIVE_RDB_TRANS_DB_H
18 #include <memory>
19 
20 #include "connection.h"
21 #include "rdb_store.h"
22 #include "statement.h"
23 namespace OHOS::NativeRdb {
24 class TransDB : public RdbStore {
25 public:
26     TransDB(std::shared_ptr<Connection> conn, const std::string &name);
27     std::pair<int, int64_t> Insert(const std::string &table, const Row &row, Resolution resolution) override;
28     std::pair<int, int64_t> BatchInsert(const std::string &table, const RefRows &rows) override;
29     std::pair<int, int> Update(const std::string &table, const Row &row, const std::string &where, const Values &args,
30         Resolution resolution) override;
31     int Delete(int &deletedRows, const std::string &table, const std::string &whereClause, const Values &args) override;
32     std::shared_ptr<AbsSharedResultSet> QuerySql(const std::string &sql, const Values &args) override;
33     std::shared_ptr<ResultSet> QueryByStep(const std::string &sql, const Values &args, bool preCount) override;
34     std::pair<int32_t, ValueObject> Execute(const std::string &sql, const Values &args, int64_t trxId) override;
35     int GetVersion(int &version) override;
36     int SetVersion(int version) override;
37     int Sync(const SyncOption &option, const std::vector<std::string> &tables, const AsyncDetail &async) override;
38 
39 private:
40     std::pair<int32_t, std::shared_ptr<Statement>> GetStatement(const std::string &sql) const;
41 
42     int32_t maxArgs_ = 0;
43     int64_t vSchema_ = 0;
44     std::weak_ptr<Connection> conn_;
45     std::string name_;
46 };
47 } // namespace OHOS::NativeRdb
48 #endif // NATIVE_RDB_TRANS_DB_H