MCPcopy Create free account
hub / github.com/Restream/reindexer / DumpSQL

Method DumpSQL

cpp_src/core/query/sql/sqlencoder.cc:202–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200
201template <typename Formatter>
202void SQLEncoder<Formatter>::DumpSQL(bool stripArgs) const {
203 WrSerializer& ser = formatter_.Serializer();
204 switch (realQueryType_) {
205 case QuerySelect: {
206 if (query_.IsLocal()) {
207 ser << "LOCAL ";
208 }
209 ser << "SELECT";
210 {
211 const auto selectFiltersGuard = formatter_.StartBlock();
212 bool needComma = false;
213 if (query_.IsWithRank()) {
214 ser << "RANK()";
215 needComma = true;
216 }
217 for (const auto& a : query_.aggregations_) {
218 if (needComma) {
219 formatter_.Comma();
220 } else {
221 needComma = true;
222 }
223 ser << AggTypeToStr(a.Type());
224 {
225 const auto aggregationsParenthesisGuard = formatter_.OpenParenthesis();
226 for (const auto& f : a.Fields()) {
227 if (&f != &*a.Fields().begin()) {
228 formatter_.Comma();
229 }
230 ser << f;
231 }
232 for (const auto& se : a.Sorting()) {
233 formatter_.Next();
234 ser << "ORDER BY " << '\'' << escapeQuotes(se.expression) << '\'' << (se.desc ? " DESC" : " ASC");
235 }
236
237 if (a.Offset() != QueryEntry::kDefaultOffset && !stripArgs) {
238 formatter_.Next();
239 ser << "OFFSET " << a.Offset();
240 }
241 if (a.Limit() != QueryEntry::kDefaultLimit && !stripArgs) {
242 formatter_.Next();
243 ser << "LIMIT " << a.Limit();
244 }
245 }
246 }
247 if (query_.aggregations_.empty() || (query_.aggregations_.size() == 1 && query_.aggregations_[0].Type() == AggDistinct)) {
248 if (query_.SelectFilters().Empty()) {
249 if (query_.Limit() != 0 || !query_.HasCalcTotal()) {
250 if (needComma) {
251 formatter_.Comma();
252 }
253 ser << '*';
254 if (query_.HasCalcTotal()) {
255 needComma = true;
256 }
257 }
258 } else {
259 if (query_.SelectFilters().AllRegularFields()) {

Callers 5

query.ccFile · 0.80
GetSQLMethod · 0.80
DumpSingleJoinQueryMethod · 0.80
dumpMergedMethod · 0.80
dumpWhereEntriesMethod · 0.80

Calls 15

AggTypeToStrFunction · 0.85
escapeQuotesFunction · 0.85
SerializerMethod · 0.80
StartBlockMethod · 0.80
IsWithRankMethod · 0.80
CommaMethod · 0.80
OpenParenthesisMethod · 0.80
SelectFiltersMethod · 0.80
HasCalcTotalMethod · 0.80
AllRegularFieldsMethod · 0.80
AllVectorFieldsMethod · 0.80
CalcTotalMethod · 0.80

Tested by

no test coverage detected