comparison Framework/Plugins/IndexBackend.cpp @ 536:4ecf50a4521c find-refactoring

sync ISqlLookupFormatter from Orthanc + fix bug 224: LIMIT shall not be used with MSSQL
author Alain Mazy <am@orthanc.team>
date Fri, 06 Sep 2024 16:56:37 +0200
parents 25cfcb752af6
children 12f1c5265081
comparison
equal deleted inserted replaced
535:03a4a1bc852a 536:4ecf50a4521c
2176 default: 2176 default:
2177 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 2177 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
2178 } 2178 }
2179 } 2179 }
2180 2180
2181 virtual std::string FormatLimits(uint64_t since, uint64_t count)
2182 {
2183 std::string sql;
2184
2185 switch (dialect_)
2186 {
2187 case Dialect_MSSQL:
2188 {
2189 if (since > 0)
2190 {
2191 sql += " OFFSET " + boost::lexical_cast<std::string>(since) + " ROWS ";
2192 }
2193 if (count > 0)
2194 {
2195 sql += " FETCH NEXT " + boost::lexical_cast<std::string>(count) + " ROWS ONLY ";
2196 }
2197 }; break;
2198 case Dialect_SQLite:
2199 case Dialect_PostgreSQL:
2200 case Dialect_MySQL:
2201 {
2202 if (count > 0)
2203 {
2204 sql += " LIMIT " + boost::lexical_cast<std::string>(count);
2205 }
2206 if (since > 0)
2207 {
2208 sql += " OFFSET " + boost::lexical_cast<std::string>(since);
2209 }
2210 }; break;
2211 default:
2212 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
2213 }
2214
2215 return sql;
2216 }
2217
2181 virtual bool IsEscapeBrackets() const 2218 virtual bool IsEscapeBrackets() const
2182 { 2219 {
2183 // This was initially done at a bad location by the following changeset: 2220 // This was initially done at a bad location by the following changeset:
2184 // https://orthanc.uclouvain.be/hg/orthanc-databases/rev/389c037387ea 2221 // https://orthanc.uclouvain.be/hg/orthanc-databases/rev/389c037387ea
2185 return (dialect_ == Dialect_MSSQL); 2222 return (dialect_ == Dialect_MSSQL);
2205 2242
2206 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 2243 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
2207 // New primitive since Orthanc 1.5.2 2244 // New primitive since Orthanc 1.5.2
2208 void IndexBackend::LookupResources(IDatabaseBackendOutput& output, 2245 void IndexBackend::LookupResources(IDatabaseBackendOutput& output,
2209 DatabaseManager& manager, 2246 DatabaseManager& manager,
2210 const std::vector<Orthanc::DatabaseConstraint>& lookup, 2247 Orthanc::DatabaseConstraints& lookup,
2211 OrthancPluginResourceType queryLevel_, 2248 OrthancPluginResourceType queryLevel_,
2212 const std::set<std::string>& labels, 2249 const std::set<std::string>& labels,
2213 Orthanc::LabelsConstraint labelsConstraint, 2250 Orthanc::LabelsConstraint labelsConstraint,
2214 uint32_t limit, 2251 uint32_t limit,
2215 bool requestSomeInstance) 2252 bool requestSomeInstance)