| 200 | |
| 201 | template <typename Formatter> |
| 202 | void 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()) { |
no test coverage detected