summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbell@sanja.is.com.ua <>2002-11-27 17:04:43 +0200
committerbell@sanja.is.com.ua <>2002-11-27 17:04:43 +0200
commitf8ff8fc6def43682145ed95ae5429f84918b9ae3 (patch)
treec6a430358bf45d5e1aba691c540dcaafd68f1e3d
parentaa9bfb44f987ed766a37125779cb0addd4c1da3a (diff)
downloadmariadb-git-f8ff8fc6def43682145ed95ae5429f84918b9ae3.tar.gz
after review changes in IN/ALL/ANY/SOME (SCRUM)
-rw-r--r--sql/item.cc52
-rw-r--r--sql/item.h8
-rw-r--r--sql/item_subselect.cc6
-rw-r--r--sql/mysql_priv.h2
-rw-r--r--sql/sql_base.cc23
5 files changed, 69 insertions, 22 deletions
diff --git a/sql/item.cc b/sql/item.cc
index f9e92dfedb2..03ca7ea48b9 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -457,30 +457,52 @@ bool Item_asterisk_remover::fix_fields(THD *thd,
{
DBUG_ENTER("Item_asterisk_remover::fix_fields");
- bool res;
+ bool res= 1;
if (item)
if (item->type() == Item::FIELD_ITEM &&
((Item_field*) item)->field_name[0] == '*')
{
- List<Item> fields;
- fields.push_back(item);
- List_iterator<Item> it(fields);
- it++;
- uint elem=fields.elements;
- if (insert_fields(thd, list, ((Item_field*) item)->db_name,
- ((Item_field*) item)->table_name, &it))
- res= -1;
- else
- if (fields.elements > 1)
+ Item_field *fitem= (Item_field*) item;
+ if (!list->next || fitem->db_name || fitem->table_name)
+ {
+ TABLE_LIST *table= find_table_in_list(thd, list,
+ fitem->db_name,
+ fitem->table_name);
+ if (table)
{
- my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL), MYF(0));
- res= -1;
+ TABLE * tb= table->table;
+ if (find_table_in_list(thd, table->next, fitem->db_name,
+ fitem->table_name) != 0 ||
+ tb->fields == 1)
+ {
+ if ((item= new Item_field(tb->field[0])))
+ {
+ res= 0;
+ tb->field[0]->query_id= thd->query_id;
+ tb->used_keys&= tb->field[0]->part_of_key;
+ tb->used_fields= tb->fields;
+ }
+ else
+ thd->fatal_error= 1; // can't create Item => out of memory
+ }
+ else
+ my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL),
+ MYF(0));
}
- }
+ else
+ if (!fitem->table_name)
+ my_error(ER_NO_TABLES_USED, MYF(0));
+ else
+ my_error(ER_BAD_TABLE_ERROR, MYF(0), fitem->table_name);
+ }
+ else
+ my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL),
+ MYF(0));
+ }
else
res= item->fix_fields(thd, list, &item);
else
- res= -1;
+ thd->fatal_error= 1; // no item given => out of memory
*ref= item;
DBUG_RETURN(res);
}
diff --git a/sql/item.h b/sql/item.h
index 4dde90d0beb..414dcfbc328 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -124,9 +124,9 @@ public:
class Item_outer_select_context_saver :public Item_wrapper
{
public:
- Item_outer_select_context_saver(Item *i)
+ Item_outer_select_context_saver(Item *it)
{
- item= i;
+ item= it;
}
bool fix_fields(THD *, struct st_table_list *, Item ** ref);
};
@@ -137,9 +137,9 @@ public:
class Item_asterisk_remover :public Item_wrapper
{
public:
- Item_asterisk_remover(Item *i)
+ Item_asterisk_remover(Item *it)
{
- item= i;
+ item= it;
}
bool fix_fields(THD *, struct st_table_list *, Item ** ref);
};
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 750fca5a4f8..555b7ae45c3 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -280,13 +280,13 @@ void Item_in_subselect::single_value_transformer(st_select_lex *select_lex,
compare_func_creator func)
{
DBUG_ENTER("Item_in_subselect::single_value_transformer");
- for(SELECT_LEX * sl= select_lex; sl; sl= sl->next_select())
+ for (SELECT_LEX * sl= select_lex; sl; sl= sl->next_select())
{
Item *item;
if (sl->item_list.elements > 1)
{
my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL), MYF(0));
- item= 0; // Item_asterisk_remover mast fail
+ item= 0; // Item_asterisk_remover must fail
}
else
item= (Item*) sl->item_list.pop();
@@ -408,7 +408,7 @@ void subselect_union_engine::fix_length_and_dec()
{
uint32 mlen= 0, len;
Item *sel_item= 0;
- for(SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select())
+ for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select())
{
List_iterator_fast<Item> li(sl->item_list);
Item *s_item= li++;
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 0e3ae0a2af9..242f8601b23 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -578,6 +578,8 @@ bool close_thread_table(THD *thd, TABLE **table_ptr);
void close_thread_tables(THD *thd,bool locked=0);
bool close_thread_table(THD *thd, TABLE **table_ptr);
void close_temporary_tables(THD *thd);
+TABLE_LIST * find_table_in_list(TABLE_LIST *table,
+ const char *db_name, const char *table_name);
TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name);
bool close_temporary_table(THD *thd, const char *db, const char *table_name);
void close_temporary(TABLE *table, bool delete_table=1);
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 09b29c6b41d..8aa33a65ce3 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -743,6 +743,29 @@ void close_temporary_tables(THD *thd)
thd->temporary_tables=0;
}
+/*
+ Find first suitable table in given list.
+
+ SYNOPSIS
+ find_table_in_list()
+ table - pointer to table list
+ db_name - data base name or 0 for any
+ table_name - table name or 0 for any
+
+ RETURN VALUES
+ NULL Table not found
+ # Pointer to found table.
+*/
+
+TABLE_LIST * find_table_in_list(TABLE_LIST *table,
+ const char *db_name, const char *table_name)
+{
+ for (; table; table= table->next)
+ if ((!db_name || !strcmp(table->db, db_name)) &&
+ (!table_name || !strcmp(table->alias, table_name)))
+ break;
+ return table;
+}
TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name)
{