comparison MySQL/Plugins/MySQLIndex.cpp @ 110:441a472bfd93

new extension implemented for MySQL: CreateInstance
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Jan 2019 16:28:43 +0100
parents 3f31e3fa5114
children e26690365c25
comparison
equal deleted inserted replaced
109:3f31e3fa5114 110:441a472bfd93
128 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, revision); 128 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
129 } 129 }
130 130
131 if (revision == 2) 131 if (revision == 2)
132 { 132 {
133 // Install the "GetLastChangeIndex" extension
133 std::string query; 134 std::string query;
134 135
135 Orthanc::EmbeddedResources::GetFileResource 136 Orthanc::EmbeddedResources::GetFileResource
136 (query, Orthanc::EmbeddedResources::MYSQL_GET_LAST_CHANGE_INDEX); 137 (query, Orthanc::EmbeddedResources::MYSQL_GET_LAST_CHANGE_INDEX);
137 db->Execute(query, true); 138 db->Execute(query, true);
151 152
152 revision = 4; 153 revision = 4;
153 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, revision); 154 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
154 } 155 }
155 156
156 if (revision != 4) 157 if (revision == 4)
158 {
159 // Install the "CreateInstance" extension
160 std::string query;
161
162 Orthanc::EmbeddedResources::GetFileResource
163 (query, Orthanc::EmbeddedResources::MYSQL_CREATE_INSTANCE);
164 db->Execute(query, true);
165
166 revision = 5;
167 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
168 }
169
170 if (revision != 5)
157 { 171 {
158 LOG(ERROR) << "MySQL plugin is incompatible with database schema revision: " << revision; 172 LOG(ERROR) << "MySQL plugin is incompatible with database schema revision: " << revision;
159 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); 173 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
160 } 174 }
161 175
297 statement.SetReadOnly(true); 311 statement.SetReadOnly(true);
298 statement.Execute(); 312 statement.Execute();
299 313
300 return ReadInteger64(statement, 0); 314 return ReadInteger64(statement, 0);
301 } 315 }
316
317
318 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
319 void MySQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result,
320 const char* hashPatient,
321 const char* hashStudy,
322 const char* hashSeries,
323 const char* hashInstance)
324 {
325 {
326 DatabaseManager::CachedStatement statement(
327 STATEMENT_FROM_HERE, GetManager(),
328 "CALL CreateInstance(${patient}, ${study}, ${series}, ${instance}, "
329 "@isNewPatient, @isNewStudy, @isNewSeries, @isNewInstance, "
330 "@patientKey, @studyKey, @seriesKey, @instanceKey)");
331
332 statement.SetParameterType("patient", ValueType_Utf8String);
333 statement.SetParameterType("study", ValueType_Utf8String);
334 statement.SetParameterType("series", ValueType_Utf8String);
335 statement.SetParameterType("instance", ValueType_Utf8String);
336
337 Dictionary args;
338 args.SetUtf8Value("patient", hashPatient);
339 args.SetUtf8Value("study", hashStudy);
340 args.SetUtf8Value("series", hashSeries);
341 args.SetUtf8Value("instance", hashInstance);
342
343 statement.Execute(args);
344
345 if (!statement.IsDone())
346 {
347 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
348 }
349 }
350
351 {
352 DatabaseManager::CachedStatement statement(
353 STATEMENT_FROM_HERE, GetManager(),
354 "SELECT @isNewPatient, @isNewStudy, @isNewSeries, @isNewInstance, "
355 "@patientKey, @studyKey, @seriesKey, @instanceKey");
356
357 statement.Execute();
358
359 for (size_t i = 0; i < 8; i++)
360 {
361 statement.SetResultFieldType(i, ValueType_Integer64);
362 }
363
364 result.isNewInstance = (ReadInteger64(statement, 3) == 1);
365 result.instanceId = ReadInteger64(statement, 7);
366
367 if (result.isNewInstance)
368 {
369 result.isNewPatient = (ReadInteger64(statement, 0) == 1);
370 result.isNewStudy = (ReadInteger64(statement, 1) == 1);
371 result.isNewSeries = (ReadInteger64(statement, 2) == 1);
372 result.patientId = ReadInteger64(statement, 4);
373 result.studyId = ReadInteger64(statement, 5);
374 result.seriesId = ReadInteger64(statement, 6);
375 }
376 }
377 }
378 #endif
302 } 379 }