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
f7e92479
Commit
f7e92479
authored
Sep 06, 2004
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added CHECK option test for INSERT ... ON DUPLICATE KEY UPDATE (WL#1983)
parent
ee03178f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
10 deletions
+69
-10
mysql-test/r/view.result
mysql-test/r/view.result
+13
-0
mysql-test/t/view.test
mysql-test/t/view.test
+13
-0
sql/sql_class.h
sql/sql_class.h
+6
-9
sql/sql_insert.cc
sql/sql_insert.cc
+35
-0
sql/sql_parse.cc
sql/sql_parse.cc
+2
-1
No files found.
mysql-test/r/view.result
View file @
f7e92479
...
...
@@ -1343,3 +1343,16 @@ a
2
drop view v3,v2,v1;
drop table t1;
create table t1 (a int, primary key (a));
create view v1 as select * from t1 where a < 2 with check option;
insert into v1 values (1) on duplicate key update a=2;
insert into v1 values (1) on duplicate key update a=2;
ERROR HY000: CHECK OPTION failed
insert ignore into v1 values (1) on duplicate key update a=2;
Warnings:
Error 1359 CHECK OPTION failed
select * from t1;
a
1
drop view v1;
drop table t1;
mysql-test/t/view.test
View file @
f7e92479
...
...
@@ -1296,3 +1296,16 @@ insert into v3 values (2);
select
*
from
t1
;
drop
view
v3
,
v2
,
v1
;
drop
table
t1
;
#
# CHECK OPTION with INSERT ... ON DUPLICATE KEY UPDATE
#
create
table
t1
(
a
int
,
primary
key
(
a
));
create
view
v1
as
select
*
from
t1
where
a
<
2
with
check
option
;
insert
into
v1
values
(
1
)
on
duplicate
key
update
a
=
2
;
--
error
1359
insert
into
v1
values
(
1
)
on
duplicate
key
update
a
=
2
;
insert
ignore
into
v1
values
(
1
)
on
duplicate
key
update
a
=
2
;
select
*
from
t1
;
drop
view
v1
;
drop
table
t1
;
sql/sql_class.h
View file @
f7e92479
...
...
@@ -227,6 +227,9 @@ typedef struct st_copy_info {
/* for INSERT ... UPDATE */
List
<
Item
>
*
update_fields
;
List
<
Item
>
*
update_values
;
/* for VIEW ... WITH CHECK OPTION */
Item
*
check_option
;
bool
ignore
;
}
COPY_INFO
;
...
...
@@ -1180,14 +1183,8 @@ class select_insert :public select_result {
bool
insert_into_view
;
select_insert
(
TABLE_LIST
*
table_list_par
,
TABLE
*
table_par
,
List
<
Item
>
*
fields_par
,
enum_duplicates
duplic
)
:
table_list
(
table_list_par
),
table
(
table_par
),
fields
(
fields_par
),
last_insert_id
(
0
),
insert_into_view
(
table_list_par
&&
table_list_par
->
view
!=
0
)
{
bzero
((
char
*
)
&
info
,
sizeof
(
info
));
info
.
handle_duplicates
=
duplic
;
}
List
<
Item
>
*
fields_par
,
enum_duplicates
duplic
,
bool
ignore_check_option_errors
);
~
select_insert
();
int
prepare
(
List
<
Item
>
&
list
,
SELECT_LEX_UNIT
*
u
);
bool
send_fields
(
List
<
Item
>
&
list
,
uint
flags
)
{
return
0
;
}
...
...
@@ -1211,7 +1208,7 @@ class select_create: public select_insert {
List
<
create_field
>
&
fields_par
,
List
<
Key
>
&
keys_par
,
List
<
Item
>
&
select_fields
,
enum_duplicates
duplic
)
:
select_insert
(
NULL
,
NULL
,
&
select_fields
,
duplic
),
create_table
(
table
),
:
select_insert
(
NULL
,
NULL
,
&
select_fields
,
duplic
,
0
),
create_table
(
table
),
extra_fields
(
&
fields_par
),
keys
(
&
keys_par
),
create_info
(
create_info_par
),
lock
(
0
)
{}
...
...
sql/sql_insert.cc
View file @
f7e92479
...
...
@@ -242,6 +242,8 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
info
.
handle_duplicates
=
duplic
;
info
.
update_fields
=&
update_fields
;
info
.
update_values
=&
update_values
;
info
.
check_option
=
table_list
->
check_option
;
info
.
ignore
=
thd
->
lex
->
duplicates
==
DUP_IGNORE
;
/*
Count warnings for all inserts.
For single line insert, generate an error if try to set a NOT NULL field
...
...
@@ -714,6 +716,24 @@ int write_record(TABLE *table,COPY_INFO *info)
restore_record
(
table
,
record
[
1
]);
if
(
fill_record
(
*
info
->
update_fields
,
*
info
->
update_values
,
0
))
goto
err
;
/* CHECK OPTION for VIEW ... ON DUPLICATE KEY UPDATE ... */
if
(
info
->
check_option
&&
info
->
check_option
->
val_int
()
==
0
)
{
if
(
info
->
ignore
)
{
push_warning
(
current_thd
,
MYSQL_ERROR
::
WARN_LEVEL_ERROR
,
ER_VIEW_CHECK_FAILED
,
ER
(
ER_VIEW_CHECK_FAILED
));
break
;
}
else
{
my_error
(
ER_VIEW_CHECK_FAILED
,
MYF
(
0
));
goto
err
;
}
}
if
((
error
=
table
->
file
->
update_row
(
table
->
record
[
1
],
table
->
record
[
0
])))
goto
err
;
info
->
updated
++
;
...
...
@@ -1633,6 +1653,21 @@ int mysql_insert_select_prepare(THD *thd)
}
select_insert
::
select_insert
(
TABLE_LIST
*
table_list_par
,
TABLE
*
table_par
,
List
<
Item
>
*
fields_par
,
enum_duplicates
duplic
,
bool
ignore_check_option_errors
)
:
table_list
(
table_list_par
),
table
(
table_par
),
fields
(
fields_par
),
last_insert_id
(
0
),
insert_into_view
(
table_list_par
&&
table_list_par
->
view
!=
0
)
{
bzero
((
char
*
)
&
info
,
sizeof
(
info
));
info
.
handle_duplicates
=
duplic
;
if
(
table_list_par
)
info
.
check_option
=
table_list_par
->
check_option
;
info
.
ignore
=
ignore_check_option_errors
;
}
int
select_insert
::
prepare
(
List
<
Item
>
&
values
,
SELECT_LEX_UNIT
*
u
)
{
...
...
sql/sql_parse.cc
View file @
f7e92479
...
...
@@ -2769,7 +2769,8 @@ mysql_execute_command(THD *thd)
if
((
res
=
mysql_insert_select_prepare
(
thd
)))
break
;
if
((
result
=
new
select_insert
(
first_table
,
first_table
->
table
,
&
lex
->
field_list
,
lex
->
duplicates
)))
&
lex
->
field_list
,
lex
->
duplicates
,
lex
->
duplicates
==
DUP_IGNORE
)))
/* Skip first table, which is the table we are inserting in */
lex
->
select_lex
.
table_list
.
first
=
(
byte
*
)
first_table
->
next_local
;
/*
...
...
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