Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
741a1df4
Commit
741a1df4
authored
Oct 12, 2009
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WL#1397 convert XML -> SQL
parent
946dc457
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
859 additions
and
34 deletions
+859
-34
mysql-test/r/loadxml.result
mysql-test/r/loadxml.result
+79
-0
mysql-test/std_data/loadxml.dat
mysql-test/std_data/loadxml.dat
+64
-0
mysql-test/std_data/loadxml2.dat
mysql-test/std_data/loadxml2.dat
+19
-0
mysql-test/t/loadxml.test
mysql-test/t/loadxml.test
+106
-0
sql/lex.h
sql/lex.h
+1
-0
sql/sql_class.cc
sql/sql_class.cc
+6
-2
sql/sql_class.h
sql/sql_class.h
+4
-1
sql/sql_load.cc
sql/sql_load.cc
+525
-2
sql/sql_yacc.yy
sql/sql_yacc.yy
+55
-29
No files found.
mysql-test/r/loadxml.result
0 → 100644
View file @
741a1df4
drop table if exists t1, t2;
create table t1 (a int, b varchar(64));
-- Load a static XML file
load xml infile '../../std_data/loadxml.dat' into table t1
rows identified by '<row>';
select * from t1 order by a;
a b
1 b1
2 b2
3 b3
11 b11
111 b111
112 b112 & < > " ' &unknown; -- check entities
212 b212
213 b213
214 b214
215 b215
216 &bb b;
delete from t1;
-- Load a static XML file with 'IGNORE num ROWS'
load xml infile '../../std_data/loadxml.dat' into table t1
rows identified by '<row>' ignore 4 rows;
select * from t1 order by a;
a b
111 b111
112 b112 & < > " ' &unknown; -- check entities
212 b212
213 b213
214 b214
215 b215
216 &bb b;
-- Check 'mysqldump --xml' + 'LOAD XML' round trip
delete from t1;
load xml infile 'MYSQLTEST_VARDIR/tmp/loadxml-dump.xml' into table t1 rows identified by '<row>';;
select * from t1 order by a;
a b
111 b111
112 b112 & < > " ' &unknown; -- check entities
212 b212
213 b213
214 b214
215 b215
216 &bb b;
--Check that default row tag is '<row>
delete from t1;
load xml infile 'MYSQLTEST_VARDIR/tmp/loadxml-dump.xml' into table t1;;
select * from t1 order by a;
a b
111 b111
112 b112 & < > " ' &unknown; -- check entities
212 b212
213 b213
214 b214
215 b215
216 &bb b;
-- Check that 'xml' is not a keyword
select 1 as xml;
xml
1
create table t2(fl text);
LOAD XML LOCAL INFILE "$MYSQLTEST_VARDIR/tmp/loadxml-dump.xml" INTO TABLE t2 ROWS IDENTIFIED BY '<person>';;
show processlist;
Id User Host db Command Time State Info
2 root localhost test Query 0 NULL show processlist
5 root localhost test Query 3 Reading from net LOAD XML LOCAL INFILE "$MYSQLTEST_VARDIR/tmp/loadxml-dump.xml" INTO TABLE t2 ROWS IDENTIFIED BY '<p
drop table t1;
drop table t2;
create table t1 (
id int(11) not null,
text text,
primary key (id)
) engine=MyISAM default charset=latin1;
load xml infile '../../std_data/loadxml2.dat' into table t1;
select * from t1;
id text
1 line1
line2
line3
drop table t1;
mysql-test/std_data/loadxml.dat
0 → 100644
View file @
741a1df4
<?xml version="1.0"?>
<mysqldump
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
>
<database
name=
"test"
>
<table_structure
name=
"t1"
>
<field
Field=
"a"
Type=
"int(11)"
Null=
"YES"
Key=
""
Extra=
""
/>
<field
Field=
"b"
Type=
"varchar(128)"
Null=
"YES"
Key=
""
Extra=
""
/>
<options
Name=
"t1"
Engine=
"MyISAM"
Version=
"10"
Row_format=
"Dynamic"
Rows=
"3"
Avg_row_length=
"20"
Data_length=
"60"
Max_data_length=
"281474976710655"
Index_length=
"1024"
Data_free=
"0"
Create_time=
"2007-02-09 09:08:36"
Update_time=
"2007-02-09 09:08:54"
Collation=
"latin1_swedish_ci"
Create_options=
""
Comment=
""
/>
</table_structure>
<table_data
name=
"t1"
>
<row>
<field
name=
"a"
>
1
</field>
<field
name=
"b"
>
b1
</field>
</row>
<row>
<field
name=
"a"
>
2
</field>
<field
name=
"b"
>
b2
</field>
</row>
<row>
<field
name=
"a"
>
3
</field>
<field
name=
"b"
>
b3
</field>
</row>
<row>
<field
name=
"a"
>
11
</field>
<field
name=
"b"
>
b11
</field>
</row>
<!-- Check field values as tags -->
<row>
<a>
111
</a>
<b>
b111
</b>
</row>
<row>
<a>
112
</a>
<b>
b112
&
<
>
"
'
&unknown;
-- check entities
</b>
</row>
<!-- Check field values in attributes -->
<row
a=
212
b=
"b212"
></row>
<!-- Bug#29752 Linefeeds break LOAD XML INFILE -->
<!-- Check varios combinations of TAB and NL -->
<row
a=
213
b=
"b213"
>
</row>
<row
a=
214
b=
"b214"
>
</row>
<row
a=
215
b=
"b215"
></row>
<row
a=
216
b=
"&bb
b;"
></row>
<!-- End of bug#29752 -->
</table_data>
</database>
</mysqldump>
mysql-test/std_data/loadxml2.dat
0 → 100644
View file @
741a1df4
<?xml version="1.0"?>
<mysqldump
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
>
<database
name=
"test_of_xml_import"
>
<table_structure
name=
"t1"
>
<field
Field=
"id"
Type=
"int(11)"
Null=
"NO"
Key=
"PRI"
Extra=
""
/>
<field
Field=
"text"
Type=
"text"
Null=
"YES"
Key=
""
Extra=
""
/>
<key
Table=
"t1"
Non_unique=
"0"
Key_name=
"PRIMARY"
Seq_in_index=
"1"
Column_name=
"id"
Collation=
"A"
Cardinality=
"1"
Null=
""
Index_type=
"BTREE"
Comment=
""
Index_Comment=
""
/>
<options
Name=
"t1"
Engine=
"MyISAM"
Version=
"10"
Row_format=
"Dynamic"
Rows=
"1"
Avg_row_length=
"32"
Data_length=
"32"
Max_data_length=
"281474976710655"
Index_length=
"2048"
Data_free=
"0"
Create_time=
"2009-06-18 10:02:37"
Update_time=
"2009-06-18 10:02:43"
Collation=
"latin1_swedish_ci"
Create_options=
""
Comment=
""
/>
</table_structure>
<table_data
name=
"t1"
>
<row>
<field
name=
"id"
>
1
</field>
<field
name=
"text"
>
line1
line2
line3
</field>
</row>
</table_data>
</database>
</mysqldump>
mysql-test/t/loadxml.test
0 → 100644
View file @
741a1df4
#
# Tests for "LOAD XML" - a contributed patch from Erik Wetterberg.
#
# Running the $MYSQL_DUMP tool against an embedded server does not work.
--
source
include
/
not_embedded
.
inc
--
disable_warnings
drop
table
if
exists
t1
,
t2
;
--
enable_warnings
create
table
t1
(
a
int
,
b
varchar
(
64
));
--
echo
--
Load
a
static
XML
file
load
xml
infile
'../../std_data/loadxml.dat'
into
table
t1
rows
identified
by
'<row>'
;
select
*
from
t1
order
by
a
;
delete
from
t1
;
--
echo
--
Load
a
static
XML
file
with
'IGNORE num ROWS'
load
xml
infile
'../../std_data/loadxml.dat'
into
table
t1
rows
identified
by
'<row>'
ignore
4
rows
;
select
*
from
t1
order
by
a
;
--
echo
--
Check
'mysqldump --xml'
+
'LOAD XML'
round
trip
--
exec
$MYSQL_DUMP
--
xml
test
t1
>
"
$MYSQLTEST_VARDIR
/tmp/loadxml-dump.xml"
2
>&
1
delete
from
t1
;
--
replace_result
$MYSQLTEST_VARDIR
MYSQLTEST_VARDIR
--
eval
load
xml
infile
'$MYSQLTEST_VARDIR/tmp/loadxml-dump.xml'
into
table
t1
rows
identified
by
'<row>'
;
select
*
from
t1
order
by
a
;
--
echo
--
Check
that
default
row
tag
is
'<row>
delete from t1;
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--eval load xml infile '
$MYSQLTEST_VARDIR
/
tmp
/
loadxml
-
dump
.
xml
' into table t1;
select * from t1 order by a;
--echo -- Check that '
xml
' is not a keyword
select 1 as xml;
#
# Bug #42520 killing load .. infile Assertion failed: ! is_set(), file .\sql_error.cc, line 8
#
--disable_query_log
delete from t1;
insert into t1 values (1, '
12345678900987654321
'), (2, '
asdfghjkl
;
asdfghjkl
;
');
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
insert into t1 select * from t1;
--exec $MYSQL_DUMP --xml test t1 > "$MYSQLTEST_VARDIR/tmp/loadxml-dump.xml" 2>&1
--enable_query_log
connect (addconroot, localhost, root,,);
connection addconroot;
create table t2(fl text);
--let $PSEUDO_THREAD_ID=`select @@pseudo_thread_id `
--send LOAD XML LOCAL INFILE "$MYSQLTEST_VARDIR/tmp/loadxml-dump.xml" INTO TABLE t2 ROWS IDENTIFIED BY '
<
person
>
';
sleep 3;
connection default;
show processlist;
--disable_query_log
--eval kill $PSEUDO_THREAD_ID
--enable_query_log
disconnect addconroot;
#
# Clean up
#
remove_file $MYSQLTEST_VARDIR/tmp/loadxml-dump.xml;
drop table t1;
drop table t2;
#
# Bug #36750 LOAD XML doesn'
t
understand
new
line
(
feed
)
characters
in
multi
line
text
fields
#
create
table
t1
(
id
int
(
11
)
not
null
,
text
text
,
primary
key
(
id
)
)
engine
=
MyISAM
default
charset
=
latin1
;
load
xml
infile
'../../std_data/loadxml2.dat'
into
table
t1
;
select
*
from
t1
;
drop
table
t1
;
sql/lex.h
View file @
741a1df4
...
...
@@ -607,6 +607,7 @@ static SYMBOL symbols[] = {
{
"X509"
,
SYM
(
X509_SYM
)},
{
"XOR"
,
SYM
(
XOR
)},
{
"XA"
,
SYM
(
XA_SYM
)},
{
"XML"
,
SYM
(
XML_SYM
)},
/* LOAD XML Arnold/Erik */
{
"YEAR"
,
SYM
(
YEAR_SYM
)},
{
"YEAR_MONTH"
,
SYM
(
YEAR_MONTH_SYM
)},
{
"ZEROFILL"
,
SYM
(
ZEROFILL
)},
...
...
sql/sql_class.cc
View file @
741a1df4
...
...
@@ -1602,13 +1602,17 @@ bool select_result::check_simple_select() const
static
String
default_line_term
(
"
\n
"
,
default_charset_info
);
static
String
default_escaped
(
"
\\
"
,
default_charset_info
);
static
String
default_field_term
(
"
\t
"
,
default_charset_info
);
static
String
default_xml_row_term
(
"<row>"
,
default_charset_info
);
sql_exchange
::
sql_exchange
(
char
*
name
,
bool
flag
)
sql_exchange
::
sql_exchange
(
char
*
name
,
bool
flag
,
enum
enum_filetype
filetype_arg
)
:
file_name
(
name
),
opt_enclosed
(
0
),
dumpfile
(
flag
),
skip_lines
(
0
)
{
filetype
=
filetype_arg
;
field_term
=
&
default_field_term
;
enclosed
=
line_start
=
&
my_empty_string
;
line_term
=
&
default_line_term
;
line_term
=
filetype
==
FILETYPE_CSV
?
&
default_line_term
:
&
default_xml_row_term
;
escaped
=
&
default_escaped
;
cs
=
NULL
;
}
...
...
sql/sql_class.h
View file @
741a1df4
...
...
@@ -89,6 +89,7 @@ enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRICT,
SLAVE_EXEC_MODE_LAST_BIT
};
enum
enum_mark_columns
{
MARK_COLUMNS_NONE
,
MARK_COLUMNS_READ
,
MARK_COLUMNS_WRITE
};
enum
enum_filetype
{
FILETYPE_CSV
,
FILETYPE_XML
};
extern
char
internal_table_name
[
2
];
extern
char
empty_c_string
[
1
];
...
...
@@ -2364,13 +2365,15 @@ my_eof(THD *thd)
class
sql_exchange
:
public
Sql_alloc
{
public:
enum
enum_filetype
filetype
;
/* load XML, Added by Arnold & Erik */
char
*
file_name
;
String
*
field_term
,
*
enclosed
,
*
line_term
,
*
line_start
,
*
escaped
;
bool
opt_enclosed
;
bool
dumpfile
;
ulong
skip_lines
;
CHARSET_INFO
*
cs
;
sql_exchange
(
char
*
name
,
bool
dumpfile_flag
);
sql_exchange
(
char
*
name
,
bool
dumpfile_flag
,
enum_filetype
filetype_arg
=
FILETYPE_CSV
);
bool
escaped_given
(
void
);
};
...
...
sql/sql_load.cc
View file @
741a1df4
This diff is collapsed.
Click to expand it.
sql/sql_yacc.yy
View file @
741a1df4
...
...
@@ -508,6 +508,7 @@ Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
sp_head *sphead;
struct p_elem_val *p_elem_value;
enum index_hint_type index_hint;
enum enum_filetype filetype;
Diag_condition_item_name diag_condition_item_name;
}
...
...
@@ -1116,6 +1117,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token WRITE_SYM /* SQL-2003-N */
%token X509_SYM
%token XA_SYM
%token XML_SYM
%token XOR
%token YEAR_MONTH_SYM
%token YEAR_SYM /* SQL-2003-R */
...
...
@@ -1309,7 +1311,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
prepare prepare_src execute deallocate
statement sp_suid
sp_c_chistics sp_a_chistics sp_chistic sp_c_chistic xa
load_data
opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
view_replace_or_algorithm view_replace
view_algorithm view_or_trigger_or_sp_or_event
definer_tail no_definer_tail
...
...
@@ -1338,6 +1340,7 @@ END_OF_INPUT
%type <spname> sp_name
%type <index_hint> index_hint_type
%type <num> index_hint_clause
%type <filetype> data_or_xml
%type <NONE> signal_stmt resignal_stmt
%type <diag_condition_item_name> signal_condition_information_item_name
...
...
@@ -10663,7 +10666,7 @@ use:
/* import, export of files */
load:
LOAD
DATA_SYM
LOAD
data_or_xml
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
...
...
@@ -10671,39 +10674,21 @@ load:
if (lex->sphead)
{
my_error(ER_SP_BADSTATEMENT, MYF(0), "LOAD DATA");
my_error(ER_SP_BADSTATEMENT, MYF(0),
$2 == FILETYPE_CSV ? "LOAD DATA" : "LOAD XML");
MYSQL_YYABORT;
}
lex->fname_start= lip->get_ptr();
}
load_data
{}
| LOAD TABLE_SYM table_ident FROM MASTER_SYM
{
LEX *lex=Lex;
WARN_DEPRECATED(yythd, "6.0", "LOAD TABLE FROM MASTER",
"MySQL Administrator (mysqldump, mysql)");
if (lex->sphead)
{
my_error(ER_SP_BADSTATEMENT, MYF(0), "LOAD TABLE");
MYSQL_YYABORT;
}
lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
MYSQL_YYABORT;
}
;
load_data:
load_data_lock opt_local INFILE TEXT_STRING_filesystem
{
LEX *lex=Lex;
lex->sql_command= SQLCOM_LOAD;
lex->lock_option= $
1
;
lex->local_file= $
2
;
lex->lock_option= $
4
;
lex->local_file= $
5
;
lex->duplicates= DUP_ERROR;
lex->ignore= 0;
if (!(lex->exchange= new sql_exchange($
4.str, 0
)))
if (!(lex->exchange= new sql_exchange($
7.str, 0, $2
)))
MYSQL_YYABORT;
}
opt_duplicate INTO
...
...
@@ -10713,7 +10698,7 @@ load_data:
TABLE_SYM table_ident
{
LEX *lex=Lex;
if (!Select->add_table_to_list(YYTHD, $1
0
, NULL, TL_OPTION_UPDATING,
if (!Select->add_table_to_list(YYTHD, $1
3
, NULL, TL_OPTION_UPDATING,
lex->lock_option))
MYSQL_YYABORT;
lex->field_list.empty();
...
...
@@ -10721,12 +10706,37 @@ load_data:
lex->value_list.empty();
}
opt_load_data_charset
{ Lex->exchange->cs= $12; }
{ Lex->exchange->cs= $15; }
opt_xml_rows_identified_by
opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
opt_load_data_set_spec
{}
| FROM MASTER_SYM
|
LOAD TABLE_SYM table_ident
FROM MASTER_SYM
{
LEX *lex=Lex;
WARN_DEPRECATED(yythd, "6.0", "LOAD TABLE FROM MASTER",
"MySQL Administrator (mysqldump, mysql)");
if (lex->sphead)
{
my_error(ER_SP_BADSTATEMENT, MYF(0), "LOAD TABLE");
MYSQL_YYABORT;
}
lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
MYSQL_YYABORT;
}
| LOAD DATA_SYM FROM MASTER_SYM
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
Lex_input_stream *lip= YYLIP;
if (lex->sphead)
{
my_error(ER_SP_BADSTATEMENT, MYF(0), "LOAD DATA");
MYSQL_YYABORT;
}
lex->fname_start= lip->get_ptr();
Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
WARN_DEPRECATED(yythd, "6.0", "LOAD DATA FROM MASTER",
"mysqldump or future "
...
...
@@ -10734,6 +10744,11 @@ load_data:
}
;
data_or_xml:
DATA_SYM { $$= FILETYPE_CSV; }
| XML_SYM { $$= FILETYPE_XML; }
;
opt_local:
/* empty */ { $$=0;}
| LOCAL_SYM { $$=1;}
...
...
@@ -10820,15 +10835,25 @@ line_term:
}
;
opt_xml_rows_identified_by:
/* empty */ { }
| ROWS_SYM IDENTIFIED_SYM BY text_string
{ Lex->exchange->line_term = $4; };
opt_ignore_lines:
/* empty */
| IGNORE_SYM NUM
LINES
| IGNORE_SYM NUM
lines_or_rows
{
DBUG_ASSERT(Lex->exchange != 0);
Lex->exchange->skip_lines= atol($2.str);
}
;
lines_or_rows:
LINES { }
| ROWS_SYM { }
;
opt_field_or_var_spec:
/* empty */ {}
| '(' fields_or_vars ')' {}
...
...
@@ -11924,6 +11949,7 @@ keyword_sp:
| WEEK_SYM {}
| WORK_SYM {}
| X509_SYM {}
| XML_SYM {}
| YEAR_SYM {}
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment