summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/row_test.result11
-rw-r--r--mysql-test/t/row_test.test17
-rw-r--r--sql/item.cc8
-rw-r--r--sql/item.h1
-rw-r--r--sql/item_row.cc2
-rw-r--r--sql/set_var.cc2
-rw-r--r--sql/sql_base.cc8
-rw-r--r--sql/sql_handler.cc2
-rw-r--r--sql/sql_prepare.cc3
-rw-r--r--sql/sql_select.cc7
-rw-r--r--sql/sql_yacc.yy2
11 files changed, 47 insertions, 16 deletions
diff --git a/mysql-test/r/row_test.result b/mysql-test/r/row_test.result
index bd162e35f86..f5bf9856a60 100644
--- a/mysql-test/r/row_test.result
+++ b/mysql-test/r/row_test.result
@@ -35,7 +35,7 @@ SELECT ('test',2,3.33)=('test',2,3.33);
('test',2,3.33)=('test',2,3.33)
1
SELECT ('test',2,3.33)=('test',2,3.33,4);
-Cardinality error (more/less than 4 columns)
+Cardinality error (more/less than 3 columns)
drop table if exists t1;
create table t1 ( a int, b int, c int);
insert into t1 values (1,2,3), (2,3,1), (3,2,1);
@@ -49,3 +49,12 @@ a b c
2 3 1
3 2 1
drop table t1;
+select (1,1);
+Cardinality error (more/less than 1 columns)
+drop table if exists t1;
+create table t1 (i int);
+select 1 from t1 where (1,1);
+Cardinality error (more/less than 1 columns)
+select count(*) from t1 order by (1,1);
+Cardinality error (more/less than 1 columns)
+drop table t1;
diff --git a/mysql-test/t/row_test.test b/mysql-test/t/row_test.test
index 24df2dd1b20..db65e6bd157 100644
--- a/mysql-test/t/row_test.test
+++ b/mysql-test/t/row_test.test
@@ -18,4 +18,19 @@ insert into t1 values (1,2,3), (2,3,1), (3,2,1);
select * from t1 where (1,2,3)=(a,b,c);
select * from t1 where (0,2,3)=(a,b,c);
select * from t1 where (1,2,3)<(a,b,c);
-drop table t1; \ No newline at end of file
+drop table t1;
+
+-- error 1239
+select (1,1);
+drop table if exists t1;
+create table t1 (i int);
+-- error 1239
+select 1 from t1 where (1,1);
+-- error 1239
+select count(*) from t1 order by (1,1);
+#TODO remove comments after parser fixing
+#-- error 1239
+#select count(*) from t1 order by i having (1,1);
+#-- error 1239
+#select 1 from t1 limit (1,1), (1,1);
+drop table t1;
diff --git a/sql/item.cc b/sql/item.cc
index 740ec9418c4..2dd5de0e896 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -63,7 +63,7 @@ bool Item::check_cols(uint c)
{
if (c != 1)
{
- my_error(ER_CARDINALITY_COL, MYF(0), 1);
+ my_error(ER_CARDINALITY_COL, MYF(0), c);
return 1;
}
return 0;
@@ -570,8 +570,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if (!r)
return 1;
int res;
- if ((res= r->fix_fields(thd, tables, ref)))
- return res;
+ if (r->check_cols(1) || r->fix_fields(thd, tables, ref))
+ return 1;
r->depended_from= last;
thd->lex.current_select->mark_as_dependent(last);
thd->add_possible_loop(r);
@@ -606,7 +606,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
(char *)field_name);
if (!*ref)
return 1;
- return (*ref)->fix_fields(thd, tables, ref);
+ return (*ref)->check_cols(1) || (*ref)->fix_fields(thd, tables, ref);
}
fixed= 1;
return 0;
diff --git a/sql/item.h b/sql/item.h
index 766bd7fba41..11b141613f3 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -120,6 +120,7 @@ public:
longlong val_int() { return item->val_int(); }
String* val_str(String* s) { return item->val_str(s); }
void make_field(Send_field* f) { item->make_field(f); }
+ bool check_cols(uint col) { return item->check_cols(col); }
};
diff --git a/sql/item_row.cc b/sql/item_row.cc
index 95da4f5901e..464a8fd0ec5 100644
--- a/sql/item_row.cc
+++ b/sql/item_row.cc
@@ -59,7 +59,7 @@ bool Item_row::check_cols(uint c)
{
if (c != arg_count)
{
- my_error(ER_CARDINALITY_COL, MYF(0), arg_count);
+ my_error(ER_CARDINALITY_COL, MYF(0), c);
return 1;
}
return 0;
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 599c4af06cc..566ca6da860 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -1344,7 +1344,7 @@ int set_var::check(THD *thd)
return 0;
}
- if (value->fix_fields(thd, 0, &value))
+ if (value->check_cols(1) || value->fix_fields(thd, 0, &value))
return -1;
if (var->check_update_type(value->result_type()))
{
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index f8202035d51..8f74903027e 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -2101,7 +2101,8 @@ int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields,
}
else
{
- if (item->fix_fields(thd, tables, it.ref()))
+ if (item->check_cols(1) ||
+ item->fix_fields(thd, tables, it.ref()))
DBUG_RETURN(-1); /* purecov: inspected */
item= *(it.ref()); //Item can be chenged in fix fields
if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM &&
@@ -2255,7 +2256,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
if (*conds)
{
thd->where="where clause";
- if ((*conds)->fix_fields(thd, tables, conds))
+ if ((*conds)->check_cols(1) || (*conds)->fix_fields(thd, tables, conds))
DBUG_RETURN(1);
}
@@ -2266,7 +2267,8 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
{
/* Make a join an a expression */
thd->where="on clause";
- if (table->on_expr->fix_fields(thd, tables, &table->on_expr))
+ if (table->on_expr->check_cols(1) ||
+ table->on_expr->fix_fields(thd, tables, &table->on_expr))
DBUG_RETURN(1);
thd->cond_count++;
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index c43869d9d55..909e1643fe5 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -106,7 +106,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
}
tables->table=table;
- if (cond && cond->fix_fields(thd, tables, &cond))
+ if (cond && (cond->check_cols(1) || cond->fix_fields(thd, tables, &cond)))
return -1;
if (keyname)
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index f86add6c389..7943a3e2254 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -501,7 +501,8 @@ static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables,
{
thd->where="having clause";
thd->allow_sum_func=1;
- if (having->fix_fields(thd, tables, &having) || thd->fatal_error)
+ if (having->check_cols(1) || having->fix_fields(thd, tables, &having)
+ || thd->fatal_error)
DBUG_RETURN(1);
if (having->with_sum_func)
having->split_sum_func(all_fields);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index f560cb7907f..c1f7e8272bc 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -262,7 +262,8 @@ JOIN::prepare(TABLE_LIST *tables_init,
thd->where="having clause";
thd->allow_sum_func=1;
select_lex->having_fix_field= 1;
- bool having_fix_rc= having->fix_fields(thd, tables_list, &having);
+ bool having_fix_rc= (having->check_cols(1) ||
+ having->fix_fields(thd, tables_list, &having));
select_lex->having_fix_field= 0;
if (having_fix_rc || thd->net.report_error)
DBUG_RETURN(-1); /* purecov: inspected */
@@ -6651,7 +6652,9 @@ find_order_in_list(THD *thd,TABLE_LIST *tables,ORDER *order,List<Item> &fields,
return 0;
}
order->in_field_list=0;
- if ((*order->item)->fix_fields(thd, tables, order->item) || thd->fatal_error)
+ Item *it= *order->item;
+ if (it->check_cols(1) || it->fix_fields(thd, tables, order->item) ||
+ thd->fatal_error)
return 1; // Wrong field
all_fields.push_front(*order->item); // Add new field to field list
order->item=(Item**) all_fields.head_ref();
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index cd15fb19dfb..27996acb0f0 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -3416,7 +3416,7 @@ kill:
KILL_SYM expr
{
LEX *lex=Lex;
- if ($2->fix_fields(lex->thd, 0, &$2))
+ if ($2->check_cols(1) || $2->fix_fields(lex->thd, 0, &$2))
{
send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
YYABORT;