summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2003-01-29 19:22:22 +0200
committerunknown <monty@mashka.mysql.fi>2003-01-29 19:22:22 +0200
commit93ebd4d64d4748bd55834ac76b0b796d075f68b4 (patch)
treec75b9bfc08d3d793d015a4b05b46c723ec15ce0e /sql
parent9c89ce7b3acc40fa9cd739b041611d79d43f55da (diff)
parent3a180c331aa30b393d8cbeff51793ed61592bd75 (diff)
downloadmariadb-git-93ebd4d64d4748bd55834ac76b0b796d075f68b4.tar.gz
merge with 3.23.56 to get patches for --lower-case-table-names and
proper handling of SUM() in some functions. BitKeeper/etc/logging_ok: auto-union sql/item_cmpfunc.cc: Auto merged sql/item_cmpfunc.h: Auto merged sql/item_func.cc: Auto merged sql/item_func.h: Auto merged sql/item_strfunc.cc: Auto merged sql/mysql_priv.h: Auto merged sql/sql_db.cc: Auto merged sql/sql_show.cc: Auto merged sql/table.cc: Auto merged mysql-test/r/group_by.result: merge with 3.23.56 mysql-test/t/group_by.test: merge with 3.23.56 sql/item_strfunc.h: merge with 3.23.56 sql/mysqld.cc: merge with 3.23.56 sql/sql_parse.cc: merge with 3.23.56 sql/sql_yacc.yy: merge with 3.23.56
Diffstat (limited to 'sql')
-rw-r--r--sql/item_cmpfunc.cc43
-rw-r--r--sql/item_cmpfunc.h2
-rw-r--r--sql/item_func.cc11
-rw-r--r--sql/item_func.h1
-rw-r--r--sql/item_strfunc.cc39
-rw-r--r--sql/item_strfunc.h6
-rw-r--r--sql/mysql_priv.h2
-rw-r--r--sql/sql_db.cc2
-rw-r--r--sql/sql_parse.cc24
-rw-r--r--sql/sql_show.cc2
-rw-r--r--sql/table.cc24
11 files changed, 134 insertions, 22 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 2a363164656..55e8ef7c4b5 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -293,6 +293,19 @@ void Item_func_interval::fix_length_and_dec()
}
maybe_null=0; max_length=2;
used_tables_cache|=item->used_tables();
+ with_sum_func= with_sum_func || item->with_sum_func;
+}
+
+void Item_func_interval::split_sum_func(List<Item> &fields)
+{
+ if (item->with_sum_func && item->type() != SUM_FUNC_ITEM)
+ item->split_sum_func(fields);
+ else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
+ {
+ fields.push_front(item);
+ item= new Item_ref((Item**) fields.head_ref(), 0, item->name);
+ }
+ Item_int_func::split_sum_func(fields);
}
/*
@@ -781,17 +794,45 @@ Item_func_case::fix_fields(THD *thd,TABLE_LIST *tables)
{
used_tables_cache|=(first_expr)->used_tables();
const_item_cache&= (first_expr)->const_item();
+ with_sum_func= with_sum_func || (first_expr)->with_sum_func;
}
if (else_expr)
{
used_tables_cache|=(else_expr)->used_tables();
const_item_cache&= (else_expr)->const_item();
+ with_sum_func= with_sum_func || (else_expr)->with_sum_func;
}
if (!else_expr || else_expr->maybe_null)
maybe_null=1; // The result may be NULL
return 0;
}
+void Item_func_case::split_sum_func(List<Item> &fields)
+{
+ if (first_expr)
+ {
+ if (first_expr->with_sum_func && first_expr->type() != SUM_FUNC_ITEM)
+ first_expr->split_sum_func(fields);
+ else if (first_expr->used_tables() || first_expr->type() == SUM_FUNC_ITEM)
+ {
+ fields.push_front(first_expr);
+ first_expr= new Item_ref((Item**) fields.head_ref(), 0,
+ first_expr->name);
+ }
+ }
+ if (else_expr)
+ {
+ if (else_expr->with_sum_func && else_expr->type() != SUM_FUNC_ITEM)
+ else_expr->split_sum_func(fields);
+ else if (else_expr->used_tables() || else_expr->type() == SUM_FUNC_ITEM)
+ {
+ fields.push_front(else_expr);
+ else_expr= new Item_ref((Item**) fields.head_ref(), 0, else_expr->name);
+ }
+ }
+ Item_func::split_sum_func(fields);
+}
+
void Item_func_case::update_used_tables()
{
Item_func::update_used_tables();
@@ -1081,7 +1122,7 @@ void Item_func_in::split_sum_func(List<Item> &fields)
else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
{
fields.push_front(item);
- item=new Item_ref((Item**) fields.head_ref(),0,item->name);
+ item= new Item_ref((Item**) fields.head_ref(), 0, item->name);
}
Item_func::split_sum_func(fields);
}
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index d9068e0e024..aaa15f415e7 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -184,6 +184,7 @@ public:
{
return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
}
+ void split_sum_func(List<Item> &fields);
void fix_length_and_dec();
~Item_func_interval() { delete item; }
const char *func_name() const { return "interval"; }
@@ -273,6 +274,7 @@ public:
const char *func_name() const { return "case"; }
void print(String *str);
bool fix_fields(THD *thd,struct st_table_list *tlist);
+ void split_sum_func(List<Item> &fields);
Item *find_item(String *str);
unsigned int size_of() { return sizeof(*this);}
};
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 02ae03b217f..ef629098d2a 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -971,6 +971,17 @@ longlong Item_func_field::val_int()
return 0;
}
+void Item_func_field::split_sum_func(List<Item> &fields)
+{
+ if (item->with_sum_func && item->type() != SUM_FUNC_ITEM)
+ item->split_sum_func(fields);
+ else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
+ {
+ fields.push_front(item);
+ item= new Item_ref((Item**) fields.head_ref(), 0, item->name);
+ }
+ Item_func::split_sum_func(fields);
+}
longlong Item_func_ascii::val_int()
{
diff --git a/sql/item_func.h b/sql/item_func.h
index be8ae6b57c8..68e5335dc7e 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -585,6 +585,7 @@ public:
{
return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
}
+ void split_sum_func(List<Item> &fields);
void update_used_tables()
{
item->update_used_tables() ; Item_func::update_used_tables();
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 1d058a7d810..f1e37889d5f 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -587,6 +587,17 @@ null:
return 0;
}
+void Item_func_concat_ws::split_sum_func(List<Item> &fields)
+{
+ if (separator->with_sum_func && separator->type() != SUM_FUNC_ITEM)
+ separator->split_sum_func(fields);
+ else if (separator->used_tables() || separator->type() == SUM_FUNC_ITEM)
+ {
+ fields.push_front(separator);
+ separator= new Item_ref((Item**) fields.head_ref(), 0, separator->name);
+ }
+ Item_str_func::split_sum_func(fields);
+}
void Item_func_concat_ws::fix_length_and_dec()
{
@@ -600,6 +611,7 @@ void Item_func_concat_ws::fix_length_and_dec()
}
used_tables_cache|=separator->used_tables();
const_item_cache&=separator->const_item();
+ with_sum_func= with_sum_func || separator->with_sum_func;
}
void Item_func_concat_ws::update_used_tables()
@@ -1501,6 +1513,19 @@ void Item_func_elt::fix_length_and_dec()
}
+void Item_func_elt::split_sum_func(List<Item> &fields)
+{
+ if (item->with_sum_func && item->type() != SUM_FUNC_ITEM)
+ item->split_sum_func(fields);
+ else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
+ {
+ fields.push_front(item);
+ item= new Item_ref((Item**) fields.head_ref(), 0, item->name);
+ }
+ Item_str_func::split_sum_func(fields);
+}
+
+
void Item_func_elt::update_used_tables()
{
Item_func::update_used_tables();
@@ -1547,6 +1572,19 @@ String *Item_func_elt::val_str(String *str)
}
+void Item_func_make_set::split_sum_func(List<Item> &fields)
+{
+ if (item->with_sum_func && item->type() != SUM_FUNC_ITEM)
+ item->split_sum_func(fields);
+ else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
+ {
+ fields.push_front(item);
+ item= new Item_ref((Item**) fields.head_ref(), 0, item->name);
+ }
+ Item_str_func::split_sum_func(fields);
+}
+
+
void Item_func_make_set::fix_length_and_dec()
{
max_length=arg_count-1;
@@ -1554,6 +1592,7 @@ void Item_func_make_set::fix_length_and_dec()
max_length+=args[i]->max_length;
used_tables_cache|=item->used_tables();
const_item_cache&=item->const_item();
+ with_sum_func= with_sum_func || item->with_sum_func;
}
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 181aa8fb6ba..5c9706ed633 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -108,8 +108,8 @@ public:
return (separator->fix_fields(thd,tlist)
|| Item_func::fix_fields(thd,tlist));
}
- const char *func_name() const { return "concat_ws"; }
- unsigned int size_of() { return sizeof(*this);}
+ void split_sum_func(List<Item> &fields);
+ const char *func_name() const { return "concat_ws"; }
};
class Item_func_reverse :public Item_str_func
@@ -368,6 +368,7 @@ public:
{
return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
}
+ void split_sum_func(List<Item> &fields);
void fix_length_and_dec();
void update_used_tables();
const char *func_name() const { return "elt"; }
@@ -388,6 +389,7 @@ public:
{
return (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist));
}
+ void split_sum_func(List<Item> &fields);
void fix_length_and_dec();
void update_used_tables();
const char *func_name() const { return "make_set"; }
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index ae536618e76..2afc4a5754e 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -789,7 +789,7 @@ int create_frm(char *name,uint reclength,uchar *fileinfo,
HA_CREATE_INFO *create_info, uint keys);
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
int rename_file_ext(const char * from,const char * to,const char * ext);
-bool check_db_name(const char *db);
+bool check_db_name(char *db);
bool check_column_name(const char *name);
bool check_table_name(const char *name, uint length);
char *get_field(MEM_ROOT *mem,TABLE *table,uint fieldnr);
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 4cb46c00bed..900c87d83a5 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -351,8 +351,6 @@ bool mysql_change_db(THD *thd,const char *name)
x_free(dbname);
DBUG_RETURN(1);
}
- if (lower_case_table_names)
- casedn_str(dbname);
DBUG_PRINT("info",("Use database: %s", dbname));
if (test_all_bits(thd->master_access,DB_ACLS))
db_access=DB_ACLS;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index df35e41556c..130f3ead5c7 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -828,16 +828,19 @@ int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd)
table_list->real_name = table_list->alias = tbl_name;
table_list->lock_type = TL_READ_NO_INSERT;
table_list->next = 0;
- remove_escape(table_list->real_name);
-
- if (!(table=open_ltable(thd, table_list, TL_READ_NO_INSERT)))
- DBUG_RETURN(1);
if (!db || check_db_name(db))
{
net_printf(&thd->net,ER_WRONG_DB_NAME, db ? db : "NULL");
goto err;
}
+ if (lower_case_table_names)
+ casedn_str(tbl_name);
+ remove_escape(tbl_name);
+
+ if (!(table=open_ltable(thd, table_list, TL_READ_NO_INSERT)))
+ DBUG_RETURN(1);
+
if (check_access(thd, SELECT_ACL, db, &table_list->grant.privilege))
goto err;
if (grant_option && check_grant(thd, SELECT_ACL, table_list))
@@ -1059,6 +1062,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if (!(thd->query=fields=thd->memdup(packet,thd->query_length+1)))
break;
mysql_log.write(thd,command,"%s %s",table_list.real_name,fields);
+ if (lower_case_table_names)
+ casedn_str(table_list.real_name);
remove_escape(table_list.real_name); // This can't have wildcards
if (check_access(thd,SELECT_ACL,table_list.db,&thd->col_access))
@@ -1088,8 +1093,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
net_printf(&thd->net,ER_WRONG_DB_NAME, db ? db : "NULL");
break;
}
- if (lower_case_table_names)
- casedn_str(db);
if (check_access(thd,CREATE_ACL,db,0,1))
break;
mysql_log.write(thd,command,packet);
@@ -1106,8 +1109,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
net_printf(&thd->net,ER_WRONG_DB_NAME, db ? db : "NULL");
break;
}
- if (lower_case_table_names)
- casedn_str(db);
if (check_access(thd,DROP_ACL,db,0,1))
break;
if (thd->locked_tables || thd->active_transaction())
@@ -2277,8 +2278,6 @@ mysql_execute_command(void)
net_printf(&thd->net,ER_WRONG_DB_NAME, lex->name);
break;
}
- if (lower_case_table_names)
- casedn_str(lex->name);
/*
If in a slave thread :
DROP DATABASE DB may not be preceded by USE DB.
@@ -3246,10 +3245,7 @@ TABLE_LIST *add_table_to_list(Table_ident *table, LEX_STRING *alias,
ptr->alias= alias_str;
if (lower_case_table_names)
- {
- casedn_str(ptr->db);
casedn_str(table->table.str);
- }
ptr->real_name=table->table.str;
ptr->real_name_length=table->table.length;
ptr->lock_type= lock_type;
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 50ee78c1ebc..4faee7d248f 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -308,6 +308,8 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
net_store_data(packet,convert, file_name);
table_list.db=(char*) db;
table_list.real_name= table_list.alias= file_name;
+ if (lower_case_table_names)
+ casedn_str(file_name);
if (!(table = open_ltable(thd, &table_list, TL_READ)))
{
for (uint i=0 ; i < field_list.elements ; i++)
diff --git a/sql/table.cc b/sql/table.cc
index 7e284c89871..9eaea728007 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -1100,9 +1100,29 @@ char *get_field(MEM_ROOT *mem, TABLE *table, uint fieldnr)
return to;
}
-bool check_db_name(const char *name)
+
+/*
+ Check if database name is valid
+
+ SYNPOSIS
+ check_db_name()
+ name Name of database
+
+ NOTES
+ If lower_case_table_names is set then database is converted to lower case
+
+ RETURN
+ 0 ok
+ 1 error
+*/
+
+bool check_db_name(char *name)
{
- const char *start=name;
+ char *start=name;
+
+ if (lower_case_table_names)
+ casedn_str(name);
+
while (*name)
{
#if defined(USE_MB) && defined(USE_MB_IDENT)