comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 435:326f8304daa1 pg-transactions

new creating temporary tables inside functions
author Alain Mazy <am@osimis.io>
date Thu, 14 Dec 2023 09:25:45 +0100
parents 23c7af6f671a
children f16faa1fdc46
comparison
equal deleted inserted replaced
434:23c7af6f671a 435:326f8304daa1
468 void PostgreSQLIndex::ClearDeletedFiles(DatabaseManager& manager) 468 void PostgreSQLIndex::ClearDeletedFiles(DatabaseManager& manager)
469 { 469 {
470 { // note: the temporary table lifespan is the session, not the transaction -> that's why we need the IF NOT EXISTS 470 { // note: the temporary table lifespan is the session, not the transaction -> that's why we need the IF NOT EXISTS
471 DatabaseManager::CachedStatement statement( 471 DatabaseManager::CachedStatement statement(
472 STATEMENT_FROM_HERE, manager, 472 STATEMENT_FROM_HERE, manager,
473 "CREATE TEMPORARY TABLE IF NOT EXISTS DeletedFiles(" 473 "SELECT CreateDeletedFilesTemporaryTable()"
474 "uuid VARCHAR(64) NOT NULL,"
475 "fileType INTEGER, "
476 "compressedSize BIGINT, "
477 "uncompressedSize BIGINT, "
478 "compressionType INTEGER, "
479 "uncompressedHash VARCHAR(40),"
480 "compressedHash VARCHAR(40)"
481 ");"
482 ); 474 );
483 statement.Execute(); 475 statement.ExecuteWithoutResult();
484 } 476 }
485 { 477
486 DatabaseManager::CachedStatement statement(
487 STATEMENT_FROM_HERE, manager,
488 "DELETE FROM DeletedFiles;"
489 );
490
491 statement.Execute();
492 }
493 } 478 }
494 479
495 void PostgreSQLIndex::ClearDeletedResources(DatabaseManager& manager) 480 void PostgreSQLIndex::ClearDeletedResources(DatabaseManager& manager)
496 { 481 {
497 { // note: the temporary table lifespan is the session, not the transaction -> that's why we need the IF NOT EXISTS 482 { // note: the temporary table lifespan is the session, not the transaction -> that's why we need the IF NOT EXISTS
515 500
516 } 501 }
517 502
518 void PostgreSQLIndex::ClearRemainingAncestor(DatabaseManager& manager) 503 void PostgreSQLIndex::ClearRemainingAncestor(DatabaseManager& manager)
519 { 504 {
520 { // note: the temporary table lifespan is the session, not the transaction -> that's why we need the IF NOT EXISTS
521 DatabaseManager::CachedStatement statement(
522 STATEMENT_FROM_HERE, manager,
523 "CREATE TEMPORARY TABLE IF NOT EXISTS RemainingAncestor("
524 "resourceType INTEGER NOT NULL,"
525 "publicId VARCHAR(64) NOT NULL"
526 ")"
527 );
528
529 statement.Execute();
530 }
531 {
532 DatabaseManager::CachedStatement statement(
533 STATEMENT_FROM_HERE, manager,
534 "DELETE FROM RemainingAncestor;"
535 );
536
537 statement.Execute();
538 }
539
540 } 505 }
541 506
542 void PostgreSQLIndex::DeleteResource(IDatabaseBackendOutput& output, 507 void PostgreSQLIndex::DeleteResource(IDatabaseBackendOutput& output,
543 DatabaseManager& manager, 508 DatabaseManager& manager,
544 int64_t id) 509 int64_t id)
545 { 510 {
546 ClearDeletedFiles(manager); 511 // clearing of temporary table is now implemented in the funcion DeleteResource
547 ClearDeletedResources(manager);
548
549 DatabaseManager::CachedStatement statement( 512 DatabaseManager::CachedStatement statement(
550 STATEMENT_FROM_HERE, manager, 513 STATEMENT_FROM_HERE, manager,
551 "SELECT * FROM DeleteResource(${id})"); 514 "SELECT * FROM DeleteResource(${id})");
552 515
553 statement.SetParameterType("id", ValueType_Integer64); 516 statement.SetParameterType("id", ValueType_Integer64);
573 static_cast<OrthancPluginResourceType>(statement.ReadInteger32(0))); 536 static_cast<OrthancPluginResourceType>(statement.ReadInteger32(0)));
574 } 537 }
575 538
576 SignalDeletedFiles(output, manager); 539 SignalDeletedFiles(output, manager);
577 SignalDeletedResources(output, manager); 540 SignalDeletedResources(output, manager);
578
579 } 541 }
580 542
581 543
582 544
583 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 545 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1