MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / executeMultiQuery

Method executeMultiQuery

src/Client/ClientBase.cpp:2872–3198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2870
2871
2872bool ClientBase::executeMultiQuery(const String & all_queries_text)
2873{
2874 bool echo_query = echo_queries;
2875
2876 {
2877 /// disable logs if expects errors
2878 TestHint test_hint(all_queries_text);
2879 if (test_hint.hasClientErrors() || test_hint.hasServerErrors())
2880 {
2881 auto u = processTextAsSingleQuery("SET send_logs_level = 'fatal'");
2882 UNUSED(u);
2883 }
2884 }
2885
2886 /// Test tags are started with "--" so they are interpreted as comments anyway.
2887 /// But if the echo is enabled we have to remove the test tags from `all_queries_text`
2888 /// because we don't want test tags to be echoed.
2889 size_t test_tags_length = getTestTagsLength(all_queries_text);
2890
2891 /// Several queries separated by ';'.
2892 /// INSERT data is ended by the empty line (\n\n), not ';'.
2893 /// Unnecessary semicolons may cause data to be parsed containing ';'
2894 /// e.g. 'insert into xx format csv val;' will insert "val;" instead of "val"
2895 /// 'insert into xx format csv val\n;' will insert "val" and ";"
2896 /// An exception is VALUES format where we also support semicolon in
2897 /// addition to end of line.
2898 const char * this_query_begin = all_queries_text.data() + test_tags_length;
2899 const char * this_query_end = nullptr;
2900 const char * all_queries_end = all_queries_text.data() + all_queries_text.size();
2901
2902 const char * prev_query_begin = all_queries_text.data();
2903 UInt32 script_query_number = 0;
2904 UInt32 script_line_number = 0;
2905
2906 ASTPtr parsed_query;
2907 std::unique_ptr<Exception> current_exception;
2908 size_t retries_count = 0;
2909 bool is_first = true;
2910
2911 while (true)
2912 {
2913 auto stage = analyzeMultiQueryText(this_query_begin, this_query_end, all_queries_end,
2914 parsed_query, current_exception);
2915 switch (stage)
2916 {
2917 case MultiQueryProcessingStage::QUERIES_END:
2918 {
2919 /// Compatible with old version when run interactive, e.g. "", "\ld"
2920 if (is_first && is_interactive)
2921 {
2922 auto u = processTextAsSingleQuery(all_queries_text);
2923 UNUSED(u);
2924 }
2925 return true;
2926 }
2927 case MultiQueryProcessingStage::PARSING_FAILED:
2928 {
2929 have_error |= buzz_house;

Callers

nothing calls this directly

Calls 15

getTestTagsLengthFunction · 0.85
string_viewClass · 0.85
getCurrentExceptionCodeFunction · 0.85
sleep_forFunction · 0.85
connectFunction · 0.85
hasClientErrorsMethod · 0.80
hasServerErrorsMethod · 0.80
echoQueriesMethod · 0.80
needRetryMethod · 0.80

Tested by

no test coverage detected