comparison OrthancFramework/Sources/SQLite/OrthancSQLiteException.h @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Core/SQLite/OrthancSQLiteException.h@fa5ad4368fe3
children c847b0dfd255
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 *
4 * Copyright (C) 2012-2016 Sebastien Jodogne <s.jodogne@orthanc-labs.com>,
5 * Medical Physics Department, CHU of Liege, Belgium
6 *
7 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
18 * distribution.
19 * * Neither the name of Google Inc., the name of the CHU of Liege,
20 * nor the names of its contributors may be used to endorse or promote
21 * products derived from this software without specific prior written
22 * permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 **/
36
37
38 #pragma once
39
40
41 #if ORTHANC_ENABLE_SQLITE != 1
42 # error Macro ORTHANC_ENABLE_SQLITE must be set to 1 to use SQLite
43 #endif
44
45
46 #if ORTHANC_SQLITE_STANDALONE == 1
47 #include <stdexcept>
48
49 namespace Orthanc
50 {
51 namespace SQLite
52 {
53 // Auto-generated by "Resources/GenerateErrorCodes.py"
54 enum ErrorCode
55 {
56 ErrorCode_ParameterOutOfRange,
57 ErrorCode_BadParameterType,
58 ErrorCode_SQLiteNotOpened,
59 ErrorCode_SQLiteAlreadyOpened,
60 ErrorCode_SQLiteCannotOpen,
61 ErrorCode_SQLiteStatementAlreadyUsed,
62 ErrorCode_SQLiteExecute,
63 ErrorCode_SQLiteRollbackWithoutTransaction,
64 ErrorCode_SQLiteCommitWithoutTransaction,
65 ErrorCode_SQLiteRegisterFunction,
66 ErrorCode_SQLiteFlush,
67 ErrorCode_SQLiteCannotRun,
68 ErrorCode_SQLiteCannotStep,
69 ErrorCode_SQLiteBindOutOfRange,
70 ErrorCode_SQLitePrepareStatement,
71 ErrorCode_SQLiteTransactionAlreadyStarted,
72 ErrorCode_SQLiteTransactionCommit,
73 ErrorCode_SQLiteTransactionBegin
74 };
75
76 class OrthancSQLiteException : public ::std::runtime_error
77 {
78 public:
79 OrthancSQLiteException(ErrorCode error) :
80 ::std::runtime_error(EnumerationToString(error))
81 {
82 }
83
84 // Auto-generated by "Resources/GenerateErrorCodes.py"
85 static const char* EnumerationToString(ErrorCode code)
86 {
87 switch (code)
88 {
89 case ErrorCode_ParameterOutOfRange:
90 return "Parameter out of range";
91
92 case ErrorCode_BadParameterType:
93 return "Bad type for a parameter";
94
95 case ErrorCode_SQLiteNotOpened:
96 return "SQLite: The database is not opened";
97
98 case ErrorCode_SQLiteAlreadyOpened:
99 return "SQLite: Connection is already open";
100
101 case ErrorCode_SQLiteCannotOpen:
102 return "SQLite: Unable to open the database";
103
104 case ErrorCode_SQLiteStatementAlreadyUsed:
105 return "SQLite: This cached statement is already being referred to";
106
107 case ErrorCode_SQLiteExecute:
108 return "SQLite: Cannot execute a command";
109
110 case ErrorCode_SQLiteRollbackWithoutTransaction:
111 return "SQLite: Rolling back a nonexistent transaction (have you called Begin()?)";
112
113 case ErrorCode_SQLiteCommitWithoutTransaction:
114 return "SQLite: Committing a nonexistent transaction";
115
116 case ErrorCode_SQLiteRegisterFunction:
117 return "SQLite: Unable to register a function";
118
119 case ErrorCode_SQLiteFlush:
120 return "SQLite: Unable to flush the database";
121
122 case ErrorCode_SQLiteCannotRun:
123 return "SQLite: Cannot run a cached statement";
124
125 case ErrorCode_SQLiteCannotStep:
126 return "SQLite: Cannot step over a cached statement";
127
128 case ErrorCode_SQLiteBindOutOfRange:
129 return "SQLite: Bing a value while out of range (serious error)";
130
131 case ErrorCode_SQLitePrepareStatement:
132 return "SQLite: Cannot prepare a cached statement";
133
134 case ErrorCode_SQLiteTransactionAlreadyStarted:
135 return "SQLite: Beginning the same transaction twice";
136
137 case ErrorCode_SQLiteTransactionCommit:
138 return "SQLite: Failure when committing the transaction";
139
140 case ErrorCode_SQLiteTransactionBegin:
141 return "SQLite: Cannot start a transaction";
142
143 default:
144 return "Unknown error code";
145 }
146 }
147 };
148 }
149 }
150
151 #else
152 # include "../OrthancException.h"
153 # define OrthancSQLiteException ::Orthanc::OrthancException
154 #endif