Mercurial > hg > orthanc
comparison Core/SQLite/Transaction.cpp @ 1582:bd1889029cbb
encoding of exceptions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 25 Aug 2015 17:39:38 +0200 |
parents | 63d47b1fa239 |
children | b1291df2f780 |
comparison
equal
deleted
inserted
replaced
1581:357c4bb15701 | 1582:bd1889029cbb |
---|---|
62 | 62 |
63 void Transaction::Begin() | 63 void Transaction::Begin() |
64 { | 64 { |
65 if (isOpen_) | 65 if (isOpen_) |
66 { | 66 { |
67 throw OrthancSQLiteException("SQLite: Beginning a transaction twice!"); | 67 throw OrthancSQLiteException(ErrorCode_SQLiteTransactionAlreadyStarted); |
68 } | 68 } |
69 | 69 |
70 isOpen_ = connection_.BeginTransaction(); | 70 isOpen_ = connection_.BeginTransaction(); |
71 if (!isOpen_) | 71 if (!isOpen_) |
72 { | 72 { |
73 throw OrthancSQLiteException("SQLite: Unable to create a transaction"); | 73 throw OrthancSQLiteException(ErrorCode_SQLiteTransactionBegin); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 void Transaction::Rollback() | 77 void Transaction::Rollback() |
78 { | 78 { |
79 if (!isOpen_) | 79 if (!isOpen_) |
80 { | 80 { |
81 throw OrthancSQLiteException("SQLite: Attempting to roll back a nonexistent transaction. " | 81 throw OrthancSQLiteException(ErrorCode_SQLiteRollbackWithoutTransaction); |
82 "Did you remember to call Begin()?"); | |
83 } | 82 } |
84 | 83 |
85 isOpen_ = false; | 84 isOpen_ = false; |
86 | 85 |
87 connection_.RollbackTransaction(); | 86 connection_.RollbackTransaction(); |
89 | 88 |
90 void Transaction::Commit() | 89 void Transaction::Commit() |
91 { | 90 { |
92 if (!isOpen_) | 91 if (!isOpen_) |
93 { | 92 { |
94 throw OrthancSQLiteException("SQLite: Attempting to roll back a nonexistent transaction. " | 93 throw OrthancSQLiteException(ErrorCode_SQLiteRollbackWithoutTransaction); |
95 "Did you remember to call Begin()?"); | |
96 } | 94 } |
97 | 95 |
98 isOpen_ = false; | 96 isOpen_ = false; |
99 | 97 |
100 if (!connection_.CommitTransaction()) | 98 if (!connection_.CommitTransaction()) |
101 { | 99 { |
102 throw OrthancSQLiteException("SQLite: Failure when committing the transaction"); | 100 throw OrthancSQLiteException(ErrorCode_SQLiteTransactionCommit); |
103 } | 101 } |
104 } | 102 } |
105 } | 103 } |
106 } | 104 } |