Mercurial > hg > orthanc-databases
annotate PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 106:b559af8fe6e0
Remove "ASSERT" in SQL for compatibility with older releases of PostgreSQL
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 Jan 2019 15:35:52 +0100 |
parents | e61587582cef |
children | cc3dc759c989 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
67 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "PostgreSQLIndex.h" | |
23 | |
24 #include "../../Framework/Plugins/GlobalProperties.h" | |
25 #include "../../Framework/PostgreSQL/PostgreSQLDatabase.h" | |
26 #include "../../Framework/PostgreSQL/PostgreSQLTransaction.h" | |
27 | |
28 #include <EmbeddedResources.h> // Auto-generated file | |
29 | |
30 #include <Core/Logging.h> | |
31 #include <Core/OrthancException.h> | |
32 | |
33 | |
34 namespace Orthanc | |
35 { | |
36 // Some aliases for internal properties | |
37 static const GlobalProperty GlobalProperty_HasTrigramIndex = GlobalProperty_DatabaseInternal0; | |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
38 static const GlobalProperty GlobalProperty_HasCreateInstance = GlobalProperty_DatabaseInternal1; |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
39 static const GlobalProperty GlobalProperty_HasFastCountResources = GlobalProperty_DatabaseInternal2; |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
40 static const GlobalProperty GlobalProperty_GetLastChangeIndex = GlobalProperty_DatabaseInternal3; |
0 | 41 } |
42 | |
43 | |
44 namespace OrthancDatabases | |
45 { | |
46 IDatabase* PostgreSQLIndex::OpenInternal() | |
47 { | |
48 uint32_t expectedVersion = 6; | |
49 if (context_) | |
50 { | |
51 expectedVersion = OrthancPluginGetExpectedDatabaseVersion(context_); | |
52 } | |
53 else | |
54 { | |
55 // This case only occurs during unit testing | |
56 expectedVersion = 6; | |
57 } | |
58 | |
59 // Check the expected version of the database | |
60 if (expectedVersion != 6) | |
61 { | |
62 LOG(ERROR) << "This database plugin is incompatible with your version of Orthanc " | |
63 << "expecting the DB schema version " << expectedVersion | |
64 << ", but this plugin is only compatible with version 6"; | |
65 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); | |
66 } | |
67 | |
68 std::auto_ptr<PostgreSQLDatabase> db(new PostgreSQLDatabase(parameters_)); | |
69 | |
70 db->Open(); | |
71 | |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
72 if (parameters_.HasLock()) |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
73 { |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
74 db->AdvisoryLock(42 /* some arbitrary constant */); |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
75 } |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
76 |
0 | 77 if (clearAll_) |
78 { | |
79 db->ClearAll(); | |
80 } | |
81 | |
82 { | |
83 PostgreSQLTransaction t(*db); | |
84 | |
85 if (!db->DoesTableExist("Resources")) | |
86 { | |
87 std::string query; | |
88 | |
89 Orthanc::EmbeddedResources::GetFileResource | |
90 (query, Orthanc::EmbeddedResources::POSTGRESQL_PREPARE_INDEX); | |
91 db->Execute(query); | |
92 | |
93 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); | |
94 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, 1); | |
95 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasTrigramIndex, 0); | |
96 } | |
97 | |
98 if (!db->DoesTableExist("Resources")) | |
99 { | |
100 LOG(ERROR) << "Corrupted PostgreSQL database"; | |
101 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
102 } | |
103 | |
104 int version = 0; | |
105 if (!LookupGlobalIntegerProperty(version, *db, t, Orthanc::GlobalProperty_DatabaseSchemaVersion) || | |
106 version != 6) | |
107 { | |
108 LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema version: " << version; | |
109 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
110 } | |
111 | |
112 int revision; | |
113 if (!LookupGlobalIntegerProperty(revision, *db, t, Orthanc::GlobalProperty_DatabasePatchLevel)) | |
114 { | |
115 revision = 1; | |
116 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, revision); | |
117 } | |
118 | |
56
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
119 if (revision != 1) |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
120 { |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
121 LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema revision: " << revision; |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
122 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
123 } |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
124 |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
125 t.Commit(); |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
126 } |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
127 |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
128 { |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
129 PostgreSQLTransaction t(*db); |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
130 |
0 | 131 int hasTrigram = 0; |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
132 if (!LookupGlobalIntegerProperty(hasTrigram, *db, t, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
133 Orthanc::GlobalProperty_HasTrigramIndex) || |
0 | 134 hasTrigram != 1) |
135 { | |
13
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
136 /** |
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
137 * Apply fix for performance issue (speed up wildcard search |
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
138 * by using GIN trigrams). This implements the patch suggested |
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
139 * in issue #47, BUT we also keep the original |
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
140 * "DicomIdentifiersIndexValues", as it leads to better |
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
141 * performance for "strict" searches (i.e. searches involving |
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
142 * no wildcard). |
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
143 * https://www.postgresql.org/docs/current/static/pgtrgm.html |
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
144 * https://bitbucket.org/sjodogne/orthanc/issues/47/index-improvements-for-pg-plugin |
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
145 **/ |
0 | 146 try |
147 { | |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
148 // We've observed 9 minutes on DB with 100000 studies |
20 | 149 LOG(WARNING) << "Trying to enable trigram matching on the PostgreSQL database " |
57
f4d5c2c70f98
Suggestion by Karsten Hilbert: CREATE EXTENSION IF NOT EXISTS pg_trgm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
150 << "to speed up wildcard searches. This may take several minutes"; |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
151 |
0 | 152 db->Execute( |
57
f4d5c2c70f98
Suggestion by Karsten Hilbert: CREATE EXTENSION IF NOT EXISTS pg_trgm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
153 "CREATE EXTENSION IF NOT EXISTS pg_trgm; " |
13
927264a0c137
preserve the original index
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
154 "CREATE INDEX DicomIdentifiersIndexValues2 ON DicomIdentifiers USING gin(value gin_trgm_ops);"); |
0 | 155 |
156 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasTrigramIndex, 1); | |
19 | 157 LOG(WARNING) << "Trigram index has been created"; |
56
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
158 |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
159 t.Commit(); |
0 | 160 } |
161 catch (Orthanc::OrthancException&) | |
162 { | |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
163 LOG(WARNING) << "Performance warning: Your PostgreSQL server does " |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
164 << "not support trigram matching"; |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
165 LOG(WARNING) << "-> Consider installing the \"pg_trgm\" extension on the " |
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
166 << "PostgreSQL server, e.g. on Debian: sudo apt install postgresql-contrib"; |
0 | 167 } |
168 } | |
77
a2134531473c
avoid warnings "An active PostgreSQL transaction was dismissed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
169 else |
a2134531473c
avoid warnings "An active PostgreSQL transaction was dismissed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
170 { |
a2134531473c
avoid warnings "An active PostgreSQL transaction was dismissed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
171 t.Commit(); |
a2134531473c
avoid warnings "An active PostgreSQL transaction was dismissed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
172 } |
0 | 173 } |
174 | |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
175 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
176 PostgreSQLTransaction t(*db); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
177 |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
178 int property = 0; |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
179 if (!LookupGlobalIntegerProperty(property, *db, t, |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
180 Orthanc::GlobalProperty_HasCreateInstance) || |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
181 property != 2) |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
182 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
183 LOG(INFO) << "Installing the CreateInstance extension"; |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
184 |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
185 if (property == 1) |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
186 { |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
187 // Drop older, experimental versions of this extension |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
188 db->Execute("DROP FUNCTION CreateInstance(" |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
189 "IN patient TEXT, IN study TEXT, IN series TEXT, in instance TEXT)"); |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
190 } |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
191 |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
192 std::string query; |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
193 Orthanc::EmbeddedResources::GetFileResource |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
194 (query, Orthanc::EmbeddedResources::POSTGRESQL_CREATE_INSTANCE); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
195 db->Execute(query); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
196 |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
197 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasCreateInstance, 2); |
77
a2134531473c
avoid warnings "An active PostgreSQL transaction was dismissed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
198 } |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
199 |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
200 |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
201 if (!LookupGlobalIntegerProperty(property, *db, t, |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
202 Orthanc::GlobalProperty_GetTotalSizeIsFast) || |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
203 property != 1) |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
204 { |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
205 LOG(INFO) << "Installing the FastTotalSize extension"; |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
206 |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
207 std::string query; |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
208 Orthanc::EmbeddedResources::GetFileResource |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
209 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_TOTAL_SIZE); |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
210 db->Execute(query); |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
211 |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
212 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_GetTotalSizeIsFast, 1); |
77
a2134531473c
avoid warnings "An active PostgreSQL transaction was dismissed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
213 } |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
214 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
215 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
216 // Installing this extension requires the "GlobalIntegers" table |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
217 // created by the "FastTotalSize" extension |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
218 property = 0; |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
219 if (!LookupGlobalIntegerProperty(property, *db, t, |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
220 Orthanc::GlobalProperty_HasFastCountResources) || |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
221 property != 1) |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
222 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
223 LOG(INFO) << "Installing the FastCountResources extension"; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
224 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
225 std::string query; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
226 Orthanc::EmbeddedResources::GetFileResource |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
227 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_COUNT_RESOURCES); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
228 db->Execute(query); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
229 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
230 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasFastCountResources, 1); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
231 } |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
232 |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
233 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
234 // Installing this extension requires the "GlobalIntegers" table |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
235 // created by the "GetLastChangeIndex" extension |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
236 property = 0; |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
237 if (!LookupGlobalIntegerProperty(property, *db, t, |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
238 Orthanc::GlobalProperty_GetLastChangeIndex) || |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
239 property != 1) |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
240 { |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
241 LOG(INFO) << "Installing the GetLastChangeIndex extension"; |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
242 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
243 std::string query; |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
244 Orthanc::EmbeddedResources::GetFileResource |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
245 (query, Orthanc::EmbeddedResources::POSTGRESQL_GET_LAST_CHANGE_INDEX); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
246 db->Execute(query); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
247 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
248 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_GetLastChangeIndex, 1); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
249 } |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
250 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
251 t.Commit(); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
252 } |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
253 |
0 | 254 return db.release(); |
255 } | |
256 | |
257 | |
258 PostgreSQLIndex::PostgreSQLIndex(const PostgreSQLParameters& parameters) : | |
259 IndexBackend(new Factory(*this)), | |
260 context_(NULL), | |
261 parameters_(parameters), | |
262 clearAll_(false) | |
263 { | |
264 } | |
265 | |
266 | |
267 int64_t PostgreSQLIndex::CreateResource(const char* publicId, | |
268 OrthancPluginResourceType type) | |
269 { | |
270 DatabaseManager::CachedStatement statement( | |
271 STATEMENT_FROM_HERE, GetManager(), | |
272 "INSERT INTO Resources VALUES(${}, ${type}, ${id}, NULL) RETURNING internalId"); | |
273 | |
274 statement.SetParameterType("id", ValueType_Utf8String); | |
275 statement.SetParameterType("type", ValueType_Integer64); | |
276 | |
277 Dictionary args; | |
278 args.SetUtf8Value("id", publicId); | |
279 args.SetIntegerValue("type", static_cast<int>(type)); | |
280 | |
281 statement.Execute(args); | |
282 | |
283 return ReadInteger64(statement, 0); | |
284 } | |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
285 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
286 |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
287 uint64_t PostgreSQLIndex::GetTotalCompressedSize() |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
288 { |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
289 // Fast version if extension "./FastTotalSize.sql" is installed |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
290 uint64_t result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
291 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
292 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
293 DatabaseManager::CachedStatement statement( |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
294 STATEMENT_FROM_HERE, GetManager(), |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
295 "SELECT value FROM GlobalIntegers WHERE key = 0"); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
296 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
297 statement.SetReadOnly(true); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
298 statement.Execute(); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
299 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
300 result = static_cast<uint64_t>(ReadInteger64(statement, 0)); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
301 } |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
302 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
303 assert(result == IndexBackend::GetTotalCompressedSize()); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
304 return result; |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
305 } |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
306 |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
307 |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
308 uint64_t PostgreSQLIndex::GetTotalUncompressedSize() |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
309 { |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
310 // Fast version if extension "./FastTotalSize.sql" is installed |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
311 uint64_t result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
312 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
313 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
314 DatabaseManager::CachedStatement statement( |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
315 STATEMENT_FROM_HERE, GetManager(), |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
316 "SELECT value FROM GlobalIntegers WHERE key = 1"); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
317 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
318 statement.SetReadOnly(true); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
319 statement.Execute(); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
320 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
321 result = static_cast<uint64_t>(ReadInteger64(statement, 0)); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
322 } |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
323 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
324 assert(result == IndexBackend::GetTotalUncompressedSize()); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
325 return result; |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
326 } |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
327 |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
328 |
78 | 329 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
330 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
331 const char* hashPatient, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
332 const char* hashStudy, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
333 const char* hashSeries, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
334 const char* hashInstance) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
335 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
336 DatabaseManager::CachedStatement statement( |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
337 STATEMENT_FROM_HERE, GetManager(), |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
338 "SELECT * FROM CreateInstance(${patient}, ${study}, ${series}, ${instance})"); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
339 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
340 statement.SetParameterType("patient", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
341 statement.SetParameterType("study", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
342 statement.SetParameterType("series", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
343 statement.SetParameterType("instance", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
344 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
345 Dictionary args; |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
346 args.SetUtf8Value("patient", hashPatient); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
347 args.SetUtf8Value("study", hashStudy); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
348 args.SetUtf8Value("series", hashSeries); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
349 args.SetUtf8Value("instance", hashInstance); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
350 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
351 statement.Execute(args); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
352 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
353 if (statement.IsDone() || |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
354 statement.GetResultFieldsCount() != 8) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
355 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
356 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
357 } |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
358 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
359 for (size_t i = 0; i < 8; i++) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
360 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
361 statement.SetResultFieldType(i, ValueType_Integer64); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
362 } |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
363 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
364 result.isNewInstance = (ReadInteger64(statement, 3) == 1); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
365 result.instanceId = ReadInteger64(statement, 7); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
366 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
367 if (result.isNewInstance) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
368 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
369 result.isNewPatient = (ReadInteger64(statement, 0) == 1); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
370 result.isNewStudy = (ReadInteger64(statement, 1) == 1); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
371 result.isNewSeries = (ReadInteger64(statement, 2) == 1); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
372 result.patientId = ReadInteger64(statement, 4); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
373 result.studyId = ReadInteger64(statement, 5); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
374 result.seriesId = ReadInteger64(statement, 6); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
375 } |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
376 } |
73
aa81c1c80c75
fix compatibility with older sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
72
diff
changeset
|
377 #endif |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
378 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
379 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
380 uint64_t PostgreSQLIndex::GetResourceCount(OrthancPluginResourceType resourceType) |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
381 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
382 // Optimized version thanks to the "FastCountResources.sql" extension |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
383 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
384 assert(OrthancPluginResourceType_Patient == 0 && |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
385 OrthancPluginResourceType_Study == 1 && |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
386 OrthancPluginResourceType_Series == 2 && |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
387 OrthancPluginResourceType_Instance == 3); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
388 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
389 uint64_t result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
390 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
391 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
392 DatabaseManager::CachedStatement statement( |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
393 STATEMENT_FROM_HERE, GetManager(), |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
394 "SELECT value FROM GlobalIntegers WHERE key = ${key}"); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
395 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
396 statement.SetParameterType("key", ValueType_Integer64); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
397 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
398 Dictionary args; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
399 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
400 // For an explanation of the "+ 2" below, check out "FastCountResources.sql" |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
401 args.SetIntegerValue("key", static_cast<int>(resourceType + 2)); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
402 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
403 statement.SetReadOnly(true); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
404 statement.Execute(args); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
405 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
406 result = static_cast<uint64_t>(ReadInteger64(statement, 0)); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
407 } |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
408 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
409 assert(result == IndexBackend::GetResourceCount(resourceType)); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
410 return result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
411 } |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
412 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
413 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
414 int64_t PostgreSQLIndex::GetLastChangeIndex() |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
415 { |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
416 DatabaseManager::CachedStatement statement( |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
417 STATEMENT_FROM_HERE, GetManager(), |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
418 "SELECT value FROM GlobalIntegers WHERE key = 6"); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
419 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
420 statement.SetReadOnly(true); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
421 statement.Execute(); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
422 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
423 return ReadInteger64(statement, 0); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
424 } |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
425 |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
426 |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
427 void PostgreSQLIndex::TagMostRecentPatient(int64_t patient) |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
428 { |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
429 // This behavior is implemented in "CreateInstance()", and no |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
430 // backward compatibility is necessary |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
431 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
432 } |
0 | 433 } |