comparison MySQL/Plugins/MySQLIndex.cpp @ 424:95c413106a66 improve-delete

Introduced a procedure to delete resources (to be tested)
author Alain Mazy <am@osimis.io>
date Wed, 13 Sep 2023 13:32:54 +0200
parents 91124cc8a8c7
children f4244c7e2725
comparison
equal deleted inserted replaced
423:7d2ba3ece4ee 424:95c413106a66
315 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); 315 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
316 316
317 t.Commit(); 317 t.Commit();
318 } 318 }
319 319
320 if (revision != 7) 320 if (revision == 7)
321 {
322 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite);
323
324 // Install the "CreateInstance" extension
325 std::string query;
326
327 Orthanc::EmbeddedResources::GetFileResource
328 (query, Orthanc::EmbeddedResources::MYSQL_DELETE_RESOURCES);
329
330 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here
331 db.ExecuteMultiLines(query, true);
332
333 revision = 8;
334 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision);
335
336 t.Commit();
337 }
338
339
340 if (revision != 8)
321 { 341 {
322 LOG(ERROR) << "MySQL plugin is incompatible with database schema revision: " << revision; 342 LOG(ERROR) << "MySQL plugin is incompatible with database schema revision: " << revision;
323 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); 343 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
324 } 344 }
325 } 345 }
451 parent.ReadString(0), 471 parent.ReadString(0),
452 static_cast<OrthancPluginResourceType>(parent.ReadInteger32(1))); 472 static_cast<OrthancPluginResourceType>(parent.ReadInteger32(1)));
453 } 473 }
454 } 474 }
455 475
456 { 476 // {
457 DatabaseManager::CachedStatement dropTemporaryTable( 477 // DatabaseManager::CachedStatement dropTemporaryTable(
478 // STATEMENT_FROM_HERE, manager,
479 // "DROP TEMPORARY TABLE IF EXISTS DeletedResources");
480 // dropTemporaryTable.Execute();
481 // }
482
483 // {
484 // DatabaseManager::CachedStatement lookupResourcesToDelete(
485 // STATEMENT_FROM_HERE, manager,
486 // "CREATE TEMPORARY TABLE DeletedResources SELECT * FROM (SELECT internalId, resourceType, publicId FROM Resources WHERE internalId=${id} OR parentId=${id} OR parentId IN (SELECT internalId FROM Resources WHERE parentId=${id}) OR parentId IN (SELECT internalId FROM Resources WHERE parentId IN (SELECT internalId FROM Resources WHERE parentId=${id}))) AS t");
487 // lookupResourcesToDelete.SetParameterType("id", ValueType_Integer64);
488
489 // Dictionary args;
490 // args.SetIntegerValue("id", id);
491 // lookupResourcesToDelete.Execute(args);
492 // }
493
494 // {
495 // DatabaseManager::CachedStatement deleteHierarchy(
496 // STATEMENT_FROM_HERE, manager,
497 // "DELETE FROM Resources WHERE internalId IN (SELECT internalId FROM DeletedResources)");
498 // deleteHierarchy.Execute();
499 // }
500
501
502 {
503 DatabaseManager::CachedStatement deleteResources(
458 STATEMENT_FROM_HERE, manager, 504 STATEMENT_FROM_HERE, manager,
459 "DROP TEMPORARY TABLE IF EXISTS DeletedResources"); 505 "CALL DeleteResources(${id})");
460 dropTemporaryTable.Execute(); 506
461 } 507 deleteResources.SetParameterType("id", ValueType_Integer64);
462
463 {
464 DatabaseManager::CachedStatement lookupResourcesToDelete(
465 STATEMENT_FROM_HERE, manager,
466 "CREATE TEMPORARY TABLE DeletedResources SELECT * FROM (SELECT internalId, resourceType, publicId FROM Resources WHERE internalId=${id} OR parentId=${id} OR parentId IN (SELECT internalId FROM Resources WHERE parentId=${id}) OR parentId IN (SELECT internalId FROM Resources WHERE parentId IN (SELECT internalId FROM Resources WHERE parentId=${id}))) AS t");
467 lookupResourcesToDelete.SetParameterType("id", ValueType_Integer64);
468 508
469 Dictionary args; 509 Dictionary args;
470 args.SetIntegerValue("id", id); 510 args.SetIntegerValue("id", id);
471 lookupResourcesToDelete.Execute(args); 511
472 } 512 deleteResources.Execute(args);
473
474 {
475 DatabaseManager::CachedStatement deleteHierarchy(
476 STATEMENT_FROM_HERE, manager,
477 "DELETE FROM Resources WHERE internalId IN (SELECT internalId FROM DeletedResources)");
478 deleteHierarchy.Execute();
479 } 513 }
480 514
481 SignalDeletedResources(output, manager); 515 SignalDeletedResources(output, manager);
482 SignalDeletedFiles(output, manager); 516 SignalDeletedFiles(output, manager);
483 } 517 }