1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-29 00:08:14 +03:00

Merge with 4.1

This commit is contained in:
monty@mishka.local
2004-12-22 13:54:39 +02:00
395 changed files with 11807 additions and 25533 deletions

View File

@@ -15,7 +15,6 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "mysql_priv.h"
#include "sql_acl.h"
#include "sql_repl.h"
#include "repl_failsafe.h"
#include <m_ctype.h>
@@ -1129,13 +1128,26 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
thd->init_for_queries();
while (fgets(buff, thd->net.max_packet, file))
{
uint length=(uint) strlen(buff);
if (buff[length-1]!='\n' && !feof(file))
{
net_send_error(thd, ER_NET_PACKET_TOO_LARGE, NullS);
thd->fatal_error();
break;
}
ulong length= (ulong) strlen(buff);
while (buff[length-1] != '\n' && !feof(file))
{
/*
We got only a part of the current string. Will try to increase
net buffer then read the rest of the current string.
*/
if (net_realloc(&(thd->net), 2 * thd->net.max_packet))
{
net_send_error(thd, ER_NET_PACKET_TOO_LARGE, NullS);
thd->fatal_error();
break;
}
buff= (char*) thd->net.buff;
fgets(buff + length, thd->net.max_packet - length, file);
length+= (ulong) strlen(buff + length);
}
if (thd->is_fatal_error)
break;
while (length && (my_isspace(thd->charset(), buff[length-1]) ||
buff[length-1] == ';'))
length--;
@@ -2817,7 +2829,9 @@ create_error:
check_access(thd, SELECT_ACL | EXTRA_ACL, first_table->db,
&first_table->grant.privilege, 0, 0))
goto error;
res = mysqld_show_create(thd, first_table);
if (grant_option && check_grant(thd, SELECT_ACL, all_tables, 2, UINT_MAX, 0))
goto error;
res= mysqld_show_create(thd, first_table);
break;
}
#endif
@@ -2945,7 +2959,7 @@ create_error:
if ((res= insert_precheck(thd, all_tables)))
break;
res= mysql_insert(thd, all_tables, lex->field_list, lex->many_values,
select_lex->item_list, lex->value_list,
lex->update_list, lex->value_list,
(lex->value_list.elements ?
DUP_UPDATE : lex->duplicates));
if (first_table->view && !first_table->contain_auto_increment)
@@ -2956,7 +2970,7 @@ create_error:
case SQLCOM_INSERT_SELECT:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if ((res= insert_select_precheck(thd, all_tables)))
if ((res= insert_precheck(thd, all_tables)))
break;
/* Fix lock for first table */
@@ -2969,19 +2983,23 @@ create_error:
select_result *result;
unit->set_limit(select_lex, select_lex);
if (!(res= open_and_lock_tables(thd, all_tables)))
if (!(res= open_and_lock_tables(thd, all_tables)) &&
!(res= mysql_prepare_insert(thd, tables, first_local_table,
tables->table, lex->field_list, 0,
lex->update_list, lex->value_list,
lex->duplicates)))
{
TABLE *table= tables->table;
/* Skip first table, which is the table we are inserting in */
lex->select_lex.table_list.first= (byte*)first_table->next_local;
res= mysql_insert_select_prepare(thd);
if (!res && (result= new select_insert(first_table, first_table->table,
&lex->field_list,
&lex->update_list, &lex->value_list,
lex->duplicates,
lex->duplicates == DUP_IGNORE)))
{
TABLE_LIST *first_select_table;
/*
insert/replace from SELECT give its SELECT_LEX for SELECT,
and item_list belong to SELECT
@@ -2990,6 +3008,7 @@ create_error:
res= handle_select(thd, lex, result);
lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
delete result;
table->insert_values= 0;
}
/* revert changes for SP */
lex->select_lex.table_list.first= (byte*) first_table;
@@ -3355,7 +3374,13 @@ create_error:
}
case SQLCOM_ALTER_DB:
{
if (!strip_sp(lex->name) || check_db_name(lex->name))
char *db= lex->name ? lex->name : thd->db;
if (!db)
{
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
break;
}
if (!strip_sp(db) || check_db_name(db))
{
my_error(ER_WRONG_DB_NAME, MYF(0), lex->name);
break;
@@ -3369,14 +3394,14 @@ create_error:
*/
#ifdef HAVE_REPLICATION
if (thd->slave_thread &&
(!db_ok(lex->name, replicate_do_db, replicate_ignore_db) ||
!db_ok_with_wild_table(lex->name)))
(!db_ok(db, replicate_do_db, replicate_ignore_db) ||
!db_ok_with_wild_table(db)))
{
my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
break;
}
#endif
if (check_access(thd,ALTER_ACL,lex->name,0,1,0))
if (check_access(thd, ALTER_ACL, db, 0, 1, 0))
break;
if (thd->locked_tables || thd->active_transaction())
{
@@ -3384,7 +3409,7 @@ create_error:
ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
goto error;
}
res=mysql_alter_db(thd,lex->name,&lex->create_info);
res= mysql_alter_db(thd, db, &lex->create_info);
break;
}
case SQLCOM_SHOW_CREATE_DB:
@@ -3396,12 +3421,6 @@ create_error:
}
if (check_access(thd,SELECT_ACL,lex->name,0,1,0))
break;
if (thd->locked_tables || thd->active_transaction())
{
my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
goto error;
}
res=mysqld_show_create_db(thd,lex->name,&lex->create_info);
break;
}
@@ -4093,7 +4112,7 @@ error:
/*
Check grants for commands which work only with one table and all other
tables belong to subselects.
tables belonging to subselects or implicitly opened tables.
SYNOPSIS
check_one_table_access()
@@ -4116,7 +4135,7 @@ bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *all_tables)
if (grant_option && check_grant(thd, privilege, all_tables, 0, 1, 0))
return 1;
/* Check rights on tables of subselect (if exists) */
/* Check rights on tables of subselects and implictly opened tables */
TABLE_LIST *subselects_tables;
if ((subselects_tables= all_tables->next_global))
{
@@ -5977,9 +5996,9 @@ Item * all_any_subquery_creator(Item *left_expr,
Item_allany_subselect *it=
new Item_allany_subselect(left_expr, (*cmp)(all), select_lex, all);
if (all)
return it->upper_not= new Item_func_not_all(it); /* ALL */
return it->upper_item= new Item_func_not_all(it); /* ALL */
return it; /* ANY/SOME */
return it->upper_item= new Item_func_nop_all(it); /* ANY/SOME */
}
@@ -6083,6 +6102,9 @@ bool multi_update_precheck(THD *thd, TABLE_LIST *tables)
DBUG_PRINT("info",("Checking sub query list"));
for (table= tables; table; table= table->next_global)
{
if (my_tz_check_n_skip_implicit_tables(&table,
lex->time_zone_tables_used))
continue;
if (!table->table_in_first_from_clause && table->derived)
{
if (check_access(thd, SELECT_ACL, table->db,
@@ -6167,32 +6189,6 @@ bool multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count)
}
/*
INSERT ... SELECT query pre-check
SYNOPSIS
insert_delete_precheck()
thd Thread handler
tables Global table list
RETURN VALUE
FALSE OK
TRUE Error
*/
bool insert_select_precheck(THD *thd, TABLE_LIST *tables)
{
DBUG_ENTER("insert_select_precheck");
/*
Check that we have modify privileges for the first table and
select privileges for the rest
*/
ulong privilege= (thd->lex->duplicates == DUP_REPLACE ?
INSERT_ACL | DELETE_ACL : INSERT_ACL);
DBUG_RETURN(check_one_table_access(thd, privilege, tables));
}
/*
simple UPDATE query pre-check
@@ -6261,6 +6257,10 @@ bool insert_precheck(THD *thd, TABLE_LIST *tables)
LEX *lex= thd->lex;
DBUG_ENTER("insert_precheck");
/*
Check that we have modify privileges for the first table and
select privileges for the rest
*/
ulong privilege= (INSERT_ACL |
(lex->duplicates == DUP_REPLACE ? DELETE_ACL : 0) |
(lex->value_list.elements ? UPDATE_ACL : 0));
@@ -6268,7 +6268,7 @@ bool insert_precheck(THD *thd, TABLE_LIST *tables)
if (check_one_table_access(thd, privilege, tables))
DBUG_RETURN(TRUE);
if (lex->select_lex.item_list.elements != lex->value_list.elements)
if (lex->update_list.elements != lex->value_list.elements)
{
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
DBUG_RETURN(TRUE);