Mercurial > hg > orthanc
comparison Core/SQLite/Connection.cpp @ 1582:bd1889029cbb
encoding of exceptions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 25 Aug 2015 17:39:38 +0200 |
parents | f967bdf8534e |
children | 9a3e03d6a4d5 |
comparison
equal
deleted
inserted
replaced
1581:357c4bb15701 | 1582:bd1889029cbb |
---|---|
73 | 73 |
74 void Connection::CheckIsOpen() const | 74 void Connection::CheckIsOpen() const |
75 { | 75 { |
76 if (!db_) | 76 if (!db_) |
77 { | 77 { |
78 throw OrthancSQLiteException("SQLite: The database is not opened"); | 78 throw OrthancSQLiteException(ErrorCode_SQLiteNotOpened); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 void Connection::Open(const std::string& path) | 82 void Connection::Open(const std::string& path) |
83 { | 83 { |
84 if (db_) | 84 if (db_) |
85 { | 85 { |
86 throw OrthancSQLiteException("SQLite: Connection is already open"); | 86 throw OrthancSQLiteException(ErrorCode_SQLiteAlreadyOpened); |
87 } | 87 } |
88 | 88 |
89 int err = sqlite3_open(path.c_str(), &db_); | 89 int err = sqlite3_open(path.c_str(), &db_); |
90 if (err != SQLITE_OK) | 90 if (err != SQLITE_OK) |
91 { | 91 { |
92 Close(); | 92 Close(); |
93 db_ = NULL; | 93 db_ = NULL; |
94 throw OrthancSQLiteException("SQLite: Unable to open the database"); | 94 throw OrthancSQLiteException(ErrorCode_SQLiteCannotOpen); |
95 } | 95 } |
96 | 96 |
97 // Execute PRAGMAs at this point | 97 // Execute PRAGMAs at this point |
98 // http://www.sqlite.org/pragma.html | 98 // http://www.sqlite.org/pragma.html |
99 Execute("PRAGMA FOREIGN_KEYS=ON;"); | 99 Execute("PRAGMA FOREIGN_KEYS=ON;"); |
135 CachedStatements::iterator i = cachedStatements_.find(id); | 135 CachedStatements::iterator i = cachedStatements_.find(id); |
136 if (i != cachedStatements_.end()) | 136 if (i != cachedStatements_.end()) |
137 { | 137 { |
138 if (i->second->GetReferenceCount() >= 1) | 138 if (i->second->GetReferenceCount() >= 1) |
139 { | 139 { |
140 throw OrthancSQLiteException("SQLite: This cached statement is already being referred to"); | 140 throw OrthancSQLiteException(ErrorCode_SQLiteStatementAlreadyUsed); |
141 } | 141 } |
142 | 142 |
143 return *i->second; | 143 return *i->second; |
144 } | 144 } |
145 else | 145 else |
160 CheckIsOpen(); | 160 CheckIsOpen(); |
161 | 161 |
162 int error = sqlite3_exec(db_, sql, NULL, NULL, NULL); | 162 int error = sqlite3_exec(db_, sql, NULL, NULL, NULL); |
163 if (error == SQLITE_ERROR) | 163 if (error == SQLITE_ERROR) |
164 { | 164 { |
165 throw OrthancSQLiteException("SQLite Execute error: " + std::string(sqlite3_errmsg(db_))); | 165 LOG(ERROR) << "SQLite execute error: " << sqlite3_errmsg(db_); |
166 throw OrthancSQLiteException(ErrorCode_SQLiteExecute); | |
166 } | 167 } |
167 else | 168 else |
168 { | 169 { |
169 return error == SQLITE_OK; | 170 return error == SQLITE_OK; |
170 } | 171 } |
281 | 282 |
282 void Connection::RollbackTransaction() | 283 void Connection::RollbackTransaction() |
283 { | 284 { |
284 if (!transactionNesting_) | 285 if (!transactionNesting_) |
285 { | 286 { |
286 throw OrthancSQLiteException("Rolling back a nonexistent transaction"); | 287 throw OrthancSQLiteException(ErrorCode_SQLiteRollbackWithoutTransaction); |
287 } | 288 } |
288 | 289 |
289 transactionNesting_--; | 290 transactionNesting_--; |
290 | 291 |
291 if (transactionNesting_ > 0) | 292 if (transactionNesting_ > 0) |
300 | 301 |
301 bool Connection::CommitTransaction() | 302 bool Connection::CommitTransaction() |
302 { | 303 { |
303 if (!transactionNesting_) | 304 if (!transactionNesting_) |
304 { | 305 { |
305 throw OrthancSQLiteException("Committing a nonexistent transaction"); | 306 throw OrthancSQLiteException(ErrorCode_SQLiteCommitWithoutTransaction); |
306 } | 307 } |
307 transactionNesting_--; | 308 transactionNesting_--; |
308 | 309 |
309 if (transactionNesting_ > 0) | 310 if (transactionNesting_ > 0) |
310 { | 311 { |
368 ScalarFunctionDestroyer); | 369 ScalarFunctionDestroyer); |
369 | 370 |
370 if (err != SQLITE_OK) | 371 if (err != SQLITE_OK) |
371 { | 372 { |
372 delete func; | 373 delete func; |
373 throw OrthancSQLiteException("SQLite: Unable to register a function"); | 374 throw OrthancSQLiteException(ErrorCode_SQLiteRegisterFunction); |
374 } | 375 } |
375 | 376 |
376 return func; | 377 return func; |
377 } | 378 } |
378 | 379 |
385 | 386 |
386 int err = sqlite3_wal_checkpoint(db_, NULL); | 387 int err = sqlite3_wal_checkpoint(db_, NULL); |
387 | 388 |
388 if (err != SQLITE_OK) | 389 if (err != SQLITE_OK) |
389 { | 390 { |
390 throw OrthancSQLiteException("SQLite: Unable to flush the database"); | 391 throw OrthancSQLiteException(ErrorCode_SQLiteFlush); |
391 } | 392 } |
392 } | 393 } |
393 } | 394 } |
394 } | 395 } |