comparison OrthancServer/DatabaseWrapper.cpp @ 693:01d8611c4a60

md5 for attached files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Feb 2014 17:52:51 +0100
parents 2d0a347e8cfc
children 72dc919a028c
comparison
equal deleted inserted replaced
692:1a3f9d90a2dd 693:01d8611c4a60
60 return "SignalFileDeleted"; 60 return "SignalFileDeleted";
61 } 61 }
62 62
63 virtual unsigned int GetCardinality() const 63 virtual unsigned int GetCardinality() const
64 { 64 {
65 return 5; 65 return 7;
66 } 66 }
67 67
68 virtual void Compute(SQLite::FunctionContext& context) 68 virtual void Compute(SQLite::FunctionContext& context)
69 { 69 {
70 FileInfo info(context.GetStringValue(0), 70 FileInfo info(context.GetStringValue(0),
71 static_cast<FileContentType>(context.GetIntValue(1)), 71 static_cast<FileContentType>(context.GetIntValue(1)),
72 static_cast<uint64_t>(context.GetInt64Value(2)), 72 static_cast<uint64_t>(context.GetInt64Value(2)),
73 context.GetStringValue(5),
73 static_cast<CompressionType>(context.GetIntValue(3)), 74 static_cast<CompressionType>(context.GetIntValue(3)),
74 static_cast<uint64_t>(context.GetInt64Value(4))); 75 static_cast<uint64_t>(context.GetInt64Value(4)),
76 context.GetStringValue(6));
75 77
76 listener_.SignalFileDeleted(info); 78 listener_.SignalFileDeleted(info);
77 } 79 }
78 }; 80 };
79 81
431 433
432 434
433 void DatabaseWrapper::AddAttachment(int64_t id, 435 void DatabaseWrapper::AddAttachment(int64_t id,
434 const FileInfo& attachment) 436 const FileInfo& attachment)
435 { 437 {
436 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?)"); 438 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
437 s.BindInt64(0, id); 439 s.BindInt64(0, id);
438 s.BindInt(1, attachment.GetContentType()); 440 s.BindInt(1, attachment.GetContentType());
439 s.BindString(2, attachment.GetUuid()); 441 s.BindString(2, attachment.GetUuid());
440 s.BindInt64(3, attachment.GetCompressedSize()); 442 s.BindInt64(3, attachment.GetCompressedSize());
441 s.BindInt64(4, attachment.GetUncompressedSize()); 443 s.BindInt64(4, attachment.GetUncompressedSize());
442 s.BindInt(5, attachment.GetCompressionType()); 444 s.BindInt(5, attachment.GetCompressionType());
445 s.BindString(6, attachment.GetUncompressedMD5());
446 s.BindString(7, attachment.GetCompressedMD5());
443 s.Run(); 447 s.Run();
444 } 448 }
445 449
446 void DatabaseWrapper::ListAvailableAttachments(std::list<FileContentType>& result, 450 void DatabaseWrapper::ListAvailableAttachments(std::list<FileContentType>& result,
447 int64_t id) 451 int64_t id)
461 bool DatabaseWrapper::LookupAttachment(FileInfo& attachment, 465 bool DatabaseWrapper::LookupAttachment(FileInfo& attachment,
462 int64_t id, 466 int64_t id,
463 FileContentType contentType) 467 FileContentType contentType)
464 { 468 {
465 SQLite::Statement s(db_, SQLITE_FROM_HERE, 469 SQLite::Statement s(db_, SQLITE_FROM_HERE,
466 "SELECT uuid, uncompressedSize, compressionType, compressedSize FROM AttachedFiles WHERE id=? AND fileType=?"); 470 "SELECT uuid, uncompressedSize, compressionType, compressedSize, uncompressedMD5, compressedMD5 FROM AttachedFiles WHERE id=? AND fileType=?");
467 s.BindInt64(0, id); 471 s.BindInt64(0, id);
468 s.BindInt(1, contentType); 472 s.BindInt(1, contentType);
469 473
470 if (!s.Step()) 474 if (!s.Step())
471 { 475 {
474 else 478 else
475 { 479 {
476 attachment = FileInfo(s.ColumnString(0), 480 attachment = FileInfo(s.ColumnString(0),
477 contentType, 481 contentType,
478 s.ColumnInt(1), 482 s.ColumnInt(1),
483 s.ColumnString(4),
479 static_cast<CompressionType>(s.ColumnInt(2)), 484 static_cast<CompressionType>(s.ColumnInt(2)),
480 s.ColumnInt(3)); 485 s.ColumnInt(3),
486 s.ColumnString(5));
481 return true; 487 return true;
482 } 488 }
483 } 489 }
484 490
485 void DatabaseWrapper::SetMainDicomTags(int64_t id, 491 void DatabaseWrapper::SetMainDicomTags(int64_t id,
818 try 824 try
819 { 825 {
820 LOG(INFO) << "Version of the Orthanc database: " << version; 826 LOG(INFO) << "Version of the Orthanc database: " << version;
821 unsigned int v = boost::lexical_cast<unsigned int>(version); 827 unsigned int v = boost::lexical_cast<unsigned int>(version);
822 828
823 // This version of Orthanc is only compatible with version 3 of 829 // Version 3: from Orthanc 0.3.2 to Orthanc 0.7.2 (inclusive)
824 // the DB schema (since Orthanc 0.3.2) 830 // Version 4: from Orthanc 0.7.3 (inclusive)
825 ok = (v == 3); 831
832 // This version of Orthanc is only compatible with version 4 of the DB schema
833 ok = (v == 4);
826 } 834 }
827 catch (boost::bad_lexical_cast&) 835 catch (boost::bad_lexical_cast&)
828 { 836 {
829 } 837 }
830 838
831 if (!ok) 839 if (!ok)
832 { 840 {
841 LOG(ERROR) << "Incompatible version of the Orthanc database: " << version;
833 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion); 842 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
834 } 843 }
835 844
836 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor; 845 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor;
837 db_.Register(signalRemainingAncestor_); 846 db_.Register(signalRemainingAncestor_);