| 1967 | |
| 1968 | |
| 1969 | void ClientBase::processInsertQuery(String query, ASTPtr parsed_query) |
| 1970 | { |
| 1971 | if (!query_parameters.empty() |
| 1972 | && connection->getServerRevision(connection_parameters.timeouts) < DBMS_MIN_PROTOCOL_VERSION_WITH_PARAMETERS) |
| 1973 | { |
| 1974 | /// Replace ASTQueryParameter with ASTLiteral for prepared statements. |
| 1975 | ReplaceQueryParameterVisitor visitor(query_parameters); |
| 1976 | visitor.visit(parsed_query); |
| 1977 | |
| 1978 | /// Get new query after substitutions. |
| 1979 | if (visitor.getNumberOfReplacedParameters()) |
| 1980 | query = parsed_query->formatWithSecretsOneLine(); |
| 1981 | chassert(!query.empty()); |
| 1982 | } |
| 1983 | |
| 1984 | /// Process the query that requires transferring data blocks to the server. |
| 1985 | const auto & parsed_insert_query = parsed_query->as<ASTInsertQuery &>(); |
| 1986 | if ((!parsed_insert_query.data && !parsed_insert_query.infile) && (is_interactive || (!stdin_is_a_tty && !isStdinNotEmptyAndValid(*std_in)))) |
| 1987 | { |
| 1988 | const auto & settings = client_context->getSettingsRef(); |
| 1989 | if (settings[Setting::throw_if_no_data_to_insert]) |
| 1990 | throw Exception(ErrorCodes::NO_DATA_TO_INSERT, "No data to insert"); |
| 1991 | return; |
| 1992 | } |
| 1993 | |
| 1994 | if (isEmbeeddedClient() && parsed_insert_query.infile) |
| 1995 | throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "Reading from INFILE is disabled when you are running client embedded into server."); |
| 1996 | |
| 1997 | query_interrupt_handler.start(); |
| 1998 | SCOPE_EXIT({ query_interrupt_handler.stop(); }); |
| 1999 | |
| 2000 | connection->sendQuery( |
| 2001 | connection_parameters.timeouts, |
| 2002 | query, |
| 2003 | query_parameters, |
| 2004 | client_context->getCurrentQueryId(), |
| 2005 | query_processing_stage, |
| 2006 | &client_context->getSettingsRef(), |
| 2007 | &client_context->getClientInfo(), |
| 2008 | true, |
| 2009 | {}, |
| 2010 | [&](const Progress & progress) { onProgress(progress); }); |
| 2011 | |
| 2012 | try |
| 2013 | { |
| 2014 | if (send_external_tables) |
| 2015 | sendExternalTables(parsed_query); |
| 2016 | |
| 2017 | startKeystrokeInterceptorIfExists(); |
| 2018 | SCOPE_EXIT({ stopKeystrokeInterceptorIfExists(); }); |
| 2019 | |
| 2020 | /// Receive description of table structure. |
| 2021 | Block sample; |
| 2022 | ColumnsDescription columns_description; |
| 2023 | if (receiveSampleBlock(sample, columns_description, parsed_query)) |
| 2024 | { |
| 2025 | /// If structure was received (thus, server has not thrown an exception), |
| 2026 | /// send our data with that structure. |
nothing calls this directly
no test coverage detected