Mercurial > hg > orthanc-databases
comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 431:7c1fe5d6c12c pg-transactions
PG: IncrementGlobalProperty
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 07 Dec 2023 12:13:43 +0100 |
parents | 4d0bacbd0fba |
children | 8b7c1c423367 |
comparison
equal
deleted
inserted
replaced
430:f1f3c5554283 | 431:7c1fe5d6c12c |
---|---|
396 // disabled because this is not alway true while transactions are being executed in READ COMITTED TRANSACTION. This is however true when no files are being delete/added | 396 // disabled because this is not alway true while transactions are being executed in READ COMITTED TRANSACTION. This is however true when no files are being delete/added |
397 // assert(result == IndexBackend::GetTotalUncompressedSize(manager)); | 397 // assert(result == IndexBackend::GetTotalUncompressedSize(manager)); |
398 return result; | 398 return result; |
399 } | 399 } |
400 | 400 |
401 int64_t PostgreSQLIndex::IncrementGlobalProperty(DatabaseManager& manager, | |
402 const char* serverIdentifier, | |
403 int32_t property, | |
404 int64_t increment) | |
405 { | |
406 if (serverIdentifier == NULL) | |
407 { | |
408 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
409 } | |
410 else | |
411 { | |
412 if (strlen(serverIdentifier) == 0) | |
413 { | |
414 DatabaseManager::CachedStatement statement( | |
415 STATEMENT_FROM_HERE, manager, | |
416 "INSERT INTO GlobalProperties (property, value) VALUES(${property}, ${increment}) " | |
417 " ON CONFLICT (property) DO UPDATE SET value = CAST(GlobalProperties.value AS BIGINT) + ${increment}" | |
418 " RETURNING CAST(value AS BIGINT)"); | |
419 | |
420 statement.SetParameterType("property", ValueType_Integer64); | |
421 statement.SetParameterType("increment", ValueType_Integer64); | |
422 | |
423 Dictionary args; | |
424 args.SetIntegerValue("property", property); | |
425 args.SetIntegerValue("increment", increment); | |
426 | |
427 statement.Execute(args); | |
428 | |
429 return statement.ReadInteger64(0); | |
430 } | |
431 else | |
432 { | |
433 DatabaseManager::CachedStatement statement( | |
434 STATEMENT_FROM_HERE, manager, | |
435 "INSERT INTO ServerProperties (server, property, value) VALUES(${server}, ${property}, ${increment}) " | |
436 " ON CONFLICT (server, property) DO UPDATE SET value = CAST(ServerProperties.value AS BIGINT) + ${increment}" | |
437 " RETURNING CAST(value AS BIGINT)"); | |
438 | |
439 statement.SetParameterType("server", ValueType_Utf8String); | |
440 statement.SetParameterType("property", ValueType_Integer64); | |
441 statement.SetParameterType("increment", ValueType_Integer64); | |
442 | |
443 Dictionary args; | |
444 args.SetUtf8Value("server", serverIdentifier); | |
445 args.SetIntegerValue("property", property); | |
446 args.SetIntegerValue("increment", increment); | |
447 | |
448 statement.Execute(args); | |
449 | |
450 return statement.ReadInteger64(0); | |
451 } | |
452 } | |
453 } | |
454 | |
401 | 455 |
402 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | 456 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
403 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, | 457 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, |
404 DatabaseManager& manager, | 458 DatabaseManager& manager, |
405 const char* hashPatient, | 459 const char* hashPatient, |