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 #include "transaction.h"
16
17 namespace OHOS::NativeRdb {
Create(int32_t type,std::shared_ptr<Connection> connection,const std::string & path)18 std::pair<int32_t, std::shared_ptr<Transaction>> Transaction::Create(
19 int32_t type, std::shared_ptr<Connection> connection, const std::string &path)
20 {
21 if (creator_ != nullptr) {
22 return creator_(type, std::move(connection), path);
23 }
24 return { E_ERROR, nullptr };
25 }
26
RegisterCreator(Creator creator)27 int32_t Transaction::RegisterCreator(Creator creator)
28 {
29 creator_ = std::move(creator);
30 return E_OK;
31 }
32
BatchInsert(const std::string & table,const RefRows & rows,Resolution resolution)33 std::pair<int32_t, int64_t> Transaction::BatchInsert(
34 const std::string &table, const RefRows &rows, Resolution resolution)
35 {
36 auto [code, result] = BatchInsert(table, rows, {}, resolution);
37 return { code, result.changed };
38 }
39
BatchInsert(const std::string & table,const RefRows & rows,const std::vector<std::string> & returningFields,Resolution resolution)40 std::pair<int32_t, Results> Transaction::BatchInsert(const std::string &table, const RefRows &rows,
41 const std::vector<std::string> &returningFields, Resolution resolution)
42 {
43 return { E_NOT_SUPPORT, -1 };
44 }
45
Update(const std::string & table,const Row & row,const std::string & where,const Values & args,Resolution resolution)46 std::pair<int, int> Transaction::Update(
47 const std::string &table, const Row &row, const std::string &where, const Values &args, Resolution resolution)
48 {
49 AbsRdbPredicates predicates(table);
50 predicates.SetWhereClause(where);
51 predicates.SetBindArgs(args);
52 return Update(row, predicates, resolution);
53 }
54
Update(const Row & row,const AbsRdbPredicates & predicates,Resolution resolution)55 std::pair<int32_t, int32_t> Transaction::Update(
56 const Row &row, const AbsRdbPredicates &predicates, Resolution resolution)
57 {
58 auto [code, result] = Update(row, predicates, {}, resolution);
59 return { code, result.changed };
60 }
61
Update(const Row & row,const AbsRdbPredicates & predicates,const std::vector<std::string> & returningFields,Resolution resolution)62 std::pair<int32_t, Results> Transaction::Update(const Row &row, const AbsRdbPredicates &predicates,
63 const std::vector<std::string> &returningFields, Resolution resolution)
64 {
65 return { E_NOT_SUPPORT, -1 };
66 }
67
Delete(const std::string & table,const std::string & whereClause,const Values & args)68 std::pair<int32_t, int32_t> Transaction::Delete(
69 const std::string &table, const std::string &whereClause, const Values &args)
70 {
71 AbsRdbPredicates predicates(table);
72 predicates.SetWhereClause(whereClause);
73 predicates.SetBindArgs(args);
74 return Delete(predicates);
75 }
76
Delete(const AbsRdbPredicates & predicates)77 std::pair<int32_t, int32_t> Transaction::Delete(const AbsRdbPredicates &predicates)
78 {
79 auto [code, result] = Delete(predicates, {});
80 return { code, result.changed };
81 }
82
Delete(const AbsRdbPredicates & predicates,const std::vector<std::string> & returningFields)83 std::pair<int32_t, Results> Transaction::Delete(
84 const AbsRdbPredicates &predicates, const std::vector<std::string> &returningFields)
85 {
86 return { E_NOT_SUPPORT, -1 };
87 }
88
Execute(const std::string & sql,const Values & args)89 std::pair<int32_t, ValueObject> Transaction::Execute(const std::string &sql, const Values &args)
90 {
91 return { E_NOT_SUPPORT, -1 };
92 }
93
ExecuteExt(const std::string & sql,const Values & args)94 std::pair<int32_t, Results> Transaction::ExecuteExt(const std::string &sql, const Values &args)
95 {
96 return { E_NOT_SUPPORT, -1 };
97 }
98 } // namespace OHOS::NativeRdb
99