Mercurial > hg > orthanc-databases
comparison Framework/Common/DatabaseManager.cpp @ 501:594859656a06 large-queries
Added support for ExtendedApiV1: /changes
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Thu, 11 Apr 2024 18:52:42 +0200 |
parents | f0976163dbe1 |
children | 2ab3d45c0b3c |
comparison
equal
deleted
inserted
replaced
500:c27071770c04 | 501:594859656a06 |
---|---|
76 Close(); | 76 Close(); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 | 80 |
81 IPrecompiledStatement* DatabaseManager::LookupCachedStatement(const StatementLocation& location) const | 81 IPrecompiledStatement* DatabaseManager::LookupCachedStatement(const StatementId& statementId) const |
82 { | 82 { |
83 CachedStatements::const_iterator found = cachedStatements_.find(location); | 83 CachedStatements::const_iterator found = cachedStatements_.find(statementId); |
84 | 84 |
85 if (found == cachedStatements_.end()) | 85 if (found == cachedStatements_.end()) |
86 { | 86 { |
87 return NULL; | 87 return NULL; |
88 } | 88 } |
92 return found->second; | 92 return found->second; |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 IPrecompiledStatement& DatabaseManager::CacheStatement(const StatementLocation& location, | 97 IPrecompiledStatement& DatabaseManager::CacheStatement(const StatementId& statementId, |
98 const Query& query) | 98 const Query& query) |
99 { | 99 { |
100 LOG(TRACE) << "Caching statement from " << location.GetFile() << ":" << location.GetLine(); | 100 LOG(TRACE) << "Caching statement from " << statementId.GetFile() << ":" << statementId.GetLine() << "" << statementId.GetDynamicStatement(); |
101 | 101 |
102 std::unique_ptr<IPrecompiledStatement> statement(GetDatabase().Compile(query)); | 102 std::unique_ptr<IPrecompiledStatement> statement(GetDatabase().Compile(query)); |
103 | 103 |
104 IPrecompiledStatement* tmp = statement.get(); | 104 IPrecompiledStatement* tmp = statement.get(); |
105 if (tmp == NULL) | 105 if (tmp == NULL) |
106 { | 106 { |
107 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 107 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
108 } | 108 } |
109 | 109 |
110 assert(cachedStatements_.find(location) == cachedStatements_.end()); | 110 assert(cachedStatements_.find(statementId) == cachedStatements_.end()); |
111 cachedStatements_[location] = statement.release(); | 111 cachedStatements_[statementId] = statement.release(); |
112 | 112 |
113 return *tmp; | 113 return *tmp; |
114 } | 114 } |
115 | 115 |
116 | 116 |
548 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "The returned field is not of the correct type (String)"); | 548 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "The returned field is not of the correct type (String)"); |
549 } | 549 } |
550 } | 550 } |
551 | 551 |
552 | 552 |
553 DatabaseManager::CachedStatement::CachedStatement(const StatementLocation& location, | 553 DatabaseManager::CachedStatement::CachedStatement(const StatementId& statementId, |
554 DatabaseManager& manager, | 554 DatabaseManager& manager, |
555 const std::string& sql) : | 555 const std::string& sql) : |
556 StatementBase(manager), | 556 StatementBase(manager), |
557 location_(location) | 557 statementId_(statementId) |
558 { | 558 { |
559 statement_ = GetManager().LookupCachedStatement(location_); | 559 statement_ = GetManager().LookupCachedStatement(statementId_); |
560 | 560 |
561 if (statement_ == NULL) | 561 if (statement_ == NULL) |
562 { | 562 { |
563 SetQuery(new Query(sql)); | 563 SetQuery(new Query(sql)); |
564 } | 564 } |
565 else | 565 else |
566 { | 566 { |
567 LOG(TRACE) << "Reusing cached statement from " | 567 LOG(TRACE) << "Reusing cached statement from " |
568 << location_.GetFile() << ":" << location_.GetLine(); | 568 << statementId_.GetFile() << ":" << statementId_.GetLine() << " " << statementId_.GetDynamicStatement(); |
569 } | 569 } |
570 } | 570 } |
571 | 571 |
572 void DatabaseManager::CachedStatement::ExecuteInternal(const Dictionary& parameters, bool withResults) | 572 void DatabaseManager::CachedStatement::ExecuteInternal(const Dictionary& parameters, bool withResults) |
573 { | 573 { |
577 | 577 |
578 if (query.get() != NULL) | 578 if (query.get() != NULL) |
579 { | 579 { |
580 // Register the newly-created statement | 580 // Register the newly-created statement |
581 assert(statement_ == NULL); | 581 assert(statement_ == NULL); |
582 statement_ = &GetManager().CacheStatement(location_, *query); | 582 statement_ = &GetManager().CacheStatement(statementId_, *query); |
583 } | 583 } |
584 | 584 |
585 assert(statement_ != NULL); | 585 assert(statement_ != NULL); |
586 | 586 |
587 /* | 587 /* |