Merge with alias as String

This commit is contained in:
Michael Widenius 2011-02-28 13:16:17 +02:00
commit 869f5d0e81
42 changed files with 252 additions and 175 deletions

View file

@ -224,6 +224,8 @@ void *_myrealloc(register void *ptr, register size_t size,
struct st_irem *irem;
char *data;
DBUG_ENTER("_myrealloc");
DBUG_PRINT("my",("ptr: 0x%lx size: %lu my_flags: %d", (long) ptr,
(ulong) size, MyFlags));
if (!ptr && (MyFlags & MY_ALLOW_ZERO_PTR))
DBUG_RETURN(_mymalloc(size, filename, lineno, MyFlags));
@ -245,6 +247,8 @@ void *_myrealloc(register void *ptr, register size_t size,
(void) fflush(stderr);
DBUG_RETURN((uchar*) NULL);
}
DBUG_PRINT("my", ("old_size: %lu -> new_size: %lu",
(ulong) irem->datasize, (ulong) size));
if ((data= _mymalloc(size,filename,lineno,MyFlags))) /* Allocate new area */
{

View file

@ -212,7 +212,7 @@ mysql_event_fill_row(THD *thd,
Safety: this can only happen if someone started the server
and then altered mysql.event.
*/
my_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED, MYF(0), table->alias,
my_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED, MYF(0), table->alias.c_ptr(),
(int) ET_FIELD_COUNT, table->s->fields);
DBUG_RETURN(TRUE);
}

View file

@ -100,7 +100,7 @@ Event_worker_thread::print_warnings(THD *thd, Event_job_data *et)
err_msg.append(err->msg, strlen(err->msg), system_charset_info);
DBUG_ASSERT(err->level < 3);
(sql_print_message_handlers[err->level])("%*s", err_msg.length(),
err_msg.c_ptr());
err_msg.c_ptr_safe());
}
DBUG_VOID_RETURN;
}

View file

@ -480,7 +480,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
}
/* If the definer is not set or set to CURRENT_USER, the value of CURRENT_USER
will be written into the binary log as the definer for the SQL thread. */
ret= write_bin_log(thd, TRUE, log_query.c_ptr(), log_query.length());
ret= write_bin_log(thd, TRUE, log_query.ptr(), log_query.length());
}
}
pthread_mutex_unlock(&LOCK_event_metadata);
@ -779,7 +779,7 @@ send_show_create_event(THD *thd, Event_timed *et, Protocol *protocol)
protocol->store(et->name.str, et->name.length, system_charset_info);
protocol->store(sql_mode.str, sql_mode.length, system_charset_info);
protocol->store(tz_name->ptr(), tz_name->length(), system_charset_info);
protocol->store(show_str.c_ptr(), show_str.length(),
protocol->store(show_str.ptr(), show_str.length(),
et->creation_ctx->get_client_cs());
protocol->store(et->creation_ctx->get_client_cs()->csname,
strlen(et->creation_ctx->get_client_cs()->csname),

View file

@ -1536,9 +1536,9 @@ void Field::make_field(Send_field *field)
}
else
field->org_table_name= field->db_name= "";
if (orig_table && orig_table->alias)
if (orig_table && orig_table->alias.ptr())
{
field->table_name= orig_table->alias;
field->table_name= orig_table->alias.ptr();
field->org_col_name= field_name;
}
else

View file

@ -131,7 +131,8 @@ public:
*/
struct st_table *table; // Pointer for table
struct st_table *orig_table; // Pointer to original table
const char **table_name, *field_name;
const char * const *table_name;
const char *field_name;
/** reference to the list of options or NULL */
engine_option_value *option_list;
void *option_struct; /* structure with parsed options */
@ -551,10 +552,14 @@ public:
return (op_result == E_DEC_OVERFLOW);
}
int warn_if_overflow(int op_result);
void set_table_name(String *alias)
{
table_name= &alias->Ptr;
}
void init(TABLE *table_arg)
{
orig_table= table= table_arg;
table_name= &table_arg->alias;
set_table_name(&table_arg->alias);
}
/* maximum possible display length */

View file

@ -1099,7 +1099,8 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
error != HA_ADMIN_ALREADY_DONE &&
error != HA_ADMIN_TRY_ALTER)
{
print_admin_msg(thd, "error", table_share->db.str, table->alias,
print_admin_msg(thd, "error", table_share->db.str,
table->alias.c_ptr(),
opt_op_name[flag],
"Subpartition %s returned error",
sub_elem->partition_name);
@ -1126,7 +1127,8 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
error != HA_ADMIN_ALREADY_DONE &&
error != HA_ADMIN_TRY_ALTER)
{
print_admin_msg(thd, "error", table_share->db.str, table->alias,
print_admin_msg(thd, "error", table_share->db.str,
table->alias.c_ptr(),
opt_op_name[flag], "Partition %s returned error",
part_elem->partition_name);
}

View file

@ -2009,7 +2009,8 @@ int ha_delete_table(THD *thd, handlerton *table_type, const char *path,
dummy_share.db.length= strlen(db);
dummy_share.table_name.str= (char*) alias;
dummy_share.table_name.length= strlen(alias);
dummy_table.alias= alias;
dummy_table.alias.set(alias, dummy_share.table_name.length,
table_alias_charset);
file->change_table_ptr(&dummy_table, &dummy_share);
@ -2855,11 +2856,12 @@ void handler::print_error(int error, myf errflag)
{
const char* engine= table_type();
if (temporary)
my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.ptr(), engine);
my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.c_ptr(),
engine);
else
{
SET_FATAL_ERROR;
my_error(ER_GET_ERRMSG, MYF(0), error, str.ptr(), engine);
my_error(ER_GET_ERRMSG, MYF(0), error, str.c_ptr(), engine);
}
}
else

View file

@ -737,7 +737,8 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
}
if (cs->ctype)
{
uint orig_len= length;
const char *str_start= str;
/*
This will probably need a better implementation in the future:
a function in CHARSET_INFO structure.
@ -747,16 +748,20 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
length--;
str++;
}
if (orig_len != length && !is_autogenerated_name)
if (str != str_start && !is_autogenerated_name)
{
char buff[SAFE_NAME_LEN];
strmake(buff, str_start,
min(sizeof(buff)-1, length + (int) (str-str_start)));
if (length == 0)
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
str + length - orig_len);
buff);
else
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
str + length - orig_len);
buff);
}
}
if (!my_charset_same(cs, system_charset_info))
@ -2495,14 +2500,12 @@ double_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end)
tmp= my_strntod(cs, (char*) cptr, end - cptr, &end, &error);
if (error || (end != org_end && !check_if_only_end_space(cs, end, org_end)))
{
/*
We can use str_value.ptr() here as Item_string is gurantee to put an
end \0 here.
*/
char buff[80];
strmake(buff, cptr, min(sizeof(buff)-1, (size_t) (org_end-cptr)));
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE,
ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
cptr);
buff);
}
return tmp;
}
@ -2511,8 +2514,10 @@ double_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end)
double Item_string::val_real()
{
DBUG_ASSERT(fixed == 1);
return double_from_string_with_check (str_value.charset(), str_value.ptr(),
(char *) str_value.ptr() + str_value.length());
return double_from_string_with_check(str_value.charset(),
str_value.ptr(),
(char *) str_value.ptr() +
str_value.length());
}

View file

@ -5816,7 +5816,7 @@ Item_func_sp::func_name() const
qname.append('.');
}
append_identifier(thd, &qname, m_name->m_name.str, m_name->m_name.length);
return qname.ptr();
return qname.c_ptr_safe();
}
@ -5872,7 +5872,7 @@ Item_func_sp::init_result_field(THD *thd)
*/
share= dummy_table->s;
dummy_table->alias = "";
dummy_table->alias.set("", 0, table_alias_charset);
dummy_table->maybe_null = maybe_null;
dummy_table->in_use= thd;
dummy_table->copy_blobs= TRUE;

View file

@ -1274,8 +1274,13 @@ public:
void make_unique();
double val_real()
{
String *res; res=val_str(&str_value);
return res ? my_atof(res->c_ptr()) : 0.0;
int error;
const char *end;
String *res;
if (!(res= val_str(&str_value)))
return 0.0;
end= res->ptr() + res->length();
return (my_strtod(res->ptr(), (char**) &end, &error));
}
longlong val_int()
{

View file

@ -901,7 +901,7 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
*write_lock_used=table;
if (table->db_stat & HA_READ_ONLY)
{
my_error(ER_OPEN_AS_READONLY,MYF(0),table->alias);
my_error(ER_OPEN_AS_READONLY,MYF(0),table->alias.c_ptr());
/* Clear the lock type of the lock data that are stored already. */
sql_lock->lock_count= (uint) (locks - sql_lock->locks);
reset_lock_data(sql_lock);

View file

@ -1753,7 +1753,7 @@ static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv)
log_query.append("`"))
DBUG_RETURN(1);
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(),
Query_log_event qinfo(thd, log_query.ptr(), log_query.length(),
TRUE, TRUE, errcode);
DBUG_RETURN(mysql_bin_log.write(&qinfo));
}
@ -1777,7 +1777,7 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
log_query.append("`"))
DBUG_RETURN(1);
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(),
Query_log_event qinfo(thd, log_query.ptr(), log_query.length(),
TRUE, TRUE, errcode);
DBUG_RETURN(mysql_bin_log.write(&qinfo));
}

View file

@ -573,7 +573,7 @@ append_query_string(CHARSET_INFO *csinfo,
if (to->reserve(orig_len + from->length()*2+3))
return 1;
beg= to->c_ptr_quick() + to->length();
beg= (char*) to->ptr() + to->length();
ptr= beg;
if (csinfo->escape_with_backslash_is_dangerous)
ptr= str_to_hex(ptr, from->ptr(), from->length());

View file

@ -116,7 +116,7 @@ my_bool my_net_init(NET *net, Vio* vio)
net->vio = vio;
my_net_local_init(net); /* Set some limits */
if (!(net->buff=(uchar*) my_malloc((size_t) net->max_packet+
NET_HEADER_SIZE + COMP_HEADER_SIZE,
NET_HEADER_SIZE + COMP_HEADER_SIZE +1,
MYF(MY_WME))))
DBUG_RETURN(1);
net->buff_end=net->buff+net->max_packet;
@ -590,7 +590,7 @@ net_real_write(NET *net,const uchar *packet, size_t len)
uchar *b;
uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
if (!(b= (uchar*) my_malloc(len + NET_HEADER_SIZE +
COMP_HEADER_SIZE, MYF(MY_WME))))
COMP_HEADER_SIZE + 1, MYF(MY_WME))))
{
net->error= 2;
net->last_errno= ER_OUT_OF_RESOURCES;

View file

@ -11320,7 +11320,8 @@ static void print_sel_tree(PARAM *param, SEL_TREE *tree, key_map *tree_map,
if (!tmp.length())
tmp.append(STRING_WITH_LEN("(empty)"));
DBUG_PRINT("info", ("SEL_TREE: 0x%lx (%s) scans: %s", (long) tree, msg, tmp.ptr()));
DBUG_PRINT("info", ("SEL_TREE: 0x%lx (%s) scans: %s", (long) tree, msg,
tmp.c_ptr()));
DBUG_VOID_RETURN;
}
@ -11343,7 +11344,7 @@ static void print_ror_scans_arr(TABLE *table, const char *msg,
}
if (!tmp.length())
tmp.append(STRING_WITH_LEN("(empty)"));
DBUG_PRINT("info", ("ROR key scans (%s): %s", msg, tmp.ptr()));
DBUG_PRINT("info", ("ROR key scans (%s): %s", msg, tmp.c_ptr()));
DBUG_VOID_RETURN;
}

View file

@ -1778,7 +1778,7 @@ static void mark_as_eliminated(JOIN *join, TABLE_LIST *tbl)
JOIN_TAB *tab= tbl->table->reginfo.join_tab;
if (!(join->const_table_map & tab->table->map))
{
DBUG_PRINT("info", ("Eliminated table %s", table->alias));
DBUG_PRINT("info", ("Eliminated table %s", table->alias.c_ptr()));
tab->type= JT_CONST;
join->eliminated_tables |= table->map;
join->const_table_map|= table->map;
@ -1813,7 +1813,7 @@ void Dep_analysis_context::dbug_print_deps()
fprintf(DBUG_FILE, " equality%ld: %s -> %s.%s\n",
(long)(eq_mod - equality_mods),
str.c_ptr(),
eq_mod->field->table->table->alias,
eq_mod->field->table->table->alias.c_ptr(),
eq_mod->field->field->field_name);
}
else
@ -1831,12 +1831,13 @@ void Dep_analysis_context::dbug_print_deps()
if ((table_dep= table_deps[i]))
{
/* Print table */
fprintf(DBUG_FILE, " table %s\n", table_dep->table->alias);
fprintf(DBUG_FILE, " table %s\n", table_dep->table->alias.c_ptr());
/* Print fields */
for (Dep_value_field *field_dep= table_dep->fields; field_dep;
field_dep= field_dep->next_table_field)
{
fprintf(DBUG_FILE, " field %s.%s ->", table_dep->table->alias,
fprintf(DBUG_FILE, " field %s.%s ->",
table_dep->table->alias.c_ptr(),
field_dep->field->field_name);
uint ofs= field_dep->bitmap_offset;
for (uint bit= ofs; bit < ofs + n_equality_mods; bit++)

View file

@ -632,6 +632,9 @@ bool Protocol::send_fields(List<Item> *list, uint flags)
uint count= 0;
#endif
/* We have to reallocate it here as a stored procedure may have reset it */
(void) local_packet->alloc(thd->variables.net_buffer_length);
while ((item=it++))
{
char *pos;

View file

@ -975,7 +975,7 @@ bool sys_var_str::check(THD *thd, set_var *var)
if ((res=(*check_func)(thd, var)) < 0)
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
name, var->value->str_value.ptr());
name, var->value->str_value.c_ptr());
return res;
}
@ -2266,11 +2266,15 @@ bool sys_var_character_set::check(THD *thd, set_var *var)
}
tmp= NULL;
}
else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
!(tmp=get_old_charset_by_name(res->c_ptr())))
else
{
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
return 1;
const char *name= res->c_ptr_safe();
if (!(tmp=get_charset_by_csname(name,MY_CS_PRIMARY,MYF(0))) &&
!(tmp=get_old_charset_by_name(name)))
{
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), name);
return 1;
}
}
}
else // INT_RESULT
@ -2607,7 +2611,7 @@ static int sys_check_log_path(THD *thd, set_var *var)
if (!(res= var->value->val_str(&str)))
goto err;
log_file_str= res->c_ptr();
log_file_str= res->c_ptr_safe();
bzero(&f_stat, sizeof(MY_STAT));
path_length= unpack_filename(path, log_file_str);
@ -3070,7 +3074,7 @@ bool sys_var_thd_lc_time_names::check(THD *thd, set_var *var)
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
return 1;
}
const char *locale_str= res->c_ptr();
const char *locale_str= res->c_ptr_safe();
if (!(locale_match= my_locale_by_name(locale_str)))
{
my_printf_error(ER_UNKNOWN_ERROR,
@ -4102,7 +4106,7 @@ bool sys_var_thd_optimizer_switch::check(THD *thd, set_var *var)
optimizer_switch_typelib.count,
thd->variables.optimizer_switch,
global_system_variables.optimizer_switch,
res->c_ptr_safe(), res->length(), NULL,
res->ptr(), res->length(), NULL,
&error, &error_len, &not_used);
if (error_len)
{

View file

@ -1104,7 +1104,7 @@ sp_create_routine(THD *thd, int type, sp_head *sp)
(sp->m_explicit_name ? sp->m_db.length : 0),
sp->m_name.str, sp->m_name.length,
sp->m_params.str, sp->m_params.length,
retstr.c_ptr(), retstr.length(),
retstr.ptr(), retstr.length(),
sp->m_body.str, sp->m_body.length,
sp->m_chistics, &(thd->lex->definer->user),
&(thd->lex->definer->host)))
@ -1116,7 +1116,7 @@ sp_create_routine(THD *thd, int type, sp_head *sp)
thd->variables.sql_mode= saved_mode;
/* Such a statement can always go directly to binlog, no trans cache */
if (thd->binlog_query(THD::MYSQL_QUERY_TYPE,
log_query.c_ptr(), log_query.length(),
log_query.ptr(), log_query.length(),
FALSE, FALSE, 0))
ret= SP_INTERNAL_ERROR;
thd->variables.sql_mode= 0;

View file

@ -118,7 +118,7 @@ sp_rcontext::init_var_table(THD *thd)
return TRUE;
m_var_table->copy_blobs= TRUE;
m_var_table->alias= "";
m_var_table->alias.set("", 0, table_alias_charset);
return FALSE;
}

View file

@ -1474,12 +1474,11 @@ void close_temporary_tables(THD *thd)
/* Better add "if exists", in case a RESET MASTER has been done */
const char stub[]= "DROP /*!40005 TEMPORARY */ TABLE IF EXISTS ";
uint stub_len= sizeof(stub) - 1;
char buf[256];
String s_query= String(buf, sizeof(buf), system_charset_info);
char buf[FN_REFLEN];
String s_query(buf, sizeof(buf), system_charset_info);
bool found_user_tables= FALSE;
memcpy(buf, stub, stub_len);
s_query.copy(stub, sizeof(stub)-1, system_charset_info);
/*
Insertion sort of temp tables by pseudo_thread_id to build ordered list
@ -1533,19 +1532,25 @@ void close_temporary_tables(THD *thd)
{
bool save_thread_specific_used= thd->thread_specific_used;
my_thread_id save_pseudo_thread_id= thd->variables.pseudo_thread_id;
char db_buf[FN_REFLEN];
String db(db_buf, sizeof(db_buf), system_charset_info);
/* Set pseudo_thread_id to be that of the processed table */
thd->variables.pseudo_thread_id= tmpkeyval(thd, table);
String db;
db.append(table->s->db.str);
db.copy(table->s->db.str, table->s->db.length, system_charset_info);
/* Reset s_query() if changed by previous loop */
s_query.length(sizeof(stub)-1);
/* Loop forward through all tables that belong to a common database
within the sublist of common pseudo_thread_id to create single
DROP query
*/
for (s_query.length(stub_len);
for (;
table && is_user_table(table) &&
tmpkeyval(thd, table) == thd->variables.pseudo_thread_id &&
table->s->db.length == db.length() &&
strcmp(table->s->db.str, db.ptr()) == 0;
memcmp(table->s->db.str, db.ptr(), db.length()) == 0;
table= next)
{
/*
@ -1849,7 +1854,7 @@ int drop_temporary_table(THD *thd, TABLE_LIST *table_list)
/* Table might be in use by some outer statement. */
if (table->query_id && table->query_id != thd->query_id)
{
my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias);
my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias.c_ptr());
DBUG_RETURN(-1);
}
@ -1872,7 +1877,7 @@ void close_temporary_table(THD *thd, TABLE *table,
DBUG_ENTER("close_temporary_table");
DBUG_PRINT("tmptable", ("closing table: '%s'.'%s' 0x%lx alias: '%s'",
table->s->db.str, table->s->table_name.str,
(long) table, table->alias));
(long) table, table->alias.c_ptr()));
/*
When closing a MERGE parent or child table, detach the children
@ -2606,7 +2611,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
("query_id: %lu server_id: %u pseudo_thread_id: %lu",
(ulong) table->query_id, (uint) thd->server_id,
(ulong) thd->variables.pseudo_thread_id));
my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias);
my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias.c_ptr());
DBUG_RETURN(0);
}
table->query_id= thd->query_id;
@ -2643,7 +2648,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
When looking for a usable TABLE, ignore MERGE children, as they
belong to their parent and cannot be used explicitly.
*/
if (!my_strcasecmp(system_charset_info, table->alias, alias) &&
if (!my_strcasecmp(system_charset_info, table->alias.c_ptr(), alias) &&
table->query_id != thd->query_id && /* skip tables already used */
!(thd->prelocked_mode && table->query_id) &&
!table->parent)
@ -2999,13 +3004,9 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table->alias_name_used= my_strcasecmp(table_alias_charset,
table->s->table_name.str, alias);
/* Fix alias if table name changes */
if (strcmp(table->alias, alias))
{
uint length=(uint) strlen(alias)+1;
table->alias= (char*) my_realloc((char*) table->alias, length,
MYF(MY_WME));
memcpy((char*) table->alias, alias, length);
}
if (strcmp(table->alias.c_ptr(), alias))
table->alias.copy(alias, strlen(alias), table->alias.charset());
/* These variables are also set in reopen_table() */
table->tablenr=thd->current_tablenr++;
table->used_fields=0;
@ -3089,7 +3090,7 @@ bool reopen_table(TABLE *table)
#ifdef EXTRA_DEBUG
if (table->db_stat)
sql_print_error("Table %s had a open data handler in reopen_table",
table->alias);
table->alias.c_ptr());
#endif
bzero((char*) &table_list, sizeof(TABLE_LIST));
table_list.db= table->s->db.str;
@ -3100,7 +3101,7 @@ bool reopen_table(TABLE *table)
DBUG_RETURN(1); // Thread was killed
if (open_unireg_entry(thd, &tmp, &table_list,
table->alias,
table->alias.c_ptr(),
table->s->table_cache_key.str,
table->s->table_cache_key.length,
thd->mem_root, 0))
@ -3139,14 +3140,14 @@ bool reopen_table(TABLE *table)
VOID(closefrm(table, 1)); // close file, free everything
*table= tmp;
table->alias.move(tmp.alias);
table->default_column_bitmaps();
table->file->change_table_ptr(table, table->s);
DBUG_ASSERT(table->alias != 0);
DBUG_ASSERT(table->alias.ptr() != 0);
for (field=table->field ; *field ; field++)
{
(*field)->table= (*field)->orig_table= table;
(*field)->table_name= &table->alias;
(*field)->init(table);
}
for (key=0 ; key < table->s->keys ; key++)
{
@ -3273,7 +3274,7 @@ static bool reattach_merge(THD *thd, TABLE **err_tables_p)
DBUG_PRINT("tcache", ("MERGE parent, attach children"));
if(table->file->extra(HA_EXTRA_ATTACH_CHILDREN))
{
my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias);
my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias.c_ptr());
error= TRUE;
/* Remove table from open_tables. */
*prv_p= next;
@ -3366,7 +3367,8 @@ bool reopen_tables(THD *thd, bool get_locks, bool mark_share_as_old)
if (!tables || (!db_stat && reopen_table(table)))
{
my_error(ER_CANT_REOPEN_TABLE, MYF(0),
table->alias ? table->alias : table->s->table_name.str);
table->alias.ptr() ? table->alias.c_ptr() :
table->s->table_name.str);
/*
If we could not allocate 'tables', we may close open tables
here. If a MERGE table is affected, detach the children first.
@ -3563,7 +3565,8 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock)
char *key= table->s->table_cache_key.str;
uint key_length= table->s->table_cache_key.length;
DBUG_PRINT("loop", ("table_name: %s", table->alias ? table->alias : ""));
DBUG_PRINT("loop", ("table_name: %s",
table->alias.ptr() ? table->alias.c_ptr() : ""));
HASH_SEARCH_STATE state;
for (TABLE *search= (TABLE*) hash_first(&open_cache, (uchar*) key,
key_length, &state);
@ -4357,7 +4360,7 @@ void detach_merge_children(TABLE *table, bool clear_refs)
Set alias to "" to ensure that table is not used if we are in
LOCK TABLES
*/
((char*) child_l->table->alias)[0]= 0;
child_l->table->alias.length(0);
/* Clear the table reference to force new assignment at next open. */
child_l->table= NULL;
@ -4910,7 +4913,7 @@ static bool check_lock_and_start_stmt(THD *thd, TABLE *table,
if ((int) lock_type >= (int) TL_WRITE_ALLOW_READ &&
(int) table->reginfo.lock_type < (int) TL_WRITE_ALLOW_READ)
{
my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->alias);
my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->alias.c_ptr());
DBUG_RETURN(1);
}
if ((error=table->file->start_stmt(thd, lock_type)))
@ -6022,7 +6025,8 @@ find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
Field **field_ptr, *field;
uint cached_field_index= *cached_field_index_ptr;
DBUG_ENTER("find_field_in_table");
DBUG_PRINT("enter", ("table: '%s', field name: '%s'", table->alias, name));
DBUG_PRINT("enter", ("table: '%s', field name: '%s'", table->alias.c_ptr(),
name));
/* We assume here that table->field < NO_CACHED_FIELD_INDEX = UINT_MAX */
if (cached_field_index < table->s->fields &&

View file

@ -4069,8 +4069,8 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
int errcode)
{
DBUG_ENTER("THD::binlog_query");
DBUG_PRINT("enter", ("qtype: %s query: '%s'",
show_query_type(qtype), query_arg));
DBUG_PRINT("enter", ("qtype: %s query: '%-.*s'",
show_query_type(qtype), (int) query_len, query_arg));
DBUG_ASSERT(query_arg && mysql_bin_log.is_open());
/*
@ -4106,7 +4106,7 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
{
sql_print_warning("%s Statement: %.*s",
ER(ER_BINLOG_UNSAFE_STATEMENT),
MYSQL_ERRMSG_SIZE, query_arg);
(int) min(MYSQL_ERRMSG_SIZE, query_len), query_arg);
binlog_flags|= BINLOG_FLAG_UNSAFE_STMT_PRINTED;
}
}

View file

@ -2072,6 +2072,7 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd)
TABLE *copy;
TABLE_SHARE *share;
uchar *bitmap;
char *copy_tmp;
DBUG_ENTER("Delayed_insert::get_local_table");
/* First request insert thread to get a lock */
@ -2104,14 +2105,15 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd)
the other record buffers and alignment are unnecessary.
*/
thd_proc_info(client_thd, "allocating local table");
copy= (TABLE*) client_thd->alloc(sizeof(*copy)+
(share->fields+1)*sizeof(Field**)+
share->reclength +
share->column_bitmap_size*3);
if (!copy)
copy_tmp= (char*) client_thd->alloc(sizeof(*copy)+
(share->fields+1)*sizeof(Field**)+
share->reclength +
share->column_bitmap_size*3);
if (!copy_tmp)
goto error;
/* Copy the TABLE object. */
copy= new (copy_tmp) TABLE;
*copy= *table;
/* We don't need to change the file handler here */
/* Assign the pointers for the field pointers array and the record. */
@ -3500,7 +3502,7 @@ int select_create::write_to_binlog(bool is_trans, int errcode)
Avoid to use thd->binlog_query() twice, otherwise it will print the unsafe
warning twice.
*/
Query_log_event ev(thd, query.c_ptr_safe(), query.length(), is_trans,
Query_log_event ev(thd, query.ptr(), query.length(), is_trans,
FALSE, errcode);
return mysql_bin_log.write(&ev);
}

View file

@ -604,11 +604,15 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
size_t pl= 0;
List<Item> fv;
Item *item, *val;
String pfield, pfields;
int n;
const char *tbl= table_name_arg;
const char *tdb= (thd->db != NULL ? thd->db : db_arg);
String string_buf;
char name_buffer[SAFE_NAME_LEN*2];
char command_buffer[1024];
String string_buf(name_buffer, sizeof(name_buffer),
system_charset_info);
String pfields(command_buffer, sizeof(command_buffer),
system_charset_info);
if (!thd->db || strcmp(db_arg, thd->db))
{
@ -617,7 +621,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
prefix table name with database name so that it
becomes a FQ name.
*/
string_buf.set_charset(system_charset_info);
string_buf.length(0);
string_buf.append(db_arg);
string_buf.append("`");
string_buf.append(".");
@ -638,6 +642,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
/*
prepare fields-list and SET if needed; print_query won't do that for us.
*/
pfields.length(0);
if (!thd->lex->field_list.is_empty())
{
List_iterator<Item> li(thd->lex->field_list);
@ -682,8 +687,8 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
}
}
p= pfields.c_ptr_safe();
pl= strlen(p);
p= pfields.c_ptr_safe();
pl= pfields.length();
if (!(load_data_query= (char *)thd->alloc(lle.get_query_buffer_length() + 1 + pl)))
return TRUE;

View file

@ -5104,9 +5104,8 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
String str(buff,(uint32) sizeof(buff), system_charset_info);
str.length(0);
thd->lex->unit.print(&str, QT_ORDINARY);
str.append('\0');
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_YES, str.ptr());
ER_YES, str.c_ptr_safe());
}
if (res)
result->abort();

View file

@ -303,7 +303,7 @@ static const char *item_val_str(struct st_mysql_value *value,
Lets be nice and create a temporary string since the
buffer was too small
*/
return current_thd->strmake(res->c_ptr_quick(), res->length());
return current_thd->strmake(res->ptr(), res->length());
}

View file

@ -6157,9 +6157,10 @@ static void add_not_null_conds(JOIN *join)
*/
if (notnull->fix_fields(join->thd, &notnull))
DBUG_VOID_RETURN;
DBUG_EXECUTE("where",print_where(notnull,
referred_tab->table->alias,
QT_ORDINARY););
DBUG_EXECUTE("where",
print_where(notnull,
referred_tab->table->alias.c_ptr(),
QT_ORDINARY););
add_cond_and_fix(&referred_tab->select_cond, notnull);
}
}
@ -6418,7 +6419,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
}
if (tmp || !cond || tab->type == JT_REF)
{
DBUG_EXECUTE("where",print_where(tmp,tab->table->alias, QT_ORDINARY););
DBUG_EXECUTE("where",
print_where(tmp,tab->table->alias.c_ptr(),
QT_ORDINARY););
SQL_SELECT *sel= tab->select= ((SQL_SELECT*)
thd->memdup((uchar*) select,
sizeof(*select)));
@ -6458,7 +6461,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
tab->select_cond= sel->cond= NULL;
sel->head=tab->table;
DBUG_EXECUTE("where",print_where(tmp,tab->table->alias, QT_ORDINARY););
DBUG_EXECUTE("where",
print_where(tmp,tab->table->alias.c_ptr(),
QT_ORDINARY););
if (tab->quick)
{
/* Use quick key read if it's a constant and it's not used
@ -10178,7 +10183,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
thd->mem_root= &table->mem_root;
table->field=reg_field;
table->alias= table_alias;
table->alias.set(table_alias, strlen(table_alias), table_alias_charset);
table->reginfo.lock_type=TL_WRITE; /* Will be updated */
table->db_stat=HA_OPEN_KEYFILE+HA_OPEN_RNDFILE;
table->map=1;
@ -10544,7 +10550,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
null_count=(null_count+7) & ~7; // move to next byte
// fix table name in field entry
field->table_name= &table->alias;
field->set_table_name(&table->alias);
}
param->copy_field_end=copy;
@ -11268,7 +11274,7 @@ free_tmp_table(THD *thd, TABLE *entry)
MEM_ROOT own_root= entry->mem_root;
const char *save_proc_info;
DBUG_ENTER("free_tmp_table");
DBUG_PRINT("enter",("table: %s",entry->alias));
DBUG_PRINT("enter",("table: %s",entry->alias.c_ptr()));
save_proc_info=thd->proc_info;
thd_proc_info(thd, "removing tmp table");
@ -16026,6 +16032,7 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
char buff[256];
String str(buff,sizeof(buff),&my_charset_bin);
str.length(0);
str.extra_allocation(1024);
item->print(&str, QT_ORDINARY);
item_field->name= sql_strmake(str.ptr(),str.length());
}

View file

@ -816,7 +816,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
protocol->store(table_list->schema_table->table_name,
system_charset_info);
else
protocol->store(table_list->table->alias, system_charset_info);
protocol->store(table_list->table->alias.c_ptr(), system_charset_info);
}
if (table_list->view)
@ -1305,7 +1305,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
else
{
if (lower_case_table_names == 2)
alias= table->alias;
alias= table->alias.c_ptr();
else
{
alias= share->table_name.str;
@ -5661,7 +5661,7 @@ copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table)
if (et.load_from_row(thd, event_table))
{
my_error(ER_CANNOT_LOAD_FROM_TABLE, MYF(0), event_table->alias);
my_error(ER_CANNOT_LOAD_FROM_TABLE, MYF(0), event_table->alias.c_ptr());
DBUG_RETURN(1);
}

View file

@ -411,7 +411,7 @@ bool String::append(const String &s)
{
if (s.length())
{
if (realloc(str_length+s.length()))
if (realloc_with_extra_if_needed(str_length+s.length()))
return TRUE;
memcpy(Ptr+str_length,s.ptr(),s.length());
str_length+=s.length();
@ -436,7 +436,7 @@ bool String::append(const char *s,uint32 arg_length)
{
uint32 add_length=arg_length * str_charset->mbmaxlen;
uint dummy_errors;
if (realloc(str_length+ add_length))
if (realloc_with_extra_if_needed(str_length+ add_length))
return TRUE;
str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
s, arg_length, &my_charset_latin1,
@ -447,7 +447,7 @@ bool String::append(const char *s,uint32 arg_length)
/*
For an ASCII compatinble string we can just append.
*/
if (realloc(str_length+arg_length))
if (realloc_with_extra_if_needed(str_length+arg_length))
return TRUE;
memcpy(Ptr+str_length,s,arg_length);
str_length+=arg_length;
@ -478,14 +478,14 @@ bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs)
{
uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen;
uint dummy_errors;
if (realloc(str_length + add_length))
if (realloc_with_extra_if_needed(str_length + add_length))
return TRUE;
str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset,
s, arg_length, cs, &dummy_errors);
}
else
{
if (realloc(str_length + arg_length))
if (realloc_with_extra_if_needed(str_length + arg_length))
return TRUE;
memcpy(Ptr + str_length, s, arg_length);
str_length+= arg_length;
@ -497,7 +497,7 @@ bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs)
#ifdef TO_BE_REMOVED
bool String::append(FILE* file, uint32 arg_length, myf my_flags)
{
if (realloc(str_length+arg_length))
if (realloc_with_extra_if_needed(str_length+arg_length))
return TRUE;
if (my_fread(file, (uchar*) Ptr + str_length, arg_length, my_flags))
{
@ -511,7 +511,7 @@ bool String::append(FILE* file, uint32 arg_length, myf my_flags)
bool String::append(IO_CACHE* file, uint32 arg_length)
{
if (realloc(str_length+arg_length))
if (realloc_with_extra_if_needed(str_length+arg_length))
return TRUE;
if (my_b_read(file, (uchar*) Ptr + str_length, arg_length))
{
@ -527,7 +527,7 @@ bool String::append_with_prefill(const char *s,uint32 arg_length,
{
int t_length= arg_length > full_length ? arg_length : full_length;
if (realloc(str_length + t_length))
if (realloc_with_extra_if_needed(str_length + t_length))
return TRUE;
t_length= full_length - arg_length;
if (t_length > 0)
@ -636,7 +636,7 @@ bool String::replace(uint32 offset,uint32 arg_length,
{
if (diff)
{
if (realloc(str_length+(uint32) diff))
if (realloc_with_extra_if_needed(str_length+(uint32) diff))
return TRUE;
bmove_upp((uchar*) Ptr+str_length+diff, (uchar*) Ptr+str_length,
str_length-offset-arg_length);

View file

@ -53,23 +53,24 @@ uint convert_to_printable(char *to, size_t to_len,
class String
{
char *Ptr;
uint32 str_length,Alloced_length;
uint32 str_length,Alloced_length, extra_alloc;
bool alloced;
CHARSET_INFO *str_charset;
public:
String()
{
Ptr=0; str_length=Alloced_length=0; alloced=0;
Ptr=0; str_length=Alloced_length=extra_alloc=0; alloced=0;
str_charset= &my_charset_bin;
}
String(uint32 length_arg)
{
alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
alloced=0; Alloced_length= extra_alloc= 0; (void) real_alloc(length_arg);
str_charset= &my_charset_bin;
}
String(const char *str, CHARSET_INFO *cs)
{
Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;
Ptr=(char*) str; str_length= (uint32) strlen(str);
Alloced_length= extra_alloc= 0; alloced=0;
str_charset=cs;
}
/*
@ -79,18 +80,18 @@ public:
*/
String(const char *str,uint32 len, CHARSET_INFO *cs)
{
Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
Ptr=(char*) str; str_length=len; Alloced_length= extra_alloc=0; alloced=0;
str_charset=cs;
}
String(char *str,uint32 len, CHARSET_INFO *cs)
{
Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
Ptr=(char*) str; Alloced_length=str_length=len; extra_alloc= 0; alloced=0;
str_charset=cs;
}
String(const String &str)
{
Ptr=str.Ptr ; str_length=str.str_length ;
Alloced_length=str.Alloced_length; alloced=0;
Alloced_length=str.Alloced_length; extra_alloc= 0; alloced=0;
str_charset=str.str_charset;
}
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
@ -110,8 +111,10 @@ public:
inline CHARSET_INFO *charset() const { return str_charset; }
inline uint32 length() const { return str_length;}
inline uint32 alloced_length() const { return Alloced_length;}
inline uint32 extra_allocation() const { return extra_alloc;}
inline char& operator [] (uint32 i) const { return Ptr[i]; }
inline void length(uint32 len) { str_length=len ; }
inline void extra_allocation(uint32 len) { extra_alloc= len; }
inline bool is_empty() const { return (str_length == 0); }
inline void mark_as_const() { Alloced_length= 0;}
inline const char *ptr() const { return Ptr; }
@ -140,23 +143,21 @@ public:
{
DBUG_ASSERT(&str != this);
free();
Ptr=(char*) str.ptr()+offset; str_length=arg_length; alloced=0;
Ptr=(char*) str.ptr()+offset; str_length=arg_length;
if (str.Alloced_length)
Alloced_length=str.Alloced_length-offset;
else
Alloced_length=0;
str_charset=str.str_charset;
}
inline void set(char *str,uint32 arg_length, CHARSET_INFO *cs)
{
free();
Ptr=(char*) str; str_length=Alloced_length=arg_length ; alloced=0;
Ptr=(char*) str; str_length=Alloced_length=arg_length;
str_charset=cs;
}
inline void set(const char *str,uint32 arg_length, CHARSET_INFO *cs)
{
free();
Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0;
Ptr=(char*) str; str_length=arg_length;
str_charset=cs;
}
bool set_ascii(const char *str, uint32 arg_length);
@ -207,11 +208,11 @@ public:
if (alloced)
{
alloced=0;
Alloced_length=0;
my_free(Ptr,MYF(0));
Ptr=0;
str_length=0; /* Safety */
}
Alloced_length= extra_alloc= 0;
Ptr=0;
str_length=0; /* Safety */
}
inline bool alloc(uint32 arg_length)
{
@ -221,9 +222,21 @@ public:
}
bool real_alloc(uint32 arg_length); // Empties old string
bool realloc(uint32 arg_length);
inline void shrink(uint32 arg_length) // Shrink buffer
bool realloc_with_extra(uint32 arg_length)
{
if (extra_alloc < 4096)
extra_alloc= extra_alloc*2+128;
return realloc(arg_length + extra_alloc);
}
bool realloc_with_extra_if_needed(uint32 arg_length)
{
if (arg_length < Alloced_length)
return 0;
return realloc_with_extra(arg_length);
}
inline void shrink(uint32 arg_length) // Shrink buffer
{
if (ALIGN_SIZE(arg_length+1) < Alloced_length)
{
char *new_ptr;
if (!(new_ptr=(char*) my_realloc(Ptr,arg_length,MYF(0))))
@ -250,7 +263,6 @@ public:
DBUG_ASSERT(!s.uses_buffer_owned_by(this));
free();
Ptr=s.Ptr ; str_length=s.str_length ; Alloced_length=s.Alloced_length;
alloced=0;
}
return *this;
}
@ -266,6 +278,14 @@ public:
bool set_or_copy_aligned(const char *s, uint32 arg_length, CHARSET_INFO *cs);
bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom,
CHARSET_INFO *csto, uint *errors);
void move(String &s)
{
free();
Ptr=s.Ptr ; str_length=s.str_length ; Alloced_length=s.Alloced_length;
extra_alloc= s.extra_alloc;
alloced= s.alloced;
s.alloced= 0;
}
bool append(const String &s);
bool append(const char *s);
bool append(const char *s,uint32 arg_length);
@ -285,7 +305,7 @@ public:
}
else
{
if (realloc(str_length+1))
if (realloc_with_extra(str_length + 1))
return 1;
Ptr[str_length++]=chr;
}
@ -296,6 +316,7 @@ public:
friend int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
friend int stringcmp(const String *a,const String *b);
friend String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
friend class Field;
uint32 numchars();
int charpos(int i,uint32 offset=0);

View file

@ -2113,7 +2113,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
{
if (!foreign_key_error)
my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0),
wrong_tables.c_ptr());
wrong_tables.c_ptr_safe());
else
my_message(ER_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED), MYF(0));
error= 1;
@ -6955,7 +6955,7 @@ view_err:
error= 0;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
table->alias);
table->alias.c_ptr());
}
VOID(pthread_mutex_lock(&LOCK_open));
@ -7023,7 +7023,7 @@ view_err:
error= 0;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
table->alias);
table->alias.c_ptr());
}
if (!error)

View file

@ -57,14 +57,15 @@ print_where(COND *cond,const char *info, enum_query_type query_type)
{
if (cond)
{
char buff[256];
char buff[1024];
String str(buff,(uint32) sizeof(buff), system_charset_info);
str.length(0);
str.extra_allocation(1024);
cond->print(&str, query_type);
str.append('\0');
DBUG_LOCK_FILE;
(void) fprintf(DBUG_FILE,"\nWHERE:(%s) ",info);
(void) fputs(str.ptr(),DBUG_FILE);
(void) fputs(str.c_ptr_safe(),DBUG_FILE);
(void) fputc('\n',DBUG_FILE);
DBUG_UNLOCK_FILE;
}
@ -156,7 +157,7 @@ void TEST_filesort(SORT_FIELD *sortorder,uint s_length)
out.append('\0'); // Purify doesn't like c_ptr()
DBUG_LOCK_FILE;
VOID(fputs("\nInfo about FILESORT\n",DBUG_FILE));
fprintf(DBUG_FILE,"Sortorder: %s\n",out.ptr());
fprintf(DBUG_FILE,"Sortorder: %s\n",out.c_ptr_safe());
DBUG_UNLOCK_FILE;
DBUG_VOID_RETURN;
}
@ -191,7 +192,7 @@ TEST_join(JOIN *join)
TABLE *form=tab->table;
char key_map_buff[128];
fprintf(DBUG_FILE,"%-16.16s type: %-7s q_keys: %s refs: %d key: %d len: %d\n",
form->alias,
form->alias.c_ptr(),
join_type_str[tab->type],
tab->keys.print(key_map_buff),
tab->ref.key_parts,
@ -215,7 +216,7 @@ TEST_join(JOIN *join)
if (tab->ref.key_parts)
{
fprintf(DBUG_FILE,
" refs: %s\n", ref_key_parts[i].ptr());
" refs: %s\n", ref_key_parts[i].c_ptr_safe());
}
}
DBUG_UNLOCK_FILE;

View file

@ -802,7 +802,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
stmt_query->append(stmt_definition.str, stmt_definition.length);
trg_def->str= stmt_query->c_ptr();
trg_def->str= stmt_query->c_ptr_safe();
trg_def->length= stmt_query->length();
/* Create trigger definition file. */
@ -1039,10 +1039,7 @@ void Table_triggers_list::set_table(TABLE *new_table)
{
trigger_table= new_table;
for (Field **field= new_table->triggers->record1_field ; *field ; field++)
{
(*field)->table= (*field)->orig_table= new_table;
(*field)->table_name= &new_table->alias;
}
(*field)->init(new_table);
}

View file

@ -1617,7 +1617,8 @@ loop_end:
do
{
Field_string *field= new Field_string(tbl->file->ref_length, 0,
tbl->alias, &my_charset_bin);
tbl->alias.c_ptr(),
&my_charset_bin);
if (!field)
DBUG_RETURN(1);
field->init(tbl);

View file

@ -848,7 +848,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
thd->variables.sql_mode|= sql_mode;
}
DBUG_PRINT("info", ("View: %s", view_query.ptr()));
DBUG_PRINT("info", ("View: %s", view_query.c_ptr_safe()));
/* fill structure */
view->source= thd->lex->create_view_select;
@ -1675,7 +1675,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
}
if (non_existant_views.length())
{
my_error(ER_BAD_TABLE_ERROR, MYF(0), non_existant_views.c_ptr());
my_error(ER_BAD_TABLE_ERROR, MYF(0), non_existant_views.c_ptr_safe());
}
something_wrong= error || wrong_object_name || non_existant_views.length();

View file

@ -13121,7 +13121,7 @@ column_list_id:
while ((point=iter++))
{
if (!my_strcasecmp(system_charset_info,
point->column.ptr(), new_str->ptr()))
point->column.c_ptr(), new_str->c_ptr()))
break;
}
lex->grant_tot_col|= lex->which_columns;

View file

@ -2103,7 +2103,7 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
init_sql_alloc(&outparam->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
if (!(outparam->alias= my_strdup(alias, MYF(MY_WME))))
if (outparam->alias.copy(alias, strlen(alias), table_alias_charset))
goto err;
outparam->quick_keys.init();
outparam->covering_keys.init();
@ -2437,7 +2437,7 @@ partititon_err:
outparam->db_stat=0;
thd->lex->view_prepare_mode= save_view_prepare_mode;
free_root(&outparam->mem_root, MYF(0)); // Safe to call on bzero'd root
my_free((char*) outparam->alias, MYF(MY_ALLOW_ZERO_PTR));
outparam->alias.free();
DBUG_RETURN (error);
}
@ -2463,8 +2463,7 @@ int closefrm(register TABLE *table, bool free_share)
table->file->extra(HA_EXTRA_PREPARE_FOR_DROP);
error=table->file->close();
}
my_free((char*) table->alias, MYF(MY_ALLOW_ZERO_PTR));
table->alias= 0;
table->alias.free();
if (table->expr_arena)
table->expr_arena->free_items();
if (table->field)
@ -3301,7 +3300,7 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
const TABLE_FIELD_TYPE *field_def= table_def->field;
DBUG_ENTER("table_check_intact");
DBUG_PRINT("info",("table: %s expected_count: %d",
table->alias, table_def->count));
table->alias.c_ptr(), table_def->count));
/* Whether the table definition has already been validated. */
if (table->s->table_field_def_cache == table_def)
@ -3316,14 +3315,15 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
{
report_error(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE,
ER(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE),
table->alias, table_def->count, table->s->fields,
table->alias.c_ptr(), table_def->count, table->s->fields,
table->s->mysql_version, MYSQL_VERSION_ID);
DBUG_RETURN(TRUE);
}
else if (MYSQL_VERSION_ID == table->s->mysql_version)
{
report_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED,
ER(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED), table->alias,
ER(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED),
table->alias.c_ptr(),
table_def->count, table->s->fields);
DBUG_RETURN(TRUE);
}
@ -3335,11 +3335,13 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
is backward compatible.
*/
}
char buffer[STRING_BUFFER_USUAL_SIZE];
char buffer[1024];
for (i=0 ; i < table_def->count; i++, field_def++)
{
String sql_type(buffer, sizeof(buffer), system_charset_info);
sql_type.length(0);
/* Allocate min 256 characters at once */
sql_type.extra_allocation(256);
if (i < table->s->fields)
{
Field *field= table->field[i];
@ -3354,7 +3356,8 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
*/
report_error(0, "Incorrect definition of table %s.%s: "
"expected column '%s' at position %d, found '%s'.",
table->s->db.str, table->alias, field_def->name.str, i,
table->s->db.str, table->alias.c_ptr(),
field_def->name.str, i,
field->field_name);
}
field->sql_type(sql_type);
@ -3380,7 +3383,8 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
{
report_error(0, "Incorrect definition of table %s.%s: "
"expected column '%s' at position %d to have type "
"%s, found type %s.", table->s->db.str, table->alias,
"%s, found type %s.", table->s->db.str,
table->alias.c_ptr(),
field_def->name.str, i, field_def->type.str,
sql_type.c_ptr_safe());
error= TRUE;
@ -3390,7 +3394,8 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
report_error(0, "Incorrect definition of table %s.%s: "
"expected the type of column '%s' at position %d "
"to have character set '%s' but the type has no "
"character set.", table->s->db.str, table->alias,
"character set.", table->s->db.str,
table->alias.c_ptr(),
field_def->name.str, i, field_def->cset.str);
error= TRUE;
}
@ -3400,7 +3405,8 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
report_error(0, "Incorrect definition of table %s.%s: "
"expected the type of column '%s' at position %d "
"to have character set '%s' but found "
"character set '%s'.", table->s->db.str, table->alias,
"character set '%s'.", table->s->db.str,
table->alias.c_ptr(),
field_def->name.str, i, field_def->cset.str,
field->charset()->csname);
error= TRUE;
@ -3411,7 +3417,7 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
report_error(0, "Incorrect definition of table %s.%s: "
"expected column '%s' at position %d to have type %s "
" but the column is not found.",
table->s->db.str, table->alias,
table->s->db.str, table->alias.c_ptr(),
field_def->name.str, i, field_def->type.str);
error= TRUE;
}

View file

@ -721,7 +721,7 @@ struct st_table {
Table_triggers_list *triggers;
TABLE_LIST *pos_in_table_list;/* Element referring to this table */
ORDER *group;
const char *alias; /* alias or table name */
String alias; /* alias or table name */
uchar *null_flags;
my_bitmap_map *bitmap_init_value;
MY_BITMAP def_read_set, def_write_set, def_vcol_set, tmp_set;

View file

@ -1583,7 +1583,7 @@ static FEDERATEDX_SHARE *get_share(const char *table_name, TABLE *table)
tmp_share.table_name_length, ident_quote_char);
if (!(share= (FEDERATEDX_SHARE *) memdup_root(&mem_root, (char*)&tmp_share, sizeof(*share))) ||
!(share->select_query= (char*) strmake_root(&mem_root, query.ptr(), query.length() + 1)))
!(share->select_query= (char*) strmake_root(&mem_root, query.ptr(), query.length())))
goto error;
share->mem_root= mem_root;
@ -3435,11 +3435,13 @@ bool ha_federatedx::get_error_message(int error, String* buf)
buf->qs_append(remote_error_number);
buf->append(STRING_WITH_LEN(": "));
buf->append(remote_error_buf);
/* Ensure string ends with \0 */
(void) buf->c_ptr_safe();
remote_error_number= 0;
remote_error_buf[0]= '\0';
}
DBUG_PRINT("exit", ("message: %s", buf->ptr()));
DBUG_PRINT("exit", ("message: %s", buf->c_ptr_safe()));
DBUG_RETURN(FALSE);
}

View file

@ -1091,7 +1091,7 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt)
param.thd= thd;
param.op_name= "check";
param.db_name= table->s->db.str;
param.table_name= table->alias;
param.table_name= table->alias.c_ptr();
param.testflag= check_opt->flags | T_CHECK | T_SILENT;
param.stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method);
@ -1190,7 +1190,7 @@ int ha_maria::analyze(THD *thd, HA_CHECK_OPT * check_opt)
param.thd= thd;
param.op_name= "analyze";
param.db_name= table->s->db.str;
param.table_name= table->alias;
param.table_name= table->alias.c_ptr();
param.testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS |
T_DONT_CHECK_CHECKSUM);
param.using_global_keycache= 1;
@ -1485,7 +1485,7 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize)
_ma_copy_nontrans_state_information(file);
param->db_name= table->s->db.str;
param->table_name= table->alias;
param->table_name= table->alias.c_ptr();
param->tmpfile_createflag= O_RDWR | O_TRUNC;
param->using_global_keycache= 1;
param->thd= thd;

View file

@ -810,7 +810,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
param.thd = thd;
param.op_name = "check";
param.db_name= table->s->db.str;
param.table_name= table->alias;
param.table_name= table->alias.c_ptr();
param.testflag = check_opt->flags | T_CHECK | T_SILENT;
param.stats_method= (enum_handler_stats_method)thd->variables.myisam_stats_method;
@ -903,7 +903,7 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt)
param.thd = thd;
param.op_name= "analyze";
param.db_name= table->s->db.str;
param.table_name= table->alias;
param.table_name= table->alias.c_ptr();
param.testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS |
T_DONT_CHECK_CHECKSUM);
param.using_global_keycache = 1;
@ -1129,7 +1129,7 @@ int ha_myisam::repair(THD *thd, HA_CHECK &param, bool do_optimize)
DBUG_ENTER("ha_myisam::repair");
param.db_name= table->s->db.str;
param.table_name= table->alias;
param.table_name= table->alias.c_ptr();
param.tmpfile_createflag = O_RDWR | O_TRUNC;
param.using_global_keycache = 1;
param.thd= thd;