MySQL  8.0.21
Source Code Documentation
sql_load.h
Go to the documentation of this file.
1 /* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef SQL_LOAD_INCLUDED
24 #define SQL_LOAD_INCLUDED
25 
26 #include <sys/types.h>
27 
28 #include "lex_string.h"
29 #include "m_ctype.h"
30 #include "my_dbug.h"
31 #include "my_sqlcommand.h"
32 #include "sql/sql_cmd.h" /* Sql_cmd */
33 #include "sql/sql_data_change.h" /* enum_duplicates */
34 #include "sql/sql_exchange.h" /* sql_exchange */
35 #include "sql/sql_lex.h"
36 #include "sql/sql_list.h"
37 #include "sql_string.h"
38 
39 class Item;
40 class READ_INFO;
41 class THD;
42 struct TABLE_LIST;
43 
45  public:
46  Sql_cmd_load_table(enum_filetype filetype, bool is_local_file,
47  const LEX_STRING &filename, On_duplicate on_duplicate,
48  Table_ident *table, List<String> *opt_partitions,
49  const CHARSET_INFO *opt_charset,
50  String *opt_xml_rows_identified_by,
51  const Field_separators &field_separators,
52  const Line_separators &line_separators, ulong skip_lines,
53  List<Item> *opt_fields_or_vars, List<Item> *opt_set_fields,
54  List<Item> *opt_set_exprs,
55  List<String> *opt_set_expr_strings)
56  : m_exchange(filename.str, false, filetype),
57  m_is_local_file(is_local_file),
58  m_on_duplicate(on_duplicate),
59  m_table(table),
60  m_opt_partitions(opt_partitions),
61  m_opt_set_expr_strings(opt_set_expr_strings) {
62  if (opt_fields_or_vars) m_opt_fields_or_vars = *opt_fields_or_vars;
63  DBUG_ASSERT((opt_set_fields == nullptr) ^ (opt_set_exprs != nullptr));
64  if (opt_set_fields) {
65  DBUG_ASSERT(opt_set_fields->elements == opt_set_exprs->elements);
66  m_opt_set_fields = *opt_set_fields;
67  m_opt_set_exprs = *opt_set_exprs;
68  }
69 
70  m_exchange.cs = opt_charset;
71 
72  if (opt_xml_rows_identified_by != nullptr)
73  m_exchange.line.line_term = opt_xml_rows_identified_by;
74 
75  m_exchange.field.merge_field_separators(field_separators);
76  m_exchange.line.merge_line_separators(line_separators);
77  m_exchange.skip_lines = skip_lines;
78  }
79 
80  enum_sql_command sql_command_code() const override { return SQLCOM_LOAD; }
81 
82  bool execute(THD *thd) override;
83 
84  public:
86  const bool m_is_local_file;
93 
94  /**
95  A list of strings is maintained to store the SET clause command user strings
96  which are specified in load data operation. This list will be used
97  during the reconstruction of "load data" statement at the time of writing
98  to binary log.
99  */
101 
102  private:
103  bool execute_inner(THD *thd, enum enum_duplicates handle_duplicates);
104 
105  bool read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
106  READ_INFO &read_info, ulong skip_lines);
107 
108  bool read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
109  READ_INFO &read_info, const String &enclosed,
110  ulong skip_lines);
111 
112  bool read_xml_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
113  READ_INFO &read_info, ulong skip_lines);
114 
116  THD *thd, const char *db, const char *table_name, bool is_concurrent,
117  enum enum_duplicates duplicates, bool transactional_table, int errocode);
118 };
119 
120 #endif /* SQL_LOAD_INCLUDED */
Line_separators line
Definition: sql_exchange.h:79
Representation of an SQL command.
Definition: sql_cmd.h:63
Our own string classes, used pervasively throughout the executor.
Definition: mysql_lex_string.h:34
void merge_line_separators(const Line_separators &s)
Definition: sql_exchange.h:40
enum_duplicates
Definition: sql_data_change.h:45
enum_sql_command
Definition: my_sqlcommand.h:45
bool read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, READ_INFO &read_info, ulong skip_lines)
Read of rows of fixed size + optional garbage + optional newline.
Definition: sql_load.cc:737
const String * line_term
Definition: sql_exchange.h:36
Representation of an SQL command.
List< Item > m_opt_set_fields
Definition: sql_load.h:91
const bool m_is_local_file
Definition: sql_load.h:86
Used to hold information about file and file structure in exchange via non-DB file (...
Definition: sql_exchange.h:76
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:164
List< Item > m_opt_set_exprs
Definition: sql_load.h:92
void merge_field_separators(const Field_separators &s)
Definition: sql_exchange.h:60
Definition: sql_lex.h:256
enum_filetype
Definition: sql_exchange.h:29
unsigned long skip_lines
Definition: sql_exchange.h:83
const On_duplicate m_on_duplicate
Definition: sql_load.h:87
#define DBUG_ASSERT(A)
Definition: my_dbug.h:199
Sql_cmd_load_table(enum_filetype filetype, bool is_local_file, const LEX_STRING &filename, On_duplicate on_duplicate, Table_ident *table, List< String > *opt_partitions, const CHARSET_INFO *opt_charset, String *opt_xml_rows_identified_by, const Field_separators &field_separators, const Line_separators &line_separators, ulong skip_lines, List< Item > *opt_fields_or_vars, List< Item > *opt_set_fields, List< Item > *opt_set_exprs, List< String > *opt_set_expr_strings)
Definition: sql_load.h:46
Definition: sql_load.cc:115
Definition: sql_load.h:44
List< String > *const m_opt_partitions
Definition: sql_load.h:89
Definition: item.h:741
#define final(a, b, c)
Definition: hash.c:109
sql_exchange m_exchange
Definition: sql_load.h:85
List< Item > m_opt_fields_or_vars
Definition: sql_load.h:90
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_load.h:80
On_duplicate
Definition: parser_yystype.h:147
Definition: m_ctype.h:359
Table_ident *const m_table
Definition: sql_load.h:88
List< String > *const m_opt_set_expr_strings
A list of strings is maintained to store the SET clause command user strings which are specified in l...
Definition: sql_load.h:100
Field_separators field
Definition: sql_exchange.h:78
bool read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, READ_INFO &read_info, const String &enclosed, ulong skip_lines)
Read rows in delimiter-separated formats.
Definition: sql_load.cc:903
bool execute(THD *thd) override
Execute this SQL statement.
Definition: sql_load.cc:2099
This class encapsulates a data change operation.
Definition: sql_data_change.h:71
const char * filename
Definition: pfs_example_component_population.cc:64
Helper for the sql_exchange class.
Definition: sql_exchange.h:50
uint elements
Definition: sql_list.h:135
Definition: my_sqlcommand.h:76
Contains classes representing SQL-data change statements.
const CHARSET_INFO * cs
Definition: sql_exchange.h:84
bool execute_inner(THD *thd, enum enum_duplicates handle_duplicates)
Execute LOAD DATA query.
Definition: sql_load.cc:188
A better implementation of the UNIX ctype(3) library.
static char * enclosed
Definition: mysqldump.cc:133
Log info(cout, "NOTE")
bool read_xml_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, READ_INFO &read_info, ulong skip_lines)
Read rows in xml format.
Definition: sql_load.cc:1123
Definition: table.h:2494
#define false
Definition: config_static.h:43
Helper for the sql_exchange class.
Definition: sql_exchange.h:35
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:799
const char * table_name
Definition: rules_table_service.cc:55
bool write_execute_load_query_log_event(THD *thd, const char *db, const char *table_name, bool is_concurrent, enum enum_duplicates duplicates, bool transactional_table, int errocode)
Definition: sql_load.cc:666