Mercurial > hg > orthanc
comparison Core/SQLite/Connection.cpp @ 59:c996319e90bc orthanc-renaming
renaming in Core
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 16 Sep 2012 09:28:56 +0200 |
parents | a15e90e5d6fc |
children | 0e97abc7b950 |
comparison
equal
deleted
inserted
replaced
58:6da7fc87efaa | 59:c996319e90bc |
---|---|
1 /** | 1 /** |
2 * Palanthir - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | 4 * Belgium |
5 * | 5 * |
6 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 6 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
7 * | 7 * |
41 #include <sqlite3.h> | 41 #include <sqlite3.h> |
42 #include <string.h> | 42 #include <string.h> |
43 | 43 |
44 | 44 |
45 | 45 |
46 namespace Palanthir | 46 namespace Orthanc |
47 { | 47 { |
48 namespace SQLite | 48 namespace SQLite |
49 { | 49 { |
50 Connection::Connection() : | 50 Connection::Connection() : |
51 db_(NULL), | 51 db_(NULL), |
63 | 63 |
64 void Connection::CheckIsOpen() const | 64 void Connection::CheckIsOpen() const |
65 { | 65 { |
66 if (!db_) | 66 if (!db_) |
67 { | 67 { |
68 throw PalanthirException("SQLite: The database is not opened"); | 68 throw OrthancException("SQLite: The database is not opened"); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 void Connection::Open(const std::string& path) | 72 void Connection::Open(const std::string& path) |
73 { | 73 { |
74 if (db_) | 74 if (db_) |
75 { | 75 { |
76 throw PalanthirException("SQLite: Connection is already open"); | 76 throw OrthancException("SQLite: Connection is already open"); |
77 } | 77 } |
78 | 78 |
79 int err = sqlite3_open(path.c_str(), &db_); | 79 int err = sqlite3_open(path.c_str(), &db_); |
80 if (err != SQLITE_OK) | 80 if (err != SQLITE_OK) |
81 { | 81 { |
82 Close(); | 82 Close(); |
83 db_ = NULL; | 83 db_ = NULL; |
84 throw PalanthirException("SQLite: Unable to open the database"); | 84 throw OrthancException("SQLite: Unable to open the database"); |
85 } | 85 } |
86 | 86 |
87 // Execute PRAGMAs at this point | 87 // Execute PRAGMAs at this point |
88 // http://www.sqlite.org/pragma.html | 88 // http://www.sqlite.org/pragma.html |
89 Execute("PRAGMA FOREIGN_KEYS=ON;"); | 89 Execute("PRAGMA FOREIGN_KEYS=ON;"); |
131 CachedStatements::iterator i = cachedStatements_.find(id); | 131 CachedStatements::iterator i = cachedStatements_.find(id); |
132 if (i != cachedStatements_.end()) | 132 if (i != cachedStatements_.end()) |
133 { | 133 { |
134 if (i->second->GetReferenceCount() >= 1) | 134 if (i->second->GetReferenceCount() >= 1) |
135 { | 135 { |
136 throw PalanthirException("SQLite: This cached statement is already being referred to"); | 136 throw OrthancException("SQLite: This cached statement is already being referred to"); |
137 } | 137 } |
138 | 138 |
139 return *i->second; | 139 return *i->second; |
140 } | 140 } |
141 else | 141 else |
152 CheckIsOpen(); | 152 CheckIsOpen(); |
153 | 153 |
154 int error = sqlite3_exec(db_, sql, NULL, NULL, NULL); | 154 int error = sqlite3_exec(db_, sql, NULL, NULL, NULL); |
155 if (error == SQLITE_ERROR) | 155 if (error == SQLITE_ERROR) |
156 { | 156 { |
157 throw PalanthirException("SQLite Execute error: " + std::string(sqlite3_errmsg(db_))); | 157 throw OrthancException("SQLite Execute error: " + std::string(sqlite3_errmsg(db_))); |
158 } | 158 } |
159 else | 159 else |
160 { | 160 { |
161 return error == SQLITE_OK; | 161 return error == SQLITE_OK; |
162 } | 162 } |
273 | 273 |
274 void Connection::RollbackTransaction() | 274 void Connection::RollbackTransaction() |
275 { | 275 { |
276 if (!transactionNesting_) | 276 if (!transactionNesting_) |
277 { | 277 { |
278 throw PalanthirException("Rolling back a nonexistent transaction"); | 278 throw OrthancException("Rolling back a nonexistent transaction"); |
279 } | 279 } |
280 | 280 |
281 transactionNesting_--; | 281 transactionNesting_--; |
282 | 282 |
283 if (transactionNesting_ > 0) | 283 if (transactionNesting_ > 0) |
292 | 292 |
293 bool Connection::CommitTransaction() | 293 bool Connection::CommitTransaction() |
294 { | 294 { |
295 if (!transactionNesting_) | 295 if (!transactionNesting_) |
296 { | 296 { |
297 throw PalanthirException("Committing a nonexistent transaction"); | 297 throw OrthancException("Committing a nonexistent transaction"); |
298 } | 298 } |
299 transactionNesting_--; | 299 transactionNesting_--; |
300 | 300 |
301 if (transactionNesting_ > 0) | 301 if (transactionNesting_ > 0) |
302 { | 302 { |
360 ScalarFunctionDestroyer); | 360 ScalarFunctionDestroyer); |
361 | 361 |
362 if (err != SQLITE_OK) | 362 if (err != SQLITE_OK) |
363 { | 363 { |
364 delete func; | 364 delete func; |
365 throw PalanthirException("SQLite: Unable to register a function"); | 365 throw OrthancException("SQLite: Unable to register a function"); |
366 } | 366 } |
367 | 367 |
368 return func; | 368 return func; |
369 } | 369 } |
370 | 370 |