Commit 58ec3fd7 authored by unknown's avatar unknown

resolve UPDATE fields belonged to VIEWs as Item_field (instead of Item_ref) in...

resolve UPDATE fields belonged to VIEWs as Item_field (instead of Item_ref) in prepared statements, too (BUG#4999)


mysql-test/r/view.result:
  Test of view updatebility in prepared statement
mysql-test/t/view.test:
  Test of view updatebility in prepared statement
sql/sql_prepare.cc:
  resolve UPDATE fields belonged to VIEWs as Item_field (instead of Item_ref) in prepared statements, too
parent f43fe31e
...@@ -1014,3 +1014,25 @@ p2 ...@@ -1014,3 +1014,25 @@ p2
p4 p4
drop view v1; drop view v1;
drop table t1; drop table t1;
create table t1 (a int);
create view v1 as select a from t1;
insert into t1 values (1);
SET @v0 = '2';
PREPARE stmt FROM 'UPDATE v1 SET a = ?';
EXECUTE stmt USING @v0;
DEALLOCATE PREPARE stmt;
SET @v0 = '3';
PREPARE stmt FROM 'insert into v1 values (?)';
EXECUTE stmt USING @v0;
DEALLOCATE PREPARE stmt;
SET @v0 = '4';
PREPARE stmt FROM 'insert into v1 (a) values (?)';
EXECUTE stmt USING @v0;
DEALLOCATE PREPARE stmt;
select * from t1;
a
2
3
4
drop view v1;
drop table t1;
...@@ -943,3 +943,33 @@ select distinct first.col2 from t1 first where first.col2 in (select second.col2 ...@@ -943,3 +943,33 @@ select distinct first.col2 from t1 first where first.col2 in (select second.col2
select distinct first.col2 from v1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1); select distinct first.col2 from v1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1);
drop view v1; drop view v1;
drop table t1; drop table t1;
#
# Test of view updatebility in prepared statement
#
create table t1 (a int);
create view v1 as select a from t1;
insert into t1 values (1);
#update
SET @v0 = '2';
PREPARE stmt FROM 'UPDATE v1 SET a = ?';
EXECUTE stmt USING @v0;
DEALLOCATE PREPARE stmt;
#insert without field list
SET @v0 = '3';
PREPARE stmt FROM 'insert into v1 values (?)';
EXECUTE stmt USING @v0;
DEALLOCATE PREPARE stmt;
#insert with field list
SET @v0 = '4';
PREPARE stmt FROM 'insert into v1 (a) values (?)';
EXECUTE stmt USING @v0;
DEALLOCATE PREPARE stmt;
select * from t1;
drop view v1;
drop table t1;
...@@ -978,11 +978,19 @@ static int mysql_test_update(Prepared_statement *stmt, ...@@ -978,11 +978,19 @@ static int mysql_test_update(Prepared_statement *stmt,
select->order_list.elements, select->order_list.elements,
(ORDER *) select->order_list.first))) (ORDER *) select->order_list.first)))
{ {
if (setup_fields(thd, 0, table_list, thd->lex->select_lex.no_wrap_view_item= 1;
select->item_list, 1, 0, 0) || if (setup_fields(thd, 0, table_list, select->item_list, 1, 0, 0))
setup_fields(thd, 0, table_list, {
stmt->lex->value_list, 0, 0, 0)) res= -1;
res= -1; thd->lex->select_lex.no_wrap_view_item= 0;
}
else
{
thd->lex->select_lex.no_wrap_view_item= 0;
if (setup_fields(thd, 0, table_list,
stmt->lex->value_list, 0, 0, 0))
res= -1;
}
} }
stmt->lex->unit.cleanup(); stmt->lex->unit.cleanup();
} }
......
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