comparison Core/SQLite/StatementReference.cpp @ 1220:9b9026560a5f

SQLite wrapper is now fully independent of Orthanc
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 10 Nov 2014 16:33:51 +0100
parents a811bdf8b8eb
children 3f62e1269cca
comparison
equal deleted inserted replaced
1219:c4ae92753d57 1220:9b9026560a5f
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, 3 *
4 * Belgium 4 * Copyright (C) 2012-2014 Sebastien Jodogne <s.jodogne@gmail.com>,
5 * Medical Physics Department, CHU of Liege, Belgium
5 * 6 *
6 * Copyright (c) 2012 The Chromium Authors. All rights reserved. 7 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
7 * 8 *
8 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are 10 * modification, are permitted provided that the following conditions are
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 **/ 35 **/
35 36
36 37
38 #if ORTHANC_SQLITE_STANDALONE != 1
37 #include "../PrecompiledHeaders.h" 39 #include "../PrecompiledHeaders.h"
40 #include <glog/logging.h>
41 #endif
42
38 #include "StatementReference.h" 43 #include "StatementReference.h"
39 44 #include "OrthancSQLiteException.h"
40 #include "../OrthancException.h"
41 45
42 #include <cassert> 46 #include <cassert>
43 #include <glog/logging.h>
44 #include "sqlite3.h" 47 #include "sqlite3.h"
45 48
46 namespace Orthanc 49 namespace Orthanc
47 { 50 {
48 namespace SQLite 51 namespace SQLite
63 StatementReference::StatementReference(sqlite3* database, 66 StatementReference::StatementReference(sqlite3* database,
64 const char* sql) 67 const char* sql)
65 { 68 {
66 if (database == NULL || sql == NULL) 69 if (database == NULL || sql == NULL)
67 { 70 {
68 throw OrthancException(ErrorCode_ParameterOutOfRange); 71 throw OrthancSQLiteException("Parameter out of range");
69 } 72 }
70 73
71 root_ = NULL; 74 root_ = NULL;
72 refCount_ = 0; 75 refCount_ = 0;
73 76
74 int error = sqlite3_prepare_v2(database, sql, -1, &statement_, NULL); 77 int error = sqlite3_prepare_v2(database, sql, -1, &statement_, NULL);
75 if (error != SQLITE_OK) 78 if (error != SQLITE_OK)
76 { 79 {
77 throw OrthancException("SQLite: " + std::string(sqlite3_errmsg(database))); 80 throw OrthancSQLiteException("SQLite: " + std::string(sqlite3_errmsg(database)));
78 } 81 }
79 82
80 assert(IsRoot()); 83 assert(IsRoot());
81 } 84 }
82 85
107 { 110 {
108 // There remain references to this object. We cannot throw 111 // There remain references to this object. We cannot throw
109 // an exception because: 112 // an exception because:
110 // http://www.parashift.com/c++-faq/dtors-shouldnt-throw.html 113 // http://www.parashift.com/c++-faq/dtors-shouldnt-throw.html
111 114
115 #if ORTHANC_SQLITE_STANDALONE != 1
112 LOG(ERROR) << "Bad value of the reference counter"; 116 LOG(ERROR) << "Bad value of the reference counter";
117 #endif
113 } 118 }
114 else if (statement_ != NULL) 119 else if (statement_ != NULL)
115 { 120 {
116 sqlite3_finalize(statement_); 121 sqlite3_finalize(statement_);
117 } 122 }
122 { 127 {
123 // There remain references to this object. We cannot throw 128 // There remain references to this object. We cannot throw
124 // an exception because: 129 // an exception because:
125 // http://www.parashift.com/c++-faq/dtors-shouldnt-throw.html 130 // http://www.parashift.com/c++-faq/dtors-shouldnt-throw.html
126 131
132 #if ORTHANC_SQLITE_STANDALONE != 1
127 LOG(ERROR) << "Bad value of the reference counter"; 133 LOG(ERROR) << "Bad value of the reference counter";
134 #endif
128 } 135 }
129 else 136 else
130 { 137 {
131 root_->refCount_--; 138 root_->refCount_--;
132 } 139 }