Explorar o código

If given a new or newly modified file, update the Images database row

Fixes #357 and is verified by ctkDICOMDatabaseTest5.

When the user imports a file that is already in the database, delete
the old row for that image and let it be re-imported so that the
database will always point to the most current location of the file
(or at least the most recently imported).
Steve Pieper %!s(int64=11) %!d(string=hai) anos
pai
achega
77b27a2e23
Modificáronse 1 ficheiros con 14 adicións e 11 borrados
  1. 14 11
      Libs/DICOM/Core/ctkDICOMDatabase.cpp

+ 14 - 11
Libs/DICOM/Core/ctkDICOMDatabase.cpp

@@ -1123,18 +1123,12 @@ void ctkDICOMDatabasePrivate::insert( const ctkDICOMItem& ctkDataset, const QStr
       logger.error("SQLITE ERROR: " + fileExistsQuery.lastError().driverText());
       return;
     }
+  fileExistsQuery.next();
 
   QString databaseFilename(fileExistsQuery.value(1).toString());
   QDateTime fileLastModified(QFileInfo(databaseFilename).lastModified());
   QDateTime databaseInsertTimestamp(QDateTime::fromString(fileExistsQuery.value(0).toString(),Qt::ISODate));
 
-  qDebug() << "Looking for sopInstanceUID: " << sopInstanceUID;
-  qDebug() << " bound value : " << fileExistsQuery.boundValue(0);
-  qDebug() << " Ran Query : " << fileExistsQuery.lastQuery();
-  qDebug() << " Found databaseFilename : " << databaseFilename;
-  qDebug() << "  databaseInsertTimestamp : " << databaseInsertTimestamp;
-  qDebug() << "  fileLastModified : " << fileLastModified;
-
   qDebug() << "inserting filePath: " << filePath;
   if (databaseFilename == "")
     {
@@ -1142,14 +1136,23 @@ void ctkDICOMDatabasePrivate::insert( const ctkDICOMItem& ctkDataset, const QStr
     }
   else
     {
-      qDebug() << "database filename for " << sopInstanceUID << " is: " << databaseFilename;
-      qDebug() << "modified date is: " << fileLastModified;
-      qDebug() << "db insert date is: " << databaseInsertTimestamp;
-      if ( fileExistsQuery.next() && fileLastModified < databaseInsertTimestamp )
+      if ( databaseFilename == filePath && fileLastModified < databaseInsertTimestamp )
         {
           logger.debug ( "File " + databaseFilename + " already added" );
           return;
         }
+      else
+        {
+        QSqlQuery deleteFile ( Database );
+        deleteFile.prepare("DELETE FROM Images WHERE SOPInstanceUID == :sopInstanceUID");
+        deleteFile.bindValue(":sopInstanceUID",sopInstanceUID);
+        bool success = deleteFile.exec();
+        if (!success)
+          {
+            logger.error("SQLITE ERROR deleting old image row: " + deleteFile.lastError().driverText());
+            return;
+          }
+        }
     }
   }