summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <dlenev@mockturtle.local>2007-01-24 10:42:57 +0300
committerunknown <dlenev@mockturtle.local>2007-01-24 10:42:57 +0300
commita45938bf5af8b179ac998181ca8699b3403a95e8 (patch)
treefa67bc316c122857781f96764ea450c017cfbc10
parent426c64fdb1e24a4f584d5091e4f9cba81f155a72 (diff)
parent5f544ed03215d8bf3c6050df551717d513b42b66 (diff)
downloadmariadb-git-a45938bf5af8b179ac998181ca8699b3403a95e8.tar.gz
Merge mockturtle.local:/home/dlenev/src/mysql-5.0-bg24491
into mockturtle.local:/home/dlenev/src/mysql-5.1-bg24491 mysql-test/t/sp-error.test: Auto merged sql/item.h: Auto merged sql/sql_table.cc: Auto merged mysql-test/r/ps.result: SCCS merged mysql-test/r/sp-error.result: SCCS merged mysql-test/t/disabled.def: SCCS merged mysql-test/t/ps.test: SCCS merged
-rw-r--r--mysql-test/r/ps.result16
-rw-r--r--mysql-test/r/sp-error.result19
-rw-r--r--mysql-test/t/ps.test31
-rw-r--r--mysql-test/t/sp-error.test32
-rw-r--r--sql/item.h9
5 files changed, 100 insertions, 7 deletions
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index d82b07fa7d3..a99fdb16868 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -1544,6 +1544,22 @@ a
2
DEALLOCATE PREPARE stmt;
DROP TABLE t1,t2;
+drop tables if exists t1;
+create table t1 (id int primary key auto_increment, value varchar(10));
+insert into t1 (id, value) values (1, 'FIRST'), (2, 'SECOND'), (3, 'THIRD');
+prepare stmt from "insert into t1 (id, value) select * from (select 4 as i, 'FOURTH' as v) as y on duplicate key update v = 'DUP'";
+execute stmt;
+ERROR 42S22: Unknown column 'v' in 'field list'
+execute stmt;
+ERROR 42S22: Unknown column 'v' in 'field list'
+deallocate prepare stmt;
+prepare stmt from "insert into t1 (id, value) select * from (select 4 as id, 'FOURTH' as value) as y on duplicate key update y.value = 'DUP'";
+execute stmt;
+ERROR 42S22: Unknown column 'y.value' in 'field list'
+execute stmt;
+ERROR 42S22: Unknown column 'y.value' in 'field list'
+deallocate prepare stmt;
+drop tables t1;
End of 5.0 tests.
create procedure proc_1() reset query cache;
call proc_1();
diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result
index d955b69bde2..0ed92aa9e7a 100644
--- a/mysql-test/r/sp-error.result
+++ b/mysql-test/r/sp-error.result
@@ -1250,6 +1250,25 @@ ERROR HY000: View's SELECT contains a variable or parameter
PREPARE stmt FROM "CREATE VIEW v AS SELECT ?";
ERROR HY000: View's SELECT contains a variable or parameter
DROP TABLE t1;
+drop tables if exists t1;
+drop procedure if exists bug24491;
+create table t1 (id int primary key auto_increment, value varchar(10));
+insert into t1 (id, value) values (1, 'FIRST'), (2, 'SECOND'), (3, 'THIRD');
+create procedure bug24491()
+insert into t1 (id, value) select * from (select 4 as i, 'FOURTH' as v) as y on duplicate key update v = 'DUP';
+call bug24491();
+ERROR 42S22: Unknown column 'v' in 'field list'
+call bug24491();
+ERROR 42S22: Unknown column 'v' in 'field list'
+drop procedure bug24491;
+create procedure bug24491()
+insert into t1 (id, value) select * from (select 4 as id, 'FOURTH' as value) as y on duplicate key update y.value = 'DUP';
+call bug24491();
+ERROR 42S22: Unknown column 'y.value' in 'field list'
+call bug24491();
+ERROR 42S22: Unknown column 'y.value' in 'field list'
+drop procedure bug24491;
+drop tables t1;
End of 5.0 tests
drop function if exists bug16164;
create function bug16164() returns int
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index d65da7f3018..7ba8de85ae8 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -1576,6 +1576,7 @@ execute sq;
deallocate prepare no_index;
deallocate prepare sq;
+
#
# Bug 25027: query with a single-row non-correlated subquery
# and IS NULL predicate
@@ -1599,6 +1600,36 @@ DEALLOCATE PREPARE stmt;
DROP TABLE t1,t2;
+
+#
+# BUG#24491 "using alias from source table in insert ... on duplicate key"
+#
+--disable_warnings
+drop tables if exists t1;
+--enable_warnings
+create table t1 (id int primary key auto_increment, value varchar(10));
+insert into t1 (id, value) values (1, 'FIRST'), (2, 'SECOND'), (3, 'THIRD');
+# Let us prepare INSERT ... SELECT ... ON DUPLICATE KEY UPDATE statement
+# which in its ON DUPLICATE KEY clause erroneously tries to assign value
+# to a column which is mentioned only in SELECT part.
+prepare stmt from "insert into t1 (id, value) select * from (select 4 as i, 'FOURTH' as v) as y on duplicate key update v = 'DUP'";
+# Both first and second attempts to execute it should fail
+--error ER_BAD_FIELD_ERROR
+execute stmt;
+--error ER_BAD_FIELD_ERROR
+execute stmt;
+deallocate prepare stmt;
+# And now the same test for more complex case which is more close
+# to the one that was reported originally.
+prepare stmt from "insert into t1 (id, value) select * from (select 4 as id, 'FOURTH' as value) as y on duplicate key update y.value = 'DUP'";
+--error ER_BAD_FIELD_ERROR
+execute stmt;
+--error ER_BAD_FIELD_ERROR
+execute stmt;
+deallocate prepare stmt;
+drop tables t1;
+
+
--echo End of 5.0 tests.
#
diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
index 456a23123d3..bff3627e194 100644
--- a/mysql-test/t/sp-error.test
+++ b/mysql-test/t/sp-error.test
@@ -1854,6 +1854,38 @@ drop function bug20701;
--echo End of 5.1 tests
#
+# BUG#24491 "using alias from source table in insert ... on duplicate key"
+#
+--disable_warnings
+drop tables if exists t1;
+drop procedure if exists bug24491;
+--enable_warnings
+create table t1 (id int primary key auto_increment, value varchar(10));
+insert into t1 (id, value) values (1, 'FIRST'), (2, 'SECOND'), (3, 'THIRD');
+# Let us create routine with INSERT ... SELECT ... ON DUPLICATE KEY UPDATE
+# statement which in its ON DUPLICATE KEY clause erroneously tries to assign
+# value to a column which is mentioned only in SELECT part.
+create procedure bug24491()
+ insert into t1 (id, value) select * from (select 4 as i, 'FOURTH' as v) as y on duplicate key update v = 'DUP';
+# Both first and second calls to it should fail
+--error ER_BAD_FIELD_ERROR
+call bug24491();
+--error ER_BAD_FIELD_ERROR
+call bug24491();
+drop procedure bug24491;
+# And now the same test for more complex case which is more close
+# to the one that was reported originally.
+create procedure bug24491()
+ insert into t1 (id, value) select * from (select 4 as id, 'FOURTH' as value) as y on duplicate key update y.value = 'DUP';
+--error ER_BAD_FIELD_ERROR
+call bug24491();
+--error ER_BAD_FIELD_ERROR
+call bug24491();
+drop procedure bug24491;
+drop tables t1;
+
+
+#
# BUG#NNNN: New bug synopsis
#
#--disable_warnings
diff --git a/sql/item.h b/sql/item.h
index 8c97010389e..b2e363dce52 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -336,23 +336,18 @@ public:
{
save_table_list= context->table_list;
save_first_name_resolution_table= context->first_name_resolution_table;
- save_next_name_resolution_table= (context->first_name_resolution_table) ?
- context->first_name_resolution_table->
- next_name_resolution_table :
- NULL;
save_resolve_in_select_list= context->resolve_in_select_list;
save_next_local= table_list->next_local;
+ save_next_name_resolution_table= table_list->next_name_resolution_table;
}
/* Restore a name resolution context from saved state. */
void restore_state(Name_resolution_context *context, TABLE_LIST *table_list)
{
table_list->next_local= save_next_local;
+ table_list->next_name_resolution_table= save_next_name_resolution_table;
context->table_list= save_table_list;
context->first_name_resolution_table= save_first_name_resolution_table;
- if (context->first_name_resolution_table)
- context->first_name_resolution_table->
- next_name_resolution_table= save_next_name_resolution_table;
context->resolve_in_select_list= save_resolve_in_select_list;
}
};