Mercurial > hg > orthanc
comparison OrthancServer/DatabaseWrapper.cpp @ 1237:0f3716b88af7
cleaning
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Dec 2014 15:33:16 +0100 |
parents | 178de5edc0a8 |
children | 6c07108ff1e2 |
comparison
equal
deleted
inserted
replaced
1236:21d84e3acc0d | 1237:0f3716b88af7 |
---|---|
257 | 257 |
258 default: | 258 default: |
259 throw OrthancException(ErrorCode_InternalError); | 259 throw OrthancException(ErrorCode_InternalError); |
260 } | 260 } |
261 | 261 |
262 LogChange(id, changeType, type, publicId); | 262 ServerIndexChange change(changeType, type, publicId); |
263 LogChange(id, change); | |
263 return id; | 264 return id; |
264 } | 265 } |
265 | 266 |
266 bool DatabaseWrapper::LookupResource(const std::string& publicId, | 267 bool DatabaseWrapper::LookupResource(const std::string& publicId, |
267 int64_t& id, | 268 int64_t& id, |
443 return s; | 444 return s; |
444 } | 445 } |
445 else | 446 else |
446 { | 447 { |
447 return defaultValue; | 448 return defaultValue; |
448 } | |
449 } | |
450 | |
451 | |
452 bool DatabaseWrapper::GetMetadataAsInteger(int& result, | |
453 int64_t id, | |
454 MetadataType type) | |
455 { | |
456 std::string s = GetMetadata(id, type, ""); | |
457 if (s.size() == 0) | |
458 { | |
459 return false; | |
460 } | |
461 | |
462 try | |
463 { | |
464 result = boost::lexical_cast<int>(s); | |
465 return true; | |
466 } | |
467 catch (boost::bad_lexical_cast&) | |
468 { | |
469 return false; | |
470 } | 449 } |
471 } | 450 } |
472 | 451 |
473 | 452 |
474 | 453 |
1044 // Nothing to do: The patient is already unprotected | 1023 // Nothing to do: The patient is already unprotected |
1045 } | 1024 } |
1046 } | 1025 } |
1047 | 1026 |
1048 | 1027 |
1049 uint64_t DatabaseWrapper::IncrementGlobalSequence(GlobalProperty property) | |
1050 { | |
1051 std::string oldValue; | |
1052 | |
1053 if (LookupGlobalProperty(oldValue, property)) | |
1054 { | |
1055 uint64_t oldNumber; | |
1056 | |
1057 try | |
1058 { | |
1059 oldNumber = boost::lexical_cast<uint64_t>(oldValue); | |
1060 SetGlobalProperty(property, boost::lexical_cast<std::string>(oldNumber + 1)); | |
1061 return oldNumber + 1; | |
1062 } | |
1063 catch (boost::bad_lexical_cast&) | |
1064 { | |
1065 throw OrthancException(ErrorCode_InternalError); | |
1066 } | |
1067 } | |
1068 else | |
1069 { | |
1070 // Initialize the sequence at "1" | |
1071 SetGlobalProperty(property, "1"); | |
1072 return 1; | |
1073 } | |
1074 } | |
1075 | |
1076 | 1028 |
1077 void DatabaseWrapper::ClearTable(const std::string& tableName) | 1029 void DatabaseWrapper::ClearTable(const std::string& tableName) |
1078 { | 1030 { |
1079 db_.Execute("DELETE FROM " + tableName); | 1031 db_.Execute("DELETE FROM " + tableName); |
1080 } | 1032 } |