Mercurial > hg > orthanc-databases
comparison Framework/Common/DatabaseManager.cpp @ 263:29d2b76516f6
fix mysql and postgresql builds
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 20 Apr 2021 15:08:09 +0200 |
parents | d663d9e44f8d |
children | 86265ef5f3e3 |
comparison
equal
deleted
inserted
replaced
262:b0c65094b299 | 263:29d2b76516f6 |
---|---|
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "DatabaseManager.h" | 22 #include "DatabaseManager.h" |
23 | 23 |
24 #include "Integer64Value.h" | |
25 #include "BinaryStringValue.h" | |
26 #include "Utf8StringValue.h" | |
24 #include "../../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" | 27 #include "../../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
25 | 28 |
26 #include <Compatibility.h> // For std::unique_ptr<> | 29 #include <Compatibility.h> // For std::unique_ptr<> |
27 #include <Logging.h> | 30 #include <Logging.h> |
28 #include <OrthancException.h> | 31 #include <OrthancException.h> |
479 catch (Orthanc::OrthancException& e) | 482 catch (Orthanc::OrthancException& e) |
480 { | 483 { |
481 manager_.CloseIfUnavailable(e.GetErrorCode()); | 484 manager_.CloseIfUnavailable(e.GetErrorCode()); |
482 throw; | 485 throw; |
483 } | 486 } |
484 } | 487 } |
488 | |
489 | |
490 int64_t DatabaseManager::StatementBase::ReadInteger64(size_t field) const | |
491 { | |
492 if (IsDone()) | |
493 { | |
494 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
495 } | |
496 else | |
497 { | |
498 const IValue& value = GetResultField(field); | |
499 | |
500 switch (value.GetType()) | |
501 { | |
502 case ValueType_Integer64: | |
503 return dynamic_cast<const Integer64Value&>(value).GetValue(); | |
504 | |
505 default: | |
506 //LOG(ERROR) << value.Format(); | |
507 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
508 } | |
509 } | |
510 } | |
511 | |
512 | |
513 int32_t DatabaseManager::StatementBase::ReadInteger32(size_t field) const | |
514 { | |
515 if (IsDone()) | |
516 { | |
517 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
518 } | |
519 else | |
520 { | |
521 int64_t value = ReadInteger64(field); | |
522 | |
523 if (value != static_cast<int64_t>(static_cast<int32_t>(value))) | |
524 { | |
525 LOG(ERROR) << "Integer overflow"; | |
526 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
527 } | |
528 else | |
529 { | |
530 return static_cast<int32_t>(value); | |
531 } | |
532 } | |
533 } | |
534 | |
535 | |
536 std::string DatabaseManager::StatementBase::ReadString(size_t field) const | |
537 { | |
538 const IValue& value = GetResultField(field); | |
539 | |
540 switch (value.GetType()) | |
541 { | |
542 case ValueType_BinaryString: | |
543 return dynamic_cast<const BinaryStringValue&>(value).GetContent(); | |
544 | |
545 case ValueType_Utf8String: | |
546 return dynamic_cast<const Utf8StringValue&>(value).GetContent(); | |
547 | |
548 default: | |
549 //LOG(ERROR) << value.Format(); | |
550 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
551 } | |
552 } | |
485 | 553 |
486 | 554 |
487 DatabaseManager::CachedStatement::CachedStatement(const StatementLocation& location, | 555 DatabaseManager::CachedStatement::CachedStatement(const StatementLocation& location, |
488 DatabaseManager& manager, | 556 DatabaseManager& manager, |
489 const std::string& sql) : | 557 const std::string& sql) : |