MySQL 9.2.0
Source Code Documentation
sql_exchange.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, 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};
94 const String *null_value{nullptr};
95 const String *empty_value{nullptr};
96
98 if (field_sep == nullptr) {
99 return;
100 }
101 if (field_sep->field_term != nullptr) field_term = field_sep->field_term;
102 if (field_sep->escaped != nullptr) escaped = field_sep->escaped;
103 if (field_sep->enclosed != nullptr) enclosed = field_sep->enclosed;
104 // TODO: a bug?
105 // OPTIONALLY ENCLOSED BY x ENCLOSED BY y == OPTIONALLY ENCLOSED BY y
106 if (field_sep->opt_enclosed) opt_enclosed = field_sep->opt_enclosed;
107 if (field_sep->not_enclosed) not_enclosed = field_sep->not_enclosed;
108 if (field_sep->date_format != nullptr) {
109 date_format = field_sep->date_format;
110 }
111 if (field_sep->time_format != nullptr) {
112 time_format = field_sep->time_format;
113 }
115 trim_spaces = field_sep->trim_spaces;
116 }
117
118 if (field_sep->null_value != nullptr) {
119 null_value = field_sep->null_value;
120 }
121 if (field_sep->empty_value != nullptr) {
122 empty_value = field_sep->empty_value;
123 }
124 }
125
126 void assign_default_values(enum_filetype filetype_arg);
127};
128
130 public:
131 const String *uri{nullptr};
132
134 if (uri_info == nullptr) {
135 return;
136 }
137 if (uri_info->uri != nullptr) uri = uri_info->uri;
138 }
139};
140
141/**
142 Used to hold information about file and file structure in exchange
143 via non-DB file (...INTO OUTFILE..., ...LOAD DATA...)
144 XXX: We never call destructor for objects of this class.
145*/
146
148 public:
149 const char *filetype_str{nullptr};
150 /// @cond Doxygen_is_confused
151 enum enum_filetype filetype { FILETYPE_TEXT };
152 /// @endcond
153 const String *compression{nullptr};
155 const CHARSET_INFO *cs{nullptr};
156
158
159 explicit File_information(enum_destination dumpfile_flag) {
160 if (dumpfile_flag == OBJECT_STORE_DEST) {
161 filetype = FILETYPE_CSV;
162 } else {
163 filetype = FILETYPE_TEXT;
164 }
165 }
166
167 explicit File_information(enum_filetype filetype_arg)
168 : filetype(filetype_arg) {}
169
171 if (file_info == nullptr) {
172 return;
173 }
174 if (file_info->filetype_str != nullptr) {
175 filetype_str = file_info->filetype_str;
176 }
177 if (file_info->compression != nullptr) {
178 compression = file_info->compression;
179 }
180 if (file_info->with_header != enum_with_header::DEFAULT_HEADER) {
181 with_header = file_info->with_header;
182 }
183 if (file_info->cs != nullptr) {
184 cs = file_info->cs;
185 }
186 }
187
189 bool do_contextualize();
190};
191
192class sql_exchange final {
193 public:
198 /* load XML, Added by Arnold & Erik */
199 const char *file_name{nullptr};
201 unsigned long skip_lines{0};
202
204 sql_exchange(const char *name, enum_destination dumpfile_flag,
205 enum_filetype filetype);
206 sql_exchange(const char *name, enum_destination dumpfile_flag);
207 explicit sql_exchange(enum_destination dumpfile_flag);
208 bool escaped_given(void);
211};
212
213#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:95
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:97
enum_trim_spaces trim_spaces
Definition: sql_exchange.h:93
const String * date_format
Definition: sql_exchange.h:91
const String * null_value
Definition: sql_exchange.h:94
Used to hold information about file and file structure in exchange via non-DB file (....
Definition: sql_exchange.h:147
enum_with_header with_header
Definition: sql_exchange.h:154
const char * filetype_str
Definition: sql_exchange.h:149
File_information()
Definition: sql_exchange.h:157
File_information(enum_destination dumpfile_flag)
Definition: sql_exchange.h:159
File_information(enum_filetype filetype_arg)
Definition: sql_exchange.h:167
const String * compression
Definition: sql_exchange.h:153
void merge_file_information(const File_information *file_info)
Definition: sql_exchange.h:170
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:167
Definition: sql_exchange.h:129
void merge_uri_info_separators(URI_information *uri_info)
Definition: sql_exchange.h:133
const String * uri
Definition: sql_exchange.h:131
Definition: sql_exchange.h:192
URI_information uri_info
Definition: sql_exchange.h:196
bool do_contextualize(Parse_context *pc)
Definition: query_result.cc:226
Field_separators field
Definition: sql_exchange.h:194
const char * file_name
Definition: sql_exchange.h:199
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:200
File_information file_info
Definition: sql_exchange.h:197
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:203
unsigned long skip_lines
Definition: sql_exchange.h:201
Line_separators line
Definition: sql_exchange.h:195
constexpr const LEX_CSTRING NULL_CSTR
Definition: lex_string.h:47
Definition: commit_order_queue.h:34
Definition: my_file.cc:181
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:421