| 583 | } |
| 584 | |
| 585 | void PostgreSQLHandler::processQuery() |
| 586 | { |
| 587 | try |
| 588 | { |
| 589 | std::unique_ptr<PostgreSQLProtocol::Messaging::Query> query = |
| 590 | message_transport->receive<PostgreSQLProtocol::Messaging::Query>(); |
| 591 | |
| 592 | if (isEmptyQuery(query->query)) |
| 593 | { |
| 594 | message_transport->send(PostgreSQLProtocol::Messaging::EmptyQueryResponse()); |
| 595 | return; |
| 596 | } |
| 597 | |
| 598 | bool psycopg2_cond = query->query == "BEGIN" || query->query == "COMMIT"; // psycopg2 starts and ends queries with BEGIN/COMMIT commands |
| 599 | bool jdbc_cond = query->query.contains("SET extra_float_digits") || query->query.contains("SET application_name"); // jdbc starts with setting this parameter |
| 600 | if (psycopg2_cond || jdbc_cond) |
| 601 | { |
| 602 | message_transport->send( |
| 603 | PostgreSQLProtocol::Messaging::CommandComplete( |
| 604 | PostgreSQLProtocol::Messaging::CommandComplete::classifyQuery(query->query), 0)); |
| 605 | return; |
| 606 | } |
| 607 | |
| 608 | const auto & settings = session->sessionContext()->getSettingsRef(); |
| 609 | std::vector<String> queries; |
| 610 | |
| 611 | if (processPrepareStatement(query->query)) |
| 612 | return; |
| 613 | |
| 614 | if (processDeallocate(query->query)) |
| 615 | return; |
| 616 | |
| 617 | if (processCopyQuery(query->query)) |
| 618 | return; |
| 619 | |
| 620 | pcg64_fast gen{randomSeed()}; |
| 621 | std::uniform_int_distribution<Int32> dis(0, INT32_MAX); |
| 622 | |
| 623 | secret_key = dis(gen); |
| 624 | auto query_context = session->makeQueryContext(); |
| 625 | query_context->setCurrentQueryId(fmt::format("postgres:{:d}:{:d}", connection_id, secret_key)); |
| 626 | |
| 627 | if (should_init_system_tables) |
| 628 | { |
| 629 | initializeSystemTables(query_context); |
| 630 | should_init_system_tables = false; |
| 631 | } |
| 632 | |
| 633 | if (processExecute(query->query, query_context)) |
| 634 | return; |
| 635 | |
| 636 | auto parse_res = splitMultipartQuery( |
| 637 | query->query, |
| 638 | queries, |
| 639 | settings[Setting::max_query_size], |
| 640 | settings[Setting::max_parser_depth], |
| 641 | settings[Setting::max_parser_backtracks], |
| 642 | settings[Setting::allow_settings_after_format_in_insert], |
nothing calls this directly
no test coverage detected