comparison OrthancServer/DatabaseWrapper.cpp @ 1210:178de5edc0a8 db-changes

comments
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Nov 2014 13:56:17 +0100
parents 1169528a9a5f
children 0f3716b88af7
comparison
equal deleted inserted replaced
1209:25260fe03dd6 1210:178de5edc0a8
865 { 865 {
866 target.append(s.ColumnString(0)); 866 target.append(s.ColumnString(0));
867 } 867 }
868 } 868 }
869 869
870 static void UpgradeDatabase(SQLite::Connection& db,
871 EmbeddedResources::FileResourceId script)
872 {
873 std::string upgrade;
874 EmbeddedResources::GetFileResource(upgrade, script);
875 db.BeginTransaction();
876 db.Execute(upgrade);
877 db.CommitTransaction();
878 }
879
870 880
871 DatabaseWrapper::DatabaseWrapper(const std::string& path, 881 DatabaseWrapper::DatabaseWrapper(const std::string& path,
872 IServerIndexListener& listener) : 882 IServerIndexListener& listener) :
873 listener_(listener) 883 listener_(listener)
874 { 884 {
909 LOG(INFO) << "Version of the Orthanc database: " << version; 919 LOG(INFO) << "Version of the Orthanc database: " << version;
910 unsigned int v = boost::lexical_cast<unsigned int>(version); 920 unsigned int v = boost::lexical_cast<unsigned int>(version);
911 921
912 /** 922 /**
913 * History of the database versions: 923 * History of the database versions:
924 * - Orthanc before Orthanc 0.3.0 (inclusive) had no version
925 * - Version 2: only Orthanc 0.3.1
914 * - Version 3: from Orthanc 0.3.2 to Orthanc 0.7.2 (inclusive) 926 * - Version 3: from Orthanc 0.3.2 to Orthanc 0.7.2 (inclusive)
915 * - Version 4: from Orthanc 0.7.3 to Orthanc 0.8.3 (inclusive) 927 * - Version 4: from Orthanc 0.7.3 to Orthanc 0.8.4 (inclusive)
916 * - Version 5: from Orthanc 0.8.4 (inclusive) 928 * - Version 5: from Orthanc 0.8.5 (inclusive)
917 **/ 929 **/
918 930
919 // This version of Orthanc is only compatible with versions 3, 4 and 5 of the DB schema 931 // This version of Orthanc is only compatible with versions 3, 4 and 5 of the DB schema
920 ok = (v == 3 || v == 4 || v == 5); 932 ok = (v == 3 || v == 4 || v == 5);
921 933
922 if (v == 3) 934 if (v == 3)
923 { 935 {
924 LOG(WARNING) << "Upgrading database version from 3 to 4"; 936 LOG(WARNING) << "Upgrading database version from 3 to 4";
925 std::string upgrade; 937 UpgradeDatabase(db_, EmbeddedResources::UPGRADE_DATABASE_3_TO_4);
926 EmbeddedResources::GetFileResource(upgrade, EmbeddedResources::UPGRADE_DATABASE_3_TO_4);
927 db_.BeginTransaction();
928 db_.Execute(upgrade);
929 db_.CommitTransaction();
930 v = 4; 938 v = 4;
931 } 939 }
932 940
933 if (v == 4) 941 if (v == 4)
934 { 942 {
935 LOG(WARNING) << "Upgrading database version from 4 to 5"; 943 LOG(WARNING) << "Upgrading database version from 4 to 5";
936 std::string upgrade; 944 UpgradeDatabase(db_, EmbeddedResources::UPGRADE_DATABASE_4_TO_5);
937 EmbeddedResources::GetFileResource(upgrade, EmbeddedResources::UPGRADE_DATABASE_4_TO_5);
938 db_.BeginTransaction();
939 db_.Execute(upgrade);
940 db_.CommitTransaction();
941 v = 5; 945 v = 5;
942 } 946 }
943 } 947 }
944 catch (boost::bad_lexical_cast&) 948 catch (boost::bad_lexical_cast&)
945 { 949 {
950 ok = false;
946 } 951 }
947 952
948 if (!ok) 953 if (!ok)
949 { 954 {
950 LOG(ERROR) << "Incompatible version of the Orthanc database: " << version; 955 LOG(ERROR) << "Incompatible version of the Orthanc database: " << version;