| 364 | |
| 365 | |
| 366 | static String joinLines(const String & query) |
| 367 | { |
| 368 | /// Care should be taken. We don't join lines inside non-whitespace tokens (e.g. multiline string literals) |
| 369 | /// and we don't join line after comment (because it can be single-line comment). |
| 370 | /// All other whitespaces replaced to a single whitespace. |
| 371 | |
| 372 | String res; |
| 373 | const char * begin = query.data(); |
| 374 | const char * end = begin + query.size(); |
| 375 | |
| 376 | Lexer lexer(begin, end); |
| 377 | Token token = lexer.nextToken(); |
| 378 | for (; !token.isEnd(); token = lexer.nextToken()) |
| 379 | { |
| 380 | if (token.type == TokenType::Whitespace) |
| 381 | { |
| 382 | res += ' '; |
| 383 | } |
| 384 | else if (token.type == TokenType::Comment) |
| 385 | { |
| 386 | res.append(token.begin, token.end); |
| 387 | if (token.end < end && *token.end == '\n') |
| 388 | res += '\n'; |
| 389 | } |
| 390 | else |
| 391 | res.append(token.begin, token.end); |
| 392 | } |
| 393 | |
| 394 | return res; |
| 395 | } |
| 396 | |
| 397 | |
| 398 | static String prepareQueryForLogging(const String & query, ContextPtr context) |