From a2a2e32c02643a0cec111511220227703fda1cd5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 1 Jul 2024 20:15:00 +0200 Subject: Merging upstream version 1:11.4.2. Signed-off-by: Daniel Baumann --- sql/sql_load.cc | 82 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 20 deletions(-) (limited to 'sql/sql_load.cc') diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 7a82e0ce..84b253ba 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -862,8 +862,6 @@ err: #ifndef EMBEDDED_LIBRARY - -/* Not a very useful function; just to avoid duplication of code */ static bool write_execute_load_query_log_event(THD *thd, const sql_exchange* ex, const char* db_arg, /* table's database */ const char* table_name_arg, @@ -874,27 +872,34 @@ static bool write_execute_load_query_log_event(THD *thd, const sql_exchange* ex, int errcode) { char *load_data_query; - my_off_t fname_start, - fname_end; - List fv; + my_off_t fname_start, fname_end; Item *item, *val; int n; - const char *tdb= (thd->db.str != NULL ? thd->db.str : db_arg); - const char *qualify_db= NULL; - char command_buffer[1024]; - String query_str(command_buffer, sizeof(command_buffer), - system_charset_info); + StringBuffer<1024> query_str(system_charset_info); - Load_log_event lle(thd, ex, tdb, table_name_arg, fv, is_concurrent, - duplicates, ignore, transactional_table); + query_str.append(STRING_WITH_LEN("LOAD DATA ")); + + if (is_concurrent) + query_str.append(STRING_WITH_LEN("CONCURRENT ")); + + fname_start= query_str.length(); - /* - force in a LOCAL if there was one in the original. - */ if (thd->lex->local_file) - lle.set_fname_outside_temp_buf(ex->file_name, strlen(ex->file_name)); + query_str.append(STRING_WITH_LEN("LOCAL ")); + query_str.append(STRING_WITH_LEN("INFILE '")); + query_str.append_for_single_quote(ex->file_name, strlen(ex->file_name)); + query_str.append(STRING_WITH_LEN("' ")); - query_str.length(0); + if (duplicates == DUP_REPLACE) + query_str.append(STRING_WITH_LEN("REPLACE ")); + else if (ignore) + query_str.append(STRING_WITH_LEN("IGNORE ")); + + query_str.append(STRING_WITH_LEN("INTO")); + + fname_end= query_str.length(); + + query_str.append(STRING_WITH_LEN(" TABLE ")); if (!thd->db.str || strcmp(db_arg, thd->db.str)) { /* @@ -902,10 +907,47 @@ static bool write_execute_load_query_log_event(THD *thd, const sql_exchange* ex, prefix table name with database name so that it becomes a FQ name. */ - qualify_db= db_arg; + append_identifier(thd, &query_str, db_arg, strlen(db_arg)); + query_str.append(STRING_WITH_LEN(".")); + } + append_identifier(thd, &query_str, table_name_arg, strlen(table_name_arg)); + + if (ex->cs) + { + query_str.append(STRING_WITH_LEN(" CHARACTER SET ")); + query_str.append(ex->cs->cs_name); + } + + /* We have to create all optional fields as the default is not empty */ + query_str.append(STRING_WITH_LEN(" FIELDS TERMINATED BY '")); + query_str.append_for_single_quote(ex->field_term); + query_str.append(STRING_WITH_LEN("'")); + if (ex->opt_enclosed) + query_str.append(STRING_WITH_LEN(" OPTIONALLY")); + query_str.append(STRING_WITH_LEN(" ENCLOSED BY '")); + query_str.append_for_single_quote(ex->enclosed); + query_str.append(STRING_WITH_LEN("'")); + + query_str.append(STRING_WITH_LEN(" ESCAPED BY '")); + query_str.append_for_single_quote(ex->escaped); + query_str.append(STRING_WITH_LEN("'")); + + query_str.append(STRING_WITH_LEN(" LINES TERMINATED BY '")); + query_str.append_for_single_quote(ex->line_term); + query_str.append(STRING_WITH_LEN("'")); + if (ex->line_start->length()) + { + query_str.append(STRING_WITH_LEN(" STARTING BY '")); + query_str.append_for_single_quote(ex->line_start); + query_str.append(STRING_WITH_LEN("'")); + } + + if (ex->skip_lines) + { + query_str.append(STRING_WITH_LEN(" IGNORE ")); + query_str.append_ulonglong(ex->skip_lines); + query_str.append(STRING_WITH_LEN(" LINES ")); } - lle.print_query(thd, FALSE, (const char*) ex->cs ? ex->cs->cs_name.str : NULL, - &query_str, &fname_start, &fname_end, qualify_db); /* prepare fields-list and SET if needed; print_query won't do that for us. -- cgit v1.2.3