Commit e05e1860 authored by unknown's avatar unknown

post review changes:

CHECK OPTION moved to one function
view name added to error messages


mysql-test/r/view.result:
  error messages changed
sql/share/czech/errmsg.txt:
  view name added
sql/share/danish/errmsg.txt:
  view name added
sql/share/dutch/errmsg.txt:
  view name added
sql/share/english/errmsg.txt:
  view name added
sql/share/estonian/errmsg.txt:
  view name added
sql/share/french/errmsg.txt:
  view name added
sql/share/german/errmsg.txt:
  view name added
sql/share/greek/errmsg.txt:
  view name added
sql/share/hungarian/errmsg.txt:
  view name added
sql/share/italian/errmsg.txt:
  view name added
sql/share/japanese/errmsg.txt:
  view name added
sql/share/korean/errmsg.txt:
  view name added
sql/share/norwegian-ny/errmsg.txt:
  view name added
sql/share/norwegian/errmsg.txt:
  view name added
sql/share/polish/errmsg.txt:
  view name added
sql/share/portuguese/errmsg.txt:
  view name added
sql/share/romanian/errmsg.txt:
  view name added
sql/share/russian/errmsg.txt:
  view name added
sql/share/serbian/errmsg.txt:
  view name added
sql/share/slovak/errmsg.txt:
  view name added
sql/share/spanish/errmsg.txt:
  view name added
sql/share/swedish/errmsg.txt:
  view name added
sql/share/ukrainian/errmsg.txt:
  view name added
sql/sql_class.h:
  view reference saved
sql/sql_insert.cc:
  CHECK OPTION moved to one function
sql/sql_update.cc:
  CHECK OPTION moved to one function
sql/sql_view.cc:
  view name added to error message
sql/table.cc:
  CHECK OPTION moved to one function
sql/table.h:
  CHECK OPTION moved to one function
parent 44ca1f80
...@@ -477,7 +477,7 @@ drop view v1; ...@@ -477,7 +477,7 @@ drop view v1;
drop table t1; drop table t1;
create table t1 (a int); create table t1 (a int);
create view v1 as select distinct a from t1 WITH CHECK OPTION; create view v1 as select distinct a from t1 WITH CHECK OPTION;
ERROR HY000: CHECK OPTION on non-updatable view ERROR HY000: CHECK OPTION on non-updatable view 'test.v1'
create view v1 as select a from t1 WITH CHECK OPTION; create view v1 as select a from t1 WITH CHECK OPTION;
create view v2 as select a from t1 WITH CASCADED CHECK OPTION; create view v2 as select a from t1 WITH CASCADED CHECK OPTION;
create view v3 as select a from t1 WITH LOCAL CHECK OPTION; create view v3 as select a from t1 WITH LOCAL CHECK OPTION;
...@@ -1276,11 +1276,11 @@ create table t1 (a int); ...@@ -1276,11 +1276,11 @@ create table t1 (a int);
create view v1 as select * from t1 where a < 2 with check option; create view v1 as select * from t1 where a < 2 with check option;
insert into v1 values(1); insert into v1 values(1);
insert into v1 values(3); insert into v1 values(3);
ERROR HY000: CHECK OPTION failed ERROR HY000: CHECK OPTION failed 'test.v1'
insert ignore into v1 values (2),(3),(0); insert ignore into v1 values (2),(3),(0);
Warnings: Warnings:
Error 1359 CHECK OPTION failed Error 1359 CHECK OPTION failed 'test.v1'
Error 1359 CHECK OPTION failed Error 1359 CHECK OPTION failed 'test.v1'
select * from t1; select * from t1;
a a
1 1
...@@ -1288,20 +1288,20 @@ a ...@@ -1288,20 +1288,20 @@ a
delete from t1; delete from t1;
insert into v1 SELECT 1; insert into v1 SELECT 1;
insert into v1 SELECT 3; insert into v1 SELECT 3;
ERROR HY000: CHECK OPTION failed ERROR HY000: CHECK OPTION failed 'test.v1'
create table t2 (a int); create table t2 (a int);
insert into t2 values (2),(3),(0); insert into t2 values (2),(3),(0);
insert ignore into v1 SELECT a from t2; insert ignore into v1 SELECT a from t2;
Warnings: Warnings:
Error 1359 CHECK OPTION failed Error 1359 CHECK OPTION failed 'test.v1'
Error 1359 CHECK OPTION failed Error 1359 CHECK OPTION failed 'test.v1'
select * from t1; select * from t1;
a a
1 1
0 0
update v1 set a=-1 where a=0; update v1 set a=-1 where a=0;
update v1 set a=2 where a=1; update v1 set a=2 where a=1;
ERROR HY000: CHECK OPTION failed ERROR HY000: CHECK OPTION failed 'test.v1'
select * from t1; select * from t1;
a a
1 1
...@@ -1316,7 +1316,7 @@ a ...@@ -1316,7 +1316,7 @@ a
update v1 set a=a+1; update v1 set a=a+1;
update ignore v1,t2 set v1.a=v1.a+1 where v1.a=t2.a; update ignore v1,t2 set v1.a=v1.a+1 where v1.a=t2.a;
Warnings: Warnings:
Error 1359 CHECK OPTION failed Error 1359 CHECK OPTION failed 'test.v1'
select * from t1; select * from t1;
a a
1 1
...@@ -1330,12 +1330,12 @@ create view v3 as select * from v1 where a > 0 with cascaded check option; ...@@ -1330,12 +1330,12 @@ create view v3 as select * from v1 where a > 0 with cascaded check option;
insert into v2 values (1); insert into v2 values (1);
insert into v3 values (1); insert into v3 values (1);
insert into v2 values (0); insert into v2 values (0);
ERROR HY000: CHECK OPTION failed ERROR HY000: CHECK OPTION failed 'test.v2'
insert into v3 values (0); insert into v3 values (0);
ERROR HY000: CHECK OPTION failed ERROR HY000: CHECK OPTION failed 'test.v3'
insert into v2 values (2); insert into v2 values (2);
insert into v3 values (2); insert into v3 values (2);
ERROR HY000: CHECK OPTION failed ERROR HY000: CHECK OPTION failed 'test.v3'
select * from t1; select * from t1;
a a
1 1
...@@ -1347,10 +1347,10 @@ create table t1 (a int, primary key (a)); ...@@ -1347,10 +1347,10 @@ create table t1 (a int, primary key (a));
create view v1 as select * from t1 where a < 2 with check option; 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;
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 ERROR HY000: CHECK OPTION failed 'test.v1'
insert ignore into v1 values (1) on duplicate key update a=2; insert ignore into v1 values (1) on duplicate key update a=2;
Warnings: Warnings:
Error 1359 CHECK OPTION failed Error 1359 CHECK OPTION failed 'test.v1'
select * from t1; select * from t1;
a a
1 1
......
...@@ -370,5 +370,5 @@ character-set=latin2 ...@@ -370,5 +370,5 @@ character-set=latin2
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -364,5 +364,5 @@ character-set=latin1 ...@@ -364,5 +364,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -372,5 +372,5 @@ character-set=latin1 ...@@ -372,5 +372,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -361,5 +361,5 @@ character-set=latin1 ...@@ -361,5 +361,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -366,5 +366,5 @@ character-set=latin7 ...@@ -366,5 +366,5 @@ character-set=latin7
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -361,5 +361,5 @@ character-set=latin1 ...@@ -361,5 +361,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -373,5 +373,5 @@ character-set=latin1 ...@@ -373,5 +373,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -361,5 +361,5 @@ character-set=greek ...@@ -361,5 +361,5 @@ character-set=greek
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -363,5 +363,5 @@ character-set=latin2 ...@@ -363,5 +363,5 @@ character-set=latin2
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -361,5 +361,5 @@ character-set=latin1 ...@@ -361,5 +361,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -363,5 +363,5 @@ character-set=ujis ...@@ -363,5 +363,5 @@ character-set=ujis
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -361,5 +361,5 @@ character-set=euckr ...@@ -361,5 +361,5 @@ character-set=euckr
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -363,5 +363,5 @@ character-set=latin1 ...@@ -363,5 +363,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -363,5 +363,5 @@ character-set=latin1 ...@@ -363,5 +363,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -365,5 +365,5 @@ character-set=latin2 ...@@ -365,5 +365,5 @@ character-set=latin2
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -362,5 +362,5 @@ character-set=latin1 ...@@ -362,5 +362,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -365,5 +365,5 @@ character-set=latin2 ...@@ -365,5 +365,5 @@ character-set=latin2
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -363,5 +363,5 @@ character-set=koi8r ...@@ -363,5 +363,5 @@ character-set=koi8r
"View '%-.64s.%-.64s' " "View '%-.64s.%-.64s' "
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION VIEW" "CHECK OPTION VIEW '%-.64s.%-.64s'"
" CHECK OPTION " " CHECK OPTION VIEW '%-.64s.%-.64s' "
...@@ -367,5 +367,5 @@ character-set=cp1250 ...@@ -367,5 +367,5 @@ character-set=cp1250
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -369,5 +369,5 @@ character-set=latin2 ...@@ -369,5 +369,5 @@ character-set=latin2
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -363,5 +363,5 @@ character-set=latin1 ...@@ -363,5 +363,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -361,5 +361,5 @@ character-set=latin1 ...@@ -361,5 +361,5 @@ character-set=latin1
"View '%-.64s.%-.64s' references invalid table(s) or column(s)" "View '%-.64s.%-.64s' references invalid table(s) or column(s)"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION on non-updatable view" "CHECK OPTION on non-updatable view '%-.64s.%-.64s'"
"CHECK OPTION failed" "CHECK OPTION failed '%-.64s.%-.64s'"
...@@ -366,5 +366,5 @@ character-set=koi8u ...@@ -366,5 +366,5 @@ character-set=koi8u
"View '%-.64s.%-.64s' Ŧަ æ æ" "View '%-.64s.%-.64s' Ŧަ æ æ"
"Can't drop a %s from within another stored routine" "Can't drop a %s from within another stored routine"
"GOTO is not allowed in a stored procedure handler" "GOTO is not allowed in a stored procedure handler"
"CHECK OPTION VIEW " "CHECK OPTION VIEW '%-.64s.%-.64s' "
"צ CHECK OPTION " "צ CHECK OPTION VIEW '%-.64s.%-.64s' "
...@@ -228,7 +228,7 @@ typedef struct st_copy_info { ...@@ -228,7 +228,7 @@ typedef struct st_copy_info {
List<Item> *update_fields; List<Item> *update_fields;
List<Item> *update_values; List<Item> *update_values;
/* for VIEW ... WITH CHECK OPTION */ /* for VIEW ... WITH CHECK OPTION */
Item *check_option; TABLE_LIST *view;
bool ignore; bool ignore;
} COPY_INFO; } COPY_INFO;
......
...@@ -128,7 +128,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, ...@@ -128,7 +128,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
*/ */
bool log_on= (thd->options & OPTION_BIN_LOG) || (!(thd->master_access & SUPER_ACL)); bool log_on= (thd->options & OPTION_BIN_LOG) || (!(thd->master_access & SUPER_ACL));
bool transactional_table, log_delayed; bool transactional_table, log_delayed;
bool check; bool ignore_err= (thd->lex->duplicates == DUP_IGNORE);
uint value_count; uint value_count;
ulong counter = 1; ulong counter = 1;
ulonglong id; ulonglong id;
...@@ -242,8 +242,8 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, ...@@ -242,8 +242,8 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
info.handle_duplicates=duplic; info.handle_duplicates=duplic;
info.update_fields=&update_fields; info.update_fields=&update_fields;
info.update_values=&update_values; info.update_values=&update_values;
info.check_option= table_list->check_option; info.view= (table_list->view ? table_list : 0);
info.ignore= thd->lex->duplicates == DUP_IGNORE; info.ignore= ignore_err;
/* /*
Count warnings for all inserts. Count warnings for all inserts.
For single line insert, generate an error if try to set a NOT NULL field For single line insert, generate an error if try to set a NOT NULL field
...@@ -271,8 +271,6 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, ...@@ -271,8 +271,6 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
if (lock_type != TL_WRITE_DELAYED) if (lock_type != TL_WRITE_DELAYED)
table->file->start_bulk_insert(values_list.elements); table->file->start_bulk_insert(values_list.elements);
check= (table_list->check_option != 0);
while ((values= its++)) while ((values= its++))
{ {
if (fields.elements || !value_count) if (fields.elements || !value_count)
...@@ -307,20 +305,13 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, ...@@ -307,20 +305,13 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
break; break;
} }
} }
if (check && table_list->check_option->val_int() == 0) if ((res= table_list->view_check_option(thd, ignore_err)) ==
VIEW_CHECK_SKIP)
continue;
else if (res == VIEW_CHECK_ERROR)
{ {
if (thd->lex->duplicates == DUP_IGNORE) error= 1;
{ break;
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
ER_VIEW_CHECK_FAILED, ER(ER_VIEW_CHECK_FAILED));
continue;
}
else
{
my_error(ER_VIEW_CHECK_FAILED, MYF(0));
error=1;
break;
}
} }
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
if (lock_type == TL_WRITE_DELAYED) if (lock_type == TL_WRITE_DELAYED)
...@@ -708,6 +699,7 @@ int write_record(TABLE *table,COPY_INFO *info) ...@@ -708,6 +699,7 @@ int write_record(TABLE *table,COPY_INFO *info)
} }
if (info->handle_duplicates == DUP_UPDATE) if (info->handle_duplicates == DUP_UPDATE)
{ {
int res= 0;
/* we don't check for other UNIQUE keys - the first row /* we don't check for other UNIQUE keys - the first row
that matches, is updated. If update causes a conflict again, that matches, is updated. If update causes a conflict again,
an error is returned an error is returned
...@@ -718,21 +710,12 @@ int write_record(TABLE *table,COPY_INFO *info) ...@@ -718,21 +710,12 @@ int write_record(TABLE *table,COPY_INFO *info)
goto err; goto err;
/* CHECK OPTION for VIEW ... ON DUPLICATE KEY UPDATE ... */ /* CHECK OPTION for VIEW ... ON DUPLICATE KEY UPDATE ... */
if (info->check_option && if (info->view &&
info->check_option->val_int() == 0) (res= info->view->view_check_option(current_thd, info->ignore)) ==
{ VIEW_CHECK_SKIP)
if (info->ignore) break;
{ else if (res == VIEW_CHECK_ERROR)
push_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, goto err;
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]))) if ((error=table->file->update_row(table->record[1],table->record[0])))
goto err; goto err;
...@@ -1663,7 +1646,7 @@ select_insert::select_insert(TABLE_LIST *table_list_par, TABLE *table_par, ...@@ -1663,7 +1646,7 @@ select_insert::select_insert(TABLE_LIST *table_list_par, TABLE *table_par,
bzero((char*) &info,sizeof(info)); bzero((char*) &info,sizeof(info));
info.handle_duplicates=duplic; info.handle_duplicates=duplic;
if (table_list_par) if (table_list_par)
info.check_option= table_list_par->check_option; info.view= (table_list_par->view ? table_list_par : 0);
info.ignore= ignore_check_option_errors; info.ignore= ignore_check_option_errors;
} }
...@@ -1712,19 +1695,13 @@ bool select_insert::send_data(List<Item> &values) ...@@ -1712,19 +1695,13 @@ bool select_insert::send_data(List<Item> &values)
fill_record(*fields, values, 1); fill_record(*fields, values, 1);
else else
fill_record(table->field, values, 1); fill_record(table->field, values, 1);
if (table_list->check_option && table_list->check_option->val_int() == 0) switch (table_list->view_check_option(thd,
thd->lex->duplicates == DUP_IGNORE))
{ {
if (thd->lex->duplicates == DUP_IGNORE) case VIEW_CHECK_SKIP:
{ DBUG_RETURN(0);
push_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, case VIEW_CHECK_ERROR:
ER_VIEW_CHECK_FAILED, ER(ER_VIEW_CHECK_FAILED)); DBUG_RETURN(1);
DBUG_RETURN(0);
}
else
{
my_error(ER_VIEW_CHECK_FAILED, MYF(0));
DBUG_RETURN(1);
}
} }
if (thd->net.report_error || write_record(table,&info)) if (thd->net.report_error || write_record(table,&info))
DBUG_RETURN(1); DBUG_RETURN(1);
......
...@@ -94,11 +94,12 @@ int mysql_update(THD *thd, ...@@ -94,11 +94,12 @@ int mysql_update(THD *thd,
ha_rows limit, ha_rows limit,
enum enum_duplicates handle_duplicates) enum enum_duplicates handle_duplicates)
{ {
bool using_limit=limit != HA_POS_ERROR; bool using_limit= limit != HA_POS_ERROR;
bool safe_update= thd->options & OPTION_SAFE_UPDATES; bool safe_update= thd->options & OPTION_SAFE_UPDATES;
bool used_key_is_modified, transactional_table, log_delayed; bool used_key_is_modified, transactional_table, log_delayed;
bool check; bool ignore_err= (thd->lex->duplicates == DUP_IGNORE);
int error=0; int error=0;
int res;
uint used_index; uint used_index;
#ifndef NO_EMBEDDED_ACCESS_CHECKS #ifndef NO_EMBEDDED_ACCESS_CHECKS
uint want_privilege; uint want_privilege;
...@@ -150,7 +151,7 @@ int mysql_update(THD *thd, ...@@ -150,7 +151,7 @@ int mysql_update(THD *thd,
#endif #endif
{ {
thd->lex->select_lex.no_wrap_view_item= 1; thd->lex->select_lex.no_wrap_view_item= 1;
int res= setup_fields(thd, 0, table_list, fields, 1, 0, 0); res= setup_fields(thd, 0, table_list, fields, 1, 0, 0);
thd->lex->select_lex.no_wrap_view_item= 0; thd->lex->select_lex.no_wrap_view_item= 0;
if (res) if (res)
DBUG_RETURN(-1); /* purecov: inspected */ DBUG_RETURN(-1); /* purecov: inspected */
...@@ -345,7 +346,6 @@ int mysql_update(THD *thd, ...@@ -345,7 +346,6 @@ int mysql_update(THD *thd,
thd->count_cuted_fields= CHECK_FIELD_WARN; /* calc cuted fields */ thd->count_cuted_fields= CHECK_FIELD_WARN; /* calc cuted fields */
thd->cuted_fields=0L; thd->cuted_fields=0L;
thd->proc_info="Updating"; thd->proc_info="Updating";
check= (table_list->check_option != 0);
query_id=thd->query_id; query_id=thd->query_id;
while (!(error=info.read_record(&info)) && !thd->killed) while (!(error=info.read_record(&info)) && !thd->killed)
...@@ -355,25 +355,21 @@ int mysql_update(THD *thd, ...@@ -355,25 +355,21 @@ int mysql_update(THD *thd,
store_record(table,record[1]); store_record(table,record[1]);
if (fill_record(fields,values, 0) || thd->net.report_error) if (fill_record(fields,values, 0) || thd->net.report_error)
break; /* purecov: inspected */ break; /* purecov: inspected */
if (check && table_list->check_option->val_int() == 0)
{
if (thd->lex->duplicates == DUP_IGNORE)
{
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
ER_VIEW_CHECK_FAILED, ER(ER_VIEW_CHECK_FAILED));
continue;
}
else
{
my_error(ER_VIEW_CHECK_FAILED, MYF(0));
error=1;
break;
}
}
found++; found++;
if (compare_record(table, query_id)) if (compare_record(table, query_id))
{ {
if ((res= table_list->view_check_option(thd, ignore_err)) !=
VIEW_CHECK_OK)
{
found--;
if (res == VIEW_CHECK_SKIP)
continue;
else if (res == VIEW_CHECK_ERROR)
{
error= 1;
break;
}
}
if (!(error=table->file->update_row((byte*) table->record[1], if (!(error=table->file->update_row((byte*) table->record[1],
(byte*) table->record[0]))) (byte*) table->record[0])))
{ {
...@@ -974,6 +970,7 @@ multi_update::~multi_update() ...@@ -974,6 +970,7 @@ multi_update::~multi_update()
bool multi_update::send_data(List<Item> &not_used_values) bool multi_update::send_data(List<Item> &not_used_values)
{ {
TABLE_LIST *cur_table; TABLE_LIST *cur_table;
bool ignore_err= (thd->lex->duplicates == DUP_IGNORE);
DBUG_ENTER("multi_update::send_data"); DBUG_ENTER("multi_update::send_data");
for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local) for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local)
...@@ -1002,26 +999,19 @@ bool multi_update::send_data(List<Item> &not_used_values) ...@@ -1002,26 +999,19 @@ bool multi_update::send_data(List<Item> &not_used_values)
store_record(table,record[1]); store_record(table,record[1]);
if (fill_record(*fields_for_table[offset], *values_for_table[offset], 0)) if (fill_record(*fields_for_table[offset], *values_for_table[offset], 0))
DBUG_RETURN(1); DBUG_RETURN(1);
if (cur_table->check_option && cur_table->check_option->val_int() == 0)
{
if (thd->lex->duplicates == DUP_IGNORE)
{
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
ER_VIEW_CHECK_FAILED, ER(ER_VIEW_CHECK_FAILED));
continue;
}
else
{
my_error(ER_VIEW_CHECK_FAILED, MYF(0));
DBUG_RETURN(1);
}
}
found++; found++;
if (compare_record(table, thd->query_id)) if (compare_record(table, thd->query_id))
{ {
int error; int error;
if ((error= cur_table->view_check_option(thd, ignore_err)) !=
VIEW_CHECK_OK)
{
found--;
if (error == VIEW_CHECK_SKIP)
continue;
else if (error == VIEW_CHECK_ERROR)
DBUG_RETURN(1);
}
if (!updated++) if (!updated++)
{ {
/* /*
......
...@@ -398,7 +398,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, ...@@ -398,7 +398,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
char path_buff[FN_REFLEN]; char path_buff[FN_REFLEN];
LEX_STRING path; LEX_STRING path;
File_parser *parser; File_parser *parser;
path.str= path_buff; path.str= path_buff;
fn_format(path_buff, file.str, dir.str, 0, MY_UNPACK_FILENAME); fn_format(path_buff, file.str, dir.str, 0, MY_UNPACK_FILENAME);
path.length= strlen(path_buff); path.length= strlen(path_buff);
...@@ -424,7 +424,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, ...@@ -424,7 +424,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
/* /*
read revision number read revision number
TODO: read dependense list, too, to process cascade/restrict TODO: read dependense list, too, to process cascade/restrict
TODO: special cascade/restrict procedure for alter? TODO: special cascade/restrict procedure for alter?
*/ */
...@@ -481,7 +481,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, ...@@ -481,7 +481,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
if (view->with_check != VIEW_CHECK_NONE && if (view->with_check != VIEW_CHECK_NONE &&
!view->updatable_view) !view->updatable_view)
{ {
my_error(ER_VIEW_NONUPD_CHECK, MYF(0)); my_error(ER_VIEW_NONUPD_CHECK, MYF(0), view->db, view->real_name);
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
......
...@@ -1653,6 +1653,40 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds) ...@@ -1653,6 +1653,40 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
} }
/*
check CHECK OPTION condition
SYNOPSIS
check_option()
ignore_failure ignore check option fail
RETURN
VIEW_CHECK_OK OK
VIEW_CHECK_ERROR FAILED
VIEW_CHECK_SKIP FAILED, but continue
*/
int st_table_list::view_check_option(THD *thd, bool ignore_failure)
{
if (check_option && check_option->val_int() == 0)
{
if (ignore_failure)
{
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
ER_VIEW_CHECK_FAILED, ER(ER_VIEW_CHECK_FAILED),
view_db.str, view_name.str);
return(VIEW_CHECK_SKIP);
}
else
{
my_error(ER_VIEW_CHECK_FAILED, MYF(0), view_db.str, view_name.str);
return(VIEW_CHECK_ERROR);
}
}
return(VIEW_CHECK_OK);
}
void Field_iterator_view::set(TABLE_LIST *table) void Field_iterator_view::set(TABLE_LIST *table)
{ {
ptr= table->field_translation; ptr= table->field_translation;
......
...@@ -185,10 +185,16 @@ struct st_table { ...@@ -185,10 +185,16 @@ struct st_table {
#define VIEW_ALGORITHM_TMPTABLE 1 #define VIEW_ALGORITHM_TMPTABLE 1
#define VIEW_ALGORITHM_MERGE 2 #define VIEW_ALGORITHM_MERGE 2
/* view WITH CHECK OPTION parameter options */
#define VIEW_CHECK_NONE 0 #define VIEW_CHECK_NONE 0
#define VIEW_CHECK_LOCAL 1 #define VIEW_CHECK_LOCAL 1
#define VIEW_CHECK_CASCADED 2 #define VIEW_CHECK_CASCADED 2
/* result of view WITH CHECK OPTION parameter check */
#define VIEW_CHECK_OK 0
#define VIEW_CHECK_ERROR 1
#define VIEW_CHECK_SKIP 2
struct st_lex; struct st_lex;
typedef struct st_table_list typedef struct st_table_list
...@@ -264,6 +270,7 @@ typedef struct st_table_list ...@@ -264,6 +270,7 @@ typedef struct st_table_list
void calc_md5(char *buffer); void calc_md5(char *buffer);
void set_ancestor(); void set_ancestor();
int view_check_option(THD *thd, bool ignore_failure);
bool setup_ancestor(THD *thd, Item **conds); bool setup_ancestor(THD *thd, Item **conds);
bool placeholder() {return derived || view; } bool placeholder() {return derived || view; }
void print(THD *thd, String *str); void print(THD *thd, String *str);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment