comparison SQLite/Plugins/SQLiteIndex.cpp @ 85:1012fe77241c db-changes

new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Jan 2019 18:04:12 +0100
parents 714c5d2bee76
children 4cd7e45b671e
comparison
equal deleted inserted replaced
82:122f22550521 85:1012fe77241c
19 **/ 19 **/
20 20
21 21
22 #include "SQLiteIndex.h" 22 #include "SQLiteIndex.h"
23 23
24 #include "../../Framework/Common/Integer64Value.h"
24 #include "../../Framework/Plugins/GlobalProperties.h" 25 #include "../../Framework/Plugins/GlobalProperties.h"
25 #include "../../Framework/SQLite/SQLiteDatabase.h" 26 #include "../../Framework/SQLite/SQLiteDatabase.h"
26 #include "../../Framework/SQLite/SQLiteTransaction.h" 27 #include "../../Framework/SQLite/SQLiteTransaction.h"
27 28
28 #include <EmbeddedResources.h> // Auto-generated file 29 #include <EmbeddedResources.h> // Auto-generated file
171 172
172 statement.Execute(args); 173 statement.Execute(args);
173 174
174 return dynamic_cast<SQLiteDatabase&>(statement.GetDatabase()).GetLastInsertRowId(); 175 return dynamic_cast<SQLiteDatabase&>(statement.GetDatabase()).GetLastInsertRowId();
175 } 176 }
177
178
179 int64_t SQLiteIndex::GetLastChangeIndex()
180 {
181 DatabaseManager::CachedStatement statement(
182 STATEMENT_FROM_HERE, GetManager(),
183 "SELECT seq FROM sqlite_sequence WHERE name='Changes'");
184
185 statement.SetReadOnly(true);
186 statement.Execute();
187
188 if (statement.IsDone())
189 {
190 // No change has been recorded so far in the database
191 return 0;
192 }
193 else
194 {
195 const IValue& value = statement.GetResultField(0);
196
197 switch (value.GetType())
198 {
199 case ValueType_Integer64:
200 return dynamic_cast<const Integer64Value&>(value).GetValue();
201
202 default:
203 //LOG(ERROR) << value.Format();
204 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
205 }
206 }
207 }
176 } 208 }