Mercurial > hg > orthanc-databases
comparison SQLite/Plugins/SQLiteIndex.cpp @ 237:35598014f140
refactoring to remove GlobalProperties.cpp
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 08 Apr 2021 19:09:04 +0200 |
parents | a4918d57435c |
children | f033cc039264 |
comparison
equal
deleted
inserted
replaced
236:d1d2edbbe6fb | 237:35598014f140 |
---|---|
45 else | 45 else |
46 { | 46 { |
47 db->Open(path_); | 47 db->Open(path_); |
48 } | 48 } |
49 | 49 |
50 db->Execute("PRAGMA ENCODING=\"UTF-8\";"); | |
51 | |
52 if (fast_) | |
53 { | |
54 // Performance tuning of SQLite with PRAGMAs | |
55 // http://www.sqlite.org/pragma.html | |
56 db->Execute("PRAGMA SYNCHRONOUS=NORMAL;"); | |
57 db->Execute("PRAGMA JOURNAL_MODE=WAL;"); | |
58 db->Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); | |
59 db->Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;"); | |
60 //db->Execute("PRAGMA TEMP_STORE=memory"); | |
61 } | |
62 | |
50 return db.release(); | 63 return db.release(); |
51 } | 64 } |
52 | 65 |
53 | 66 |
54 void SQLiteIndex::ConfigureDatabase(IDatabase& database) | 67 void SQLiteIndex::ConfigureDatabase(DatabaseManager& manager) |
55 { | 68 { |
56 SQLiteDatabase& db = dynamic_cast<SQLiteDatabase&>(database); | |
57 | |
58 uint32_t expectedVersion = 6; | 69 uint32_t expectedVersion = 6; |
59 | 70 |
60 if (GetContext()) // "GetContext()" can possibly be NULL in the unit tests | 71 if (GetContext()) // "GetContext()" can possibly be NULL in the unit tests |
61 { | 72 { |
62 expectedVersion = OrthancPluginGetExpectedDatabaseVersion(GetContext()); | 73 expectedVersion = OrthancPluginGetExpectedDatabaseVersion(GetContext()); |
70 << ", but this plugin is only compatible with version 6"; | 81 << ", but this plugin is only compatible with version 6"; |
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); | 82 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); |
72 } | 83 } |
73 | 84 |
74 { | 85 { |
75 SQLiteTransaction t(db); | 86 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
76 | 87 |
77 if (!db.DoesTableExist("Resources")) | 88 if (!t.DoesTableExist("Resources")) |
78 { | 89 { |
79 std::string query; | 90 std::string query; |
80 | 91 |
81 Orthanc::EmbeddedResources::GetFileResource | 92 Orthanc::EmbeddedResources::GetFileResource |
82 (query, Orthanc::EmbeddedResources::SQLITE_PREPARE_INDEX); | 93 (query, Orthanc::EmbeddedResources::SQLITE_PREPARE_INDEX); |
83 db.Execute(query); | 94 |
84 | 95 t.ExecuteMultiLines(query); |
85 SetGlobalIntegerProperty(db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); | 96 |
86 SetGlobalIntegerProperty(db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, 1); | 97 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); |
87 } | 98 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, 1); |
99 } | |
88 | 100 |
89 t.Commit(); | 101 t.Commit(); |
90 } | 102 } |
91 | 103 |
92 db.Execute("PRAGMA ENCODING=\"UTF-8\";"); | 104 { |
93 | 105 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
94 if (fast_) | 106 |
95 { | 107 if (!t.DoesTableExist("Resources")) |
96 // Performance tuning of SQLite with PRAGMAs | |
97 // http://www.sqlite.org/pragma.html | |
98 db.Execute("PRAGMA SYNCHRONOUS=NORMAL;"); | |
99 db.Execute("PRAGMA JOURNAL_MODE=WAL;"); | |
100 db.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); | |
101 db.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;"); | |
102 //db.Execute("PRAGMA TEMP_STORE=memory"); | |
103 } | |
104 | |
105 { | |
106 SQLiteTransaction t(db); | |
107 | |
108 if (!db.DoesTableExist("Resources")) | |
109 { | 108 { |
110 LOG(ERROR) << "Corrupted SQLite database"; | 109 LOG(ERROR) << "Corrupted SQLite database"; |
111 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 110 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
112 } | 111 } |
113 | 112 |
114 int version = 0; | 113 int version = 0; |
115 if (!LookupGlobalIntegerProperty(version, db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion) || | 114 if (!LookupGlobalIntegerProperty(version, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion) || |
116 version != 6) | 115 version != 6) |
117 { | 116 { |
118 LOG(ERROR) << "SQLite plugin is incompatible with database schema version: " << version; | 117 LOG(ERROR) << "SQLite plugin is incompatible with database schema version: " << version; |
119 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | 118 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
120 } | 119 } |
121 | 120 |
122 int revision; | 121 int revision; |
123 if (!LookupGlobalIntegerProperty(revision, db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel)) | 122 if (!LookupGlobalIntegerProperty(revision, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel)) |
124 { | 123 { |
125 revision = 1; | 124 revision = 1; |
126 SetGlobalIntegerProperty(db, t, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); | 125 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
127 } | 126 } |
128 | 127 |
129 if (revision != 1) | 128 if (revision != 1) |
130 { | 129 { |
131 LOG(ERROR) << "SQLite plugin is incompatible with database schema revision: " << revision; | 130 LOG(ERROR) << "SQLite plugin is incompatible with database schema revision: " << revision; |