comparison OrthancServer/DatabaseWrapper.cpp @ 567:c2be0a0e049e find-move-scp

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 19 Sep 2013 17:43:38 +0200
parents 2c739f76d0bb
children ce5d2040c47b
comparison
equal deleted inserted replaced
565:c931ac02db82 567:c2be0a0e049e
805 std::string query; 805 std::string query;
806 EmbeddedResources::GetFileResource(query, EmbeddedResources::PREPARE_DATABASE); 806 EmbeddedResources::GetFileResource(query, EmbeddedResources::PREPARE_DATABASE);
807 db_.Execute(query); 807 db_.Execute(query);
808 } 808 }
809 809
810 // Sanity check of the version of the database 810 // Check the version of the database
811 std::string version = GetGlobalProperty(GlobalProperty_DatabaseSchemaVersion, "Unknown"); 811 std::string version = GetGlobalProperty(GlobalProperty_DatabaseSchemaVersion, "Unknown");
812 bool ok = false; 812 bool ok = false;
813 try 813 try
814 { 814 {
815 LOG(INFO) << "Version of the Orthanc database: " << version; 815 LOG(INFO) << "Version of the Orthanc database: " << version;
816 unsigned int v = boost::lexical_cast<unsigned int>(version); 816 unsigned int v = boost::lexical_cast<unsigned int>(version);
817 817
818 // This version of Orthanc is only compatible with version 3 of 818 // This version of Orthanc is only compatible with versions 3
819 // the DB schema (since Orthanc 0.3.2) 819 // (Orthanc 0.3.2 to 0.6.1) and 4 (since Orthanc 0.6.2) of the
820 ok = (v == 3); 820 // DB schema
821 ok = (v == 3 || v == 4);
822
823 if (v == 3)
824 {
825 LOG(WARNING) << "Upgrading the database from version 3 to version 4 (reconstructing the index)";
826
827 // Reconstruct the index for case insensitive queries in C-FIND
828 db_.Execute("DROP INDEX IF EXISTS MainDicomTagsIndexValues;");
829 db_.Execute("DROP TABLE IF EXISTS AvailableTags;");
830
831 std::string query;
832 EmbeddedResources::GetFileResource(query, EmbeddedResources::PREPARE_DATABASE_V4);
833 db_.Execute(query);
834
835 db_.Execute("INSERT INTO AvailableTags SELECT DISTINCT tagGroup, tagElement FROM MainDicomTags;");
836
837 //SetGlobalProperty(GlobalProperty_DatabaseSchemaVersion, "4");
838 }
821 } 839 }
822 catch (boost::bad_lexical_cast&) 840 catch (boost::bad_lexical_cast&)
823 { 841 {
824 } 842 }
825 843
826 if (!ok) 844 if (!ok)
827 { 845 {
828 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion); 846 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
829 } 847 }
848
849 CompleteMainDicomTags();
830 850
831 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor; 851 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor;
832 db_.Register(signalRemainingAncestor_); 852 db_.Register(signalRemainingAncestor_);
833 db_.Register(new Internals::SignalFileDeleted(listener_)); 853 db_.Register(new Internals::SignalFileDeleted(listener_));
834 } 854 }
993 while (s.Step()) 1013 while (s.Step())
994 { 1014 {
995 result.push_back(s.ColumnInt64(0)); 1015 result.push_back(s.ColumnInt64(0));
996 } 1016 }
997 } 1017 }
1018
1019
1020 void DatabaseWrapper::CompleteMainDicomTags()
1021 {
1022 std::set<DicomTag> requiredTags;
1023
1024 }
998 } 1025 }