mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Merge
This commit is contained in:
226
sql/sql_parse.cc
226
sql/sql_parse.cc
@ -263,8 +263,6 @@ void init_update_queries(void)
|
||||
sql_command_flags[SQLCOM_CREATE_DB]= CF_CHANGES_DATA;
|
||||
sql_command_flags[SQLCOM_DROP_DB]= CF_CHANGES_DATA;
|
||||
sql_command_flags[SQLCOM_RENAME_TABLE]= CF_CHANGES_DATA;
|
||||
sql_command_flags[SQLCOM_BACKUP_TABLE]= CF_CHANGES_DATA;
|
||||
sql_command_flags[SQLCOM_RESTORE_TABLE]= CF_CHANGES_DATA;
|
||||
sql_command_flags[SQLCOM_DROP_INDEX]= CF_CHANGES_DATA;
|
||||
sql_command_flags[SQLCOM_CREATE_VIEW]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE;
|
||||
sql_command_flags[SQLCOM_DROP_VIEW]= CF_CHANGES_DATA;
|
||||
@ -623,72 +621,6 @@ void cleanup_items(Item *item)
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
/**
|
||||
Handle COM_TABLE_DUMP command.
|
||||
|
||||
@param thd thread handle
|
||||
@param db database name or an empty string. If empty,
|
||||
the current database of the connection is used
|
||||
@param tbl_name name of the table to dump
|
||||
|
||||
@note
|
||||
This function is written to handle one specific command only.
|
||||
|
||||
@retval
|
||||
0 success
|
||||
@retval
|
||||
1 error, the error message is set in THD
|
||||
*/
|
||||
|
||||
static
|
||||
int mysql_table_dump(THD *thd, LEX_STRING *db, char *tbl_name)
|
||||
{
|
||||
TABLE* table;
|
||||
TABLE_LIST* table_list;
|
||||
int error = 0;
|
||||
DBUG_ENTER("mysql_table_dump");
|
||||
if (db->length == 0)
|
||||
{
|
||||
db->str= thd->db; /* purecov: inspected */
|
||||
db->length= thd->db_length; /* purecov: inspected */
|
||||
}
|
||||
if (!(table_list = (TABLE_LIST*) thd->calloc(sizeof(TABLE_LIST))))
|
||||
DBUG_RETURN(1); // out of memory
|
||||
table_list->db= db->str;
|
||||
table_list->table_name= table_list->alias= tbl_name;
|
||||
table_list->lock_type= TL_READ_NO_INSERT;
|
||||
table_list->prev_global= &table_list; // can be removed after merge with 4.1
|
||||
|
||||
if (check_db_name(db))
|
||||
{
|
||||
/* purecov: begin inspected */
|
||||
my_error(ER_WRONG_DB_NAME ,MYF(0), db->str ? db->str : "NULL");
|
||||
goto err;
|
||||
/* purecov: end */
|
||||
}
|
||||
if (lower_case_table_names)
|
||||
my_casedn_str(files_charset_info, tbl_name);
|
||||
|
||||
if (!(table=open_ltable(thd, table_list, TL_READ_NO_INSERT, 0)))
|
||||
DBUG_RETURN(1);
|
||||
|
||||
if (check_one_table_access(thd, SELECT_ACL, table_list))
|
||||
goto err;
|
||||
thd->free_list = 0;
|
||||
thd->set_query(tbl_name, (uint) strlen(tbl_name));
|
||||
if ((error = mysqld_dump_create_info(thd, table_list, -1)))
|
||||
{
|
||||
my_error(ER_GET_ERRNO, MYF(0), my_errno);
|
||||
goto err;
|
||||
}
|
||||
net_flush(&thd->net);
|
||||
if ((error= table->file->dump(thd,-1)))
|
||||
my_error(ER_GET_ERRNO, MYF(0), error);
|
||||
|
||||
err:
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
/**
|
||||
Ends the current transaction and (maybe) begin the next.
|
||||
|
||||
@ -1033,40 +965,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case COM_TABLE_DUMP:
|
||||
{
|
||||
char *tbl_name;
|
||||
LEX_STRING db;
|
||||
/* Safe because there is always a trailing \0 at the end of the packet */
|
||||
uint db_len= *(uchar*) packet;
|
||||
if (db_len + 1 > packet_length || db_len > NAME_LEN)
|
||||
{
|
||||
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
|
||||
break;
|
||||
}
|
||||
/* Safe because there is always a trailing \0 at the end of the packet */
|
||||
uint tbl_len= *(uchar*) (packet + db_len + 1);
|
||||
if (db_len + tbl_len + 2 > packet_length || tbl_len > NAME_LEN)
|
||||
{
|
||||
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
|
||||
break;
|
||||
}
|
||||
|
||||
status_var_increment(thd->status_var.com_other);
|
||||
thd->enable_slow_log= opt_log_slow_admin_statements;
|
||||
db.str= (char*) thd->alloc(db_len + tbl_len + 2);
|
||||
if (!db.str)
|
||||
{
|
||||
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
|
||||
break;
|
||||
}
|
||||
db.length= db_len;
|
||||
tbl_name= strmake(db.str, packet + 1, db_len)+1;
|
||||
strmake(tbl_name, packet + db_len + 2, tbl_len);
|
||||
if (mysql_table_dump(thd, &db, tbl_name) == 0)
|
||||
thd->stmt_da->disable_status();
|
||||
break;
|
||||
}
|
||||
case COM_CHANGE_USER:
|
||||
{
|
||||
status_var_increment(thd->status_var.com_other);
|
||||
@ -2349,30 +2247,6 @@ case SQLCOM_PREPARE:
|
||||
}
|
||||
#endif
|
||||
|
||||
case SQLCOM_BACKUP_TABLE:
|
||||
{
|
||||
DBUG_ASSERT(first_table == all_tables && first_table != 0);
|
||||
if (check_table_access(thd, SELECT_ACL, all_tables, FALSE, UINT_MAX, FALSE)
|
||||
|| check_global_access(thd, FILE_ACL))
|
||||
goto error; /* purecov: inspected */
|
||||
thd->enable_slow_log= opt_log_slow_admin_statements;
|
||||
res = mysql_backup_table(thd, first_table);
|
||||
select_lex->table_list.first= (uchar*) first_table;
|
||||
lex->query_tables=all_tables;
|
||||
break;
|
||||
}
|
||||
case SQLCOM_RESTORE_TABLE:
|
||||
{
|
||||
DBUG_ASSERT(first_table == all_tables && first_table != 0);
|
||||
if (check_table_access(thd, INSERT_ACL, all_tables, FALSE, UINT_MAX, FALSE)
|
||||
|| check_global_access(thd, FILE_ACL))
|
||||
goto error; /* purecov: inspected */
|
||||
thd->enable_slow_log= opt_log_slow_admin_statements;
|
||||
res = mysql_restore_table(thd, first_table);
|
||||
select_lex->table_list.first= (uchar*) first_table;
|
||||
lex->query_tables=all_tables;
|
||||
break;
|
||||
}
|
||||
case SQLCOM_ASSIGN_TO_KEYCACHE:
|
||||
{
|
||||
DBUG_ASSERT(first_table == all_tables && first_table != 0);
|
||||
@ -2431,13 +2305,6 @@ case SQLCOM_PREPARE:
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLCOM_LOAD_MASTER_DATA: // sync with master
|
||||
if (check_global_access(thd, SUPER_ACL))
|
||||
goto error;
|
||||
if (end_active_trans(thd))
|
||||
goto error;
|
||||
res = load_master_data(thd);
|
||||
break;
|
||||
#endif /* HAVE_REPLICATION */
|
||||
case SQLCOM_SHOW_ENGINE_STATUS:
|
||||
{
|
||||
@ -2453,35 +2320,6 @@ case SQLCOM_PREPARE:
|
||||
res = ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_MUTEX);
|
||||
break;
|
||||
}
|
||||
#ifdef HAVE_REPLICATION
|
||||
case SQLCOM_LOAD_MASTER_TABLE:
|
||||
{
|
||||
DBUG_ASSERT(first_table == all_tables && first_table != 0);
|
||||
DBUG_ASSERT(first_table->db); /* Must be set in the parser */
|
||||
|
||||
if (check_access(thd, CREATE_ACL, first_table->db,
|
||||
&first_table->grant.privilege, 0, 0,
|
||||
test(first_table->schema_table)))
|
||||
goto error; /* purecov: inspected */
|
||||
/* Check that the first table has CREATE privilege */
|
||||
if (check_grant(thd, CREATE_ACL, all_tables, FALSE, 1, FALSE))
|
||||
goto error;
|
||||
|
||||
pthread_mutex_lock(&LOCK_active_mi);
|
||||
/*
|
||||
fetch_master_table will send the error to the client on failure.
|
||||
Give error if the table already exists.
|
||||
*/
|
||||
if (!fetch_master_table(thd, first_table->db, first_table->table_name,
|
||||
active_mi, 0, 0))
|
||||
{
|
||||
my_ok(thd);
|
||||
}
|
||||
pthread_mutex_unlock(&LOCK_active_mi);
|
||||
break;
|
||||
}
|
||||
#endif /* HAVE_REPLICATION */
|
||||
|
||||
case SQLCOM_CREATE_TABLE:
|
||||
{
|
||||
/* If CREATE TABLE of non-temporary table, do implicit commit */
|
||||
@ -3012,6 +2850,7 @@ end_with_restore_list:
|
||||
if (check_table_access(thd, SELECT_ACL, all_tables,
|
||||
FALSE, UINT_MAX, FALSE))
|
||||
goto error; /* purecov: inspected */
|
||||
|
||||
res = mysql_checksum_table(thd, first_table, &lex->check_opt);
|
||||
break;
|
||||
}
|
||||
@ -3029,7 +2868,7 @@ end_with_restore_list:
|
||||
/*
|
||||
Presumably, REPAIR and binlog writing doesn't require synchronization
|
||||
*/
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
res= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
}
|
||||
select_lex->table_list.first= (uchar*) first_table;
|
||||
lex->query_tables=all_tables;
|
||||
@ -3061,7 +2900,7 @@ end_with_restore_list:
|
||||
/*
|
||||
Presumably, ANALYZE and binlog writing doesn't require synchronization
|
||||
*/
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
res= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
}
|
||||
select_lex->table_list.first= (uchar*) first_table;
|
||||
lex->query_tables=all_tables;
|
||||
@ -3084,7 +2923,7 @@ end_with_restore_list:
|
||||
/*
|
||||
Presumably, OPTIMIZE and binlog writing doesn't require synchronization
|
||||
*/
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
res= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
}
|
||||
select_lex->table_list.first= (uchar*) first_table;
|
||||
lex->query_tables=all_tables;
|
||||
@ -3225,7 +3064,7 @@ end_with_restore_list:
|
||||
if (incident)
|
||||
{
|
||||
Incident_log_event ev(thd, incident);
|
||||
mysql_bin_log.write(&ev);
|
||||
(void) mysql_bin_log.write(&ev); /* error is ignored */
|
||||
mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE);
|
||||
}
|
||||
DBUG_PRINT("debug", ("Just after generate_incident()"));
|
||||
@ -4066,7 +3905,8 @@ end_with_restore_list:
|
||||
*/
|
||||
if (!lex->no_write_to_binlog && write_to_binlog)
|
||||
{
|
||||
write_bin_log(thd, FALSE, thd->query(), thd->query_length());
|
||||
if (res= write_bin_log(thd, FALSE, thd->query(), thd->query_length()))
|
||||
break;
|
||||
}
|
||||
my_ok(thd);
|
||||
}
|
||||
@ -4638,12 +4478,12 @@ create_sp_error:
|
||||
case SP_KEY_NOT_FOUND:
|
||||
if (lex->drop_if_exists)
|
||||
{
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
res= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
|
||||
ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST),
|
||||
SP_COM_STRING(lex), lex->spname->m_name.str);
|
||||
res= FALSE;
|
||||
my_ok(thd);
|
||||
if (!res)
|
||||
my_ok(thd);
|
||||
break;
|
||||
}
|
||||
my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
|
||||
@ -6296,17 +6136,6 @@ bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum_field_types type,
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
|
||||
if (type == MYSQL_TYPE_TIMESTAMP && length)
|
||||
{
|
||||
/* Display widths are no longer supported for TIMSTAMP as of MySQL 4.1.
|
||||
In other words, for declarations such as TIMESTAMP(2), TIMESTAMP(4),
|
||||
and so on, the display width is ignored.
|
||||
*/
|
||||
char buf[32];
|
||||
my_snprintf(buf, sizeof(buf), "TIMESTAMP(%s)", length);
|
||||
WARN_DEPRECATED(thd, "6.0", buf, "'TIMESTAMP'");
|
||||
}
|
||||
|
||||
if (!(new_field= new Create_field()) ||
|
||||
new_field->init(thd, field_name->str, type, length, decimals, type_modifier,
|
||||
default_value, on_update_value, comment, change,
|
||||
@ -6990,7 +6819,6 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
|
||||
{
|
||||
thd->thread_stack= (char*) &tmp_thd;
|
||||
thd->store_globals();
|
||||
lex_start(thd);
|
||||
}
|
||||
|
||||
if (thd)
|
||||
@ -8089,3 +7917,37 @@ bool parse_sql(THD *thd,
|
||||
/**
|
||||
@} (end of group Runtime_Environment)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Check and merge "CHARACTER SET cs [ COLLATE cl ]" clause
|
||||
|
||||
@param cs character set pointer.
|
||||
@param cl collation pointer.
|
||||
|
||||
Check if collation "cl" is applicable to character set "cs".
|
||||
|
||||
If "cl" is NULL (e.g. when COLLATE clause is not specified),
|
||||
then simply "cs" is returned.
|
||||
|
||||
@return Error status.
|
||||
@retval NULL, if "cl" is not applicable to "cs".
|
||||
@retval pointer to merged CHARSET_INFO on success.
|
||||
*/
|
||||
|
||||
|
||||
CHARSET_INFO*
|
||||
merge_charset_and_collation(CHARSET_INFO *cs, CHARSET_INFO *cl)
|
||||
{
|
||||
if (cl)
|
||||
{
|
||||
if (!my_charset_same(cs, cl))
|
||||
{
|
||||
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), cl->name, cs->csname);
|
||||
return NULL;
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
Reference in New Issue
Block a user