MySQL 9.4.0
Source Code Documentation
sql_exchange.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_EXCHANGE_INCLUDED
25#define SQL_EXCHANGE_INCLUDED
26
27#include "lex_string.h"
28#include "sql_string.h"
29
30struct Parse_context;
31
33
40};
41
47};
48
49enum class enum_with_header {
51 WITH_HEADER = 1,
53};
54
55enum class enum_trim_spaces {
59};
60
61/**
62 Helper for the sql_exchange class
63*/
64
66 public:
67 const String *line_term{nullptr};
68 const String *line_start{nullptr};
69
70 void merge_line_separators(const Line_separators *line_sep) {
71 if (line_sep == nullptr) return;
72 if (line_sep->line_term != nullptr) line_term = line_sep->line_term;
73 if (line_sep->line_start != nullptr) line_start = line_sep->line_start;
74 }
75
77 enum_filetype filetype_arg);
78};
79
80/**
81 Helper for the sql_exchange class
82*/
83
85 public:
86 const String *field_term{nullptr};
87 const String *escaped{nullptr};
88 const String *enclosed{nullptr};
89 bool opt_enclosed{false};
90 bool not_enclosed{false};
91 const String *date_format{nullptr};
92 const String *time_format{nullptr};
93 const String *datetime_format{nullptr};
95 const String *null_value{nullptr};
96 const String *empty_value{nullptr};
97
99 if (field_sep == nullptr) {
100 return;
101 }
102 if (field_sep->field_term != nullptr) field_term = field_sep->field_term;
103 if (field_sep->escaped != nullptr) escaped = field_sep->escaped;
104 if (field_sep->enclosed != nullptr) enclosed = field_sep->enclosed;
105 // TODO: a bug?
106 // OPTIONALLY ENCLOSED BY x ENCLOSED BY y == OPTIONALLY ENCLOSED BY y
107 if (field_sep->opt_enclosed) opt_enclosed = field_sep->opt_enclosed;
108 if (field_sep->not_enclosed) not_enclosed = field_sep->not_enclosed;
109 if (field_sep->date_format != nullptr) {
110 date_format = field_sep->date_format;
111 }
112 if (field_sep->time_format != nullptr) {
113 time_format = field_sep->time_format;
114 }
115 if (field_sep->datetime_format != nullptr) {
116 datetime_format = field_sep->datetime_format;
117 }
119 trim_spaces = field_sep->trim_spaces;
120 }
121
122 if (field_sep->null_value != nullptr) {
123 null_value = field_sep->null_value;
124 }
125 if (field_sep->empty_value != nullptr) {
126 empty_value = field_sep->empty_value;
127 }
128 }
129
130 void assign_default_values(enum_filetype filetype_arg);
131};
132
134 public:
135 const String *uri{nullptr};
136
138 if (uri_info == nullptr) {
139 return;
140 }
141 if (uri_info->uri != nullptr) uri = uri_info->uri;
142 }
143};
144
145/**
146 Used to hold information about file and file structure in exchange
147 via non-DB file (...INTO OUTFILE..., ...LOAD DATA...)
148 XXX: We never call destructor for objects of this class.
149*/
150
152 public:
153 const char *filetype_str{nullptr};
154 /// @cond Doxygen_is_confused
155 enum enum_filetype filetype { FILETYPE_TEXT };
156 /// @endcond
157 const String *compression{nullptr};
159 const CHARSET_INFO *cs{nullptr};
160
162
163 explicit File_information(enum_destination dumpfile_flag) {
164 if (dumpfile_flag == OBJECT_STORE_DEST) {
165 filetype = FILETYPE_CSV;
166 } else {
167 filetype = FILETYPE_TEXT;
168 }
169 }
170
171 explicit File_information(enum_filetype filetype_arg)
172 : filetype(filetype_arg) {}
173
175 if (file_info == nullptr) {
176 return;
177 }
178 if (file_info->filetype_str != nullptr) {
179 filetype_str = file_info->filetype_str;
180 }
181 if (file_info->compression != nullptr) {
182 compression = file_info->compression;
183 }
184 if (file_info->with_header != enum_with_header::DEFAULT_HEADER) {
185 with_header = file_info->with_header;
186 }
187 if (file_info->cs != nullptr) {
188 cs = file_info->cs;
189 }
190 }
191
193 bool do_contextualize();
194};
195
196class sql_exchange final {
197 public:
202 /* load XML, Added by Arnold & Erik */
203 const char *file_name{nullptr};
205 unsigned long skip_lines{0};
206
208 sql_exchange(const char *name, enum_destination dumpfile_flag,
209 enum_filetype filetype);
210 sql_exchange(const char *name, enum_destination dumpfile_flag);
211 explicit sql_exchange(enum_destination dumpfile_flag);
212 bool escaped_given(void);
215};
216
217#endif
Helper for the sql_exchange class.
Definition: sql_exchange.h:84
const String * field_term
Definition: sql_exchange.h:86
const String * empty_value
Definition: sql_exchange.h:96
const String * datetime_format
Definition: sql_exchange.h:93
bool not_enclosed
Definition: sql_exchange.h:90
const String * enclosed
Definition: sql_exchange.h:88
const String * time_format
Definition: sql_exchange.h:92
const String * escaped
Definition: sql_exchange.h:87
bool opt_enclosed
Definition: sql_exchange.h:89
void assign_default_values(enum_filetype filetype_arg)
Definition: query_result.cc:167
void merge_field_separators(const Field_separators *field_sep)
Definition: sql_exchange.h:98
enum_trim_spaces trim_spaces
Definition: sql_exchange.h:94
const String * date_format
Definition: sql_exchange.h:91
const String * null_value
Definition: sql_exchange.h:95
Used to hold information about file and file structure in exchange via non-DB file (....
Definition: sql_exchange.h:151
enum_with_header with_header
Definition: sql_exchange.h:158
const char * filetype_str
Definition: sql_exchange.h:153
File_information()
Definition: sql_exchange.h:161
File_information(enum_destination dumpfile_flag)
Definition: sql_exchange.h:163
File_information(enum_filetype filetype_arg)
Definition: sql_exchange.h:171
const String * compression
Definition: sql_exchange.h:157
void merge_file_information(const File_information *file_info)
Definition: sql_exchange.h:174
void assign_default_values()
Definition: query_result.cc:147
bool do_contextualize()
Definition: query_result.cc:125
Helper for the sql_exchange class.
Definition: sql_exchange.h:65
void assign_default_values(enum_destination dumpfile, enum_filetype filetype_arg)
Definition: query_result.cc:153
void merge_line_separators(const Line_separators *line_sep)
Definition: sql_exchange.h:70
const String * line_term
Definition: sql_exchange.h:67
const String * line_start
Definition: sql_exchange.h:68
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:169
Definition: sql_exchange.h:133
void merge_uri_info_separators(URI_information *uri_info)
Definition: sql_exchange.h:137
const String * uri
Definition: sql_exchange.h:135
Definition: sql_exchange.h:196
URI_information uri_info
Definition: sql_exchange.h:200
bool do_contextualize(Parse_context *pc)
Definition: query_result.cc:226
Field_separators field
Definition: sql_exchange.h:198
const char * file_name
Definition: sql_exchange.h:203
sql_exchange(const char *name, enum_destination dumpfile_flag, enum_filetype filetype)
Definition: query_result.cc:199
enum enum_destination dumpfile
Definition: sql_exchange.h:204
File_information file_info
Definition: sql_exchange.h:201
bool escaped_given(void)
Definition: query_result.cc:216
void assign_default_values()
Definition: query_result.cc:220
LEX_CSTRING outfile_json
Definition: sql_exchange.h:207
unsigned long skip_lines
Definition: sql_exchange.h:205
Line_separators line
Definition: sql_exchange.h:199
constexpr const LEX_CSTRING NULL_CSTR
Definition: lex_string.h:47
Definition: commit_order_queue.h:34
Definition: my_file.cc:180
enum_filetype
Definition: sql_exchange.h:34
@ FILETYPE_CSV
Definition: sql_exchange.h:35
@ FILETYPE_PARQUET
Definition: sql_exchange.h:38
@ FILETYPE_JSON
Definition: sql_exchange.h:39
@ FILETYPE_TEXT
Definition: sql_exchange.h:37
@ FILETYPE_XML
Definition: sql_exchange.h:36
enum_trim_spaces
Definition: sql_exchange.h:55
enum_destination
Definition: sql_exchange.h:42
@ DUMPFILE_DEST
Definition: sql_exchange.h:45
@ UNDEFINED_DEST
Definition: sql_exchange.h:43
@ OBJECT_STORE_DEST
Definition: sql_exchange.h:44
@ OUTFILE_DEST
Definition: sql_exchange.h:46
enum_source_type
Definition: sql_exchange.h:32
@ LOAD_SOURCE_S3
Definition: sql_exchange.h:32
@ LOAD_SOURCE_URL
Definition: sql_exchange.h:32
@ LOAD_SOURCE_FILE
Definition: sql_exchange.h:32
enum_with_header
Definition: sql_exchange.h:49
Our own string classes, used pervasively throughout the executor.
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:421
Definition: mysql_lex_string.h:40
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:422