Mercurial > hg > orthanc-databases
comparison Framework/MySQL/MySQLTransaction.cpp @ 214:ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Mar 2021 13:56:26 +0100 |
parents | 3236894320d6 |
children | ee5858d438dc |
comparison
equal
deleted
inserted
replaced
213:c2e4a909de0e | 214:ab96698c73a3 |
---|---|
31 | 31 |
32 namespace OrthancDatabases | 32 namespace OrthancDatabases |
33 { | 33 { |
34 MySQLTransaction::MySQLTransaction(MySQLDatabase& db) : | 34 MySQLTransaction::MySQLTransaction(MySQLDatabase& db) : |
35 db_(db), | 35 db_(db), |
36 readOnly_(true), | |
37 active_(false) | 36 active_(false) |
38 { | 37 { |
39 db_.Execute("START TRANSACTION", false); | 38 db_.Execute("START TRANSACTION", false); |
40 active_ = true; | 39 active_ = true; |
41 } | 40 } |
63 { | 62 { |
64 if (active_) | 63 if (active_) |
65 { | 64 { |
66 db_.Execute("ROLLBACK", false); | 65 db_.Execute("ROLLBACK", false); |
67 active_ = false; | 66 active_ = false; |
68 readOnly_ = true; | |
69 } | 67 } |
70 else | 68 else |
71 { | 69 { |
72 LOG(ERROR) << "MySQL: This transaction is already finished"; | 70 LOG(ERROR) << "MySQL: This transaction is already finished"; |
73 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 71 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
79 { | 77 { |
80 if (active_) | 78 if (active_) |
81 { | 79 { |
82 db_.Execute("COMMIT", false); | 80 db_.Execute("COMMIT", false); |
83 active_ = false; | 81 active_ = false; |
84 readOnly_ = true; | |
85 } | 82 } |
86 else | 83 else |
87 { | 84 { |
88 LOG(ERROR) << "MySQL: This transaction is already finished"; | 85 LOG(ERROR) << "MySQL: This transaction is already finished"; |
89 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 86 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
92 | 89 |
93 | 90 |
94 IResult* MySQLTransaction::Execute(IPrecompiledStatement& statement, | 91 IResult* MySQLTransaction::Execute(IPrecompiledStatement& statement, |
95 const Dictionary& parameters) | 92 const Dictionary& parameters) |
96 { | 93 { |
97 std::unique_ptr<IResult> result(dynamic_cast<MySQLStatement&>(statement).Execute(*this, parameters)); | 94 return dynamic_cast<MySQLStatement&>(statement).Execute(*this, parameters); |
98 | |
99 if (!statement.IsReadOnly()) | |
100 { | |
101 readOnly_ = false; | |
102 } | |
103 | |
104 return result.release(); | |
105 } | 95 } |
106 | 96 |
107 | 97 |
108 void MySQLTransaction::ExecuteWithoutResult(IPrecompiledStatement& statement, | 98 void MySQLTransaction::ExecuteWithoutResult(IPrecompiledStatement& statement, |
109 const Dictionary& parameters) | 99 const Dictionary& parameters) |
110 { | 100 { |
111 dynamic_cast<MySQLStatement&>(statement).ExecuteWithoutResult(*this, parameters); | 101 dynamic_cast<MySQLStatement&>(statement).ExecuteWithoutResult(*this, parameters); |
112 | |
113 if (!statement.IsReadOnly()) | |
114 { | |
115 readOnly_ = false; | |
116 } | |
117 } | 102 } |
118 } | 103 } |