diff options
author | unknown <monty@donna.mysql.com> | 2000-08-22 00:18:32 +0300 |
---|---|---|
committer | unknown <monty@donna.mysql.com> | 2000-08-22 00:18:32 +0300 |
commit | 90104181f979b04de0a2889c2299c0add02d949c (patch) | |
tree | c129c5ccdb3df8c87c28c6a51baac6e208294313 /sql | |
parent | 90bc6094eed4bde988bad568ac48bd686a127639 (diff) | |
download | mariadb-git-90104181f979b04de0a2889c2299c0add02d949c.tar.gz |
FLUSH TABLE table_list
Fixes for RENAME TABLE
Portability fixes
Docs/manual.texi:
FLUSH TABLES table_list
client/mysql.cc:
Ia64 port
client/mysqladmin.c:
Ia64 port
client/mysqldump.c:
Ia64 port
client/mysqlimport.c:
Ia64 port
client/mysqlshow.c:
Ia64 port
client/readline.cc:
Ia64 port
configure.in:
Ia64 port
include/config-win.h:
Ia64 port
include/thr_alarm.h:
Ia64 port
myisam/myisamdef.h:
Ia64 port
myisammrg/myrg_rkey.c:
Ia64 port
mysys/thr_alarm.c:
Easier compile of non threaded client
mysys/thr_lock.c:
Easier compile of non threaded client
mysys/thr_mutex.c:
Easier compile of non threaded client
sql-bench/crash-me.sh:
Added test for RENAME + some ANSI SQL99 group functions
sql-bench/limits/mysql.cfg:
New run
sql-bench/server-cfg.sh:
Fix
sql-bench/test-insert.sh:
Fix
sql/field.cc:
Port to Ia64
sql/ha_berkeley.cc:
Port to Ia64
sql/ha_myisam.cc:
cleanup
sql/handler.cc:
Port to Ia64
sql/hostname.cc:
Port to Ia64
sql/item.cc:
Port to Ia64
sql/item_create.cc:
Port to Ia64
sql/item_func.cc:
Port to Ia64
sql/item_strfunc.cc:
Port to Ia64
sql/item_timefunc.cc:
Port to Ia64
sql/lock.cc:
Fix for RENAME
sql/log.cc:
Port to Ia64
sql/log_event.h:
Port to Ia64
sql/mini_client.cc:
Port to Ia64
sql/mysql_priv.h:
Port to Ia64
sql/mysqlbinlog.cc:
Port to Ia64
sql/mysqld.cc:
FLUSH TABLES table_list
sql/net_pkg.cc:
Port to Ia64
sql/procedure.h:
Port to Ia64
sql/share/swedish/errmsg.OLD:
FLUSH TABLES table_list
sql/slave.cc:
Port to Ia64
sql/sql_acl.cc:
Port to Ia64
sql/sql_analyse.cc:
Port to Ia64
sql/sql_analyse.h:
Port to Ia64
sql/sql_base.cc:
FLUSH TABLES table_list
sql/sql_class.cc:
Port to Ia64
sql/sql_class.h:
Port to Ia64
sql/sql_parse.cc:
Port to Ia64
sql/sql_rename.cc:
Fix of RENAME
sql/sql_show.cc:
Port to Ia64
sql/sql_string.cc:
Port to Ia64
sql/sql_string.h:
Port to Ia64
sql/sql_table.cc:
Fix of RENAME
sql/sql_udf.cc:
Port to Ia64
sql/sql_yacc.yy:
FLUSH TABLES table_list
sql/table.cc:
Port to Ia64
sql/thr_malloc.cc:
Port to Ia64
sql/time.cc:
Port to Ia64
sql/unireg.cc:
Port to Ia64
Diffstat (limited to 'sql')
39 files changed, 269 insertions, 203 deletions
diff --git a/sql/field.cc b/sql/field.cc index 9018021cb93..814a36e70a3 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -264,7 +264,7 @@ bool Field::send(String *packet) void Field_num::add_zerofill_and_unsigned(String &res) const { - res.length(strlen(res.ptr())); // Fix length + res.length((uint) strlen(res.ptr())); // Fix length if (unsigned_flag) res.append(" unsigned"); if (zerofill) @@ -355,7 +355,7 @@ void Field::store_time(TIME *ltime,timestamp_type type) case TIMESTAMP_TIME: sprintf(buff, "%02d:%02d:%02d", ltime->hour,ltime->minute,ltime->second); - store(buff,strlen(buff)); + store(buff,(uint) strlen(buff)); break; } } @@ -500,8 +500,12 @@ void Field_decimal::store(double nr) char buff[320]; fyllchar = zerofill ? (char) '0' : (char) ' '; +#ifdef HAVE_SNPRINTF_ + snprintf(buff,sizeof(buff), "%.*f",(int) dec,nr); +#else sprintf(buff,"%.*f",dec,nr); - length=strlen(buff); +#endif + length=(uint) strlen(buff); if (length > field_length) { @@ -1837,7 +1841,11 @@ String *Field_float::val_str(String *val_buffer, while (tmp_dec--) *to++= *pos++; #else +#ifdef HAVE_SNPRINTF_ + sprintf(to,val_buffer->length(),"%.*f",dec,nr); +#else sprintf(to,"%.*f",dec,nr); +#endif to=strend(to); #endif } @@ -2471,7 +2479,7 @@ void Field_timestamp::sort_string(char *to,uint length __attribute__((unused))) void Field_timestamp::sql_type(String &res) const { sprintf((char*) res.ptr(),"timestamp(%d)",(int) field_length); - res.length(strlen(res.ptr())); + res.length((uint) strlen(res.ptr())); } @@ -2597,7 +2605,7 @@ String *Field_time::val_str(String *val_buffer, sprintf((char*) val_buffer->ptr(),"%s%02d:%02d:%02d", sign,(int) (tmp/10000), (int) (tmp/100 % 100), (int) (tmp % 100)); - val_buffer->length(strlen(val_buffer->ptr())); + val_buffer->length((uint) strlen(val_buffer->ptr())); return val_buffer; } @@ -2722,7 +2730,7 @@ String *Field_year::val_str(String *val_buffer, void Field_year::sql_type(String &res) const { sprintf((char*) res.ptr(),"year(%d)",(int) field_length); - res.length(strlen(res.ptr())); + res.length((uint) strlen(res.ptr())); } @@ -3388,7 +3396,7 @@ void Field_string::sql_type(String &res) const (table->db_options_in_use & HA_OPTION_PACK_RECORD) ? "varchar" : "char", (int) field_length); - res.length(strlen(res.ptr())); + res.length((uint) strlen(res.ptr())); if (binary_flag) res.append(" binary"); } @@ -3566,7 +3574,7 @@ void Field_varstring::sort_string(char *to,uint length) void Field_varstring::sql_type(String &res) const { sprintf((char*) res.ptr(),"varchar(%d)",(int) field_length); - res.length(strlen(res.ptr())); + res.length((uint) strlen(res.ptr())); if (binary_flag) res.append(" binary"); } @@ -3980,7 +3988,7 @@ void Field_blob::sql_type(String &res) const case 3: str="medium"; break; case 4: str="long"; break; } - res.set(str,strlen(str)); + res.set(str,(uint) strlen(str)); res.append(binary_flag ? "blob" : "text"); } @@ -4191,7 +4199,7 @@ String *Field_enum::val_str(String *val_buffer __attribute__((unused)), val_ptr->length(0); else val_ptr->set((const char*) typelib->type_names[tmp-1], - strlen(typelib->type_names[tmp-1])); + (uint) strlen(typelib->type_names[tmp-1])); return val_ptr; } @@ -4309,7 +4317,7 @@ String *Field_set::val_str(String *val_buffer, if (val_buffer->length()) val_buffer->append(field_separator); String str(typelib->type_names[bitnr], - strlen(typelib->type_names[bitnr])); + (uint) strlen(typelib->type_names[bitnr])); val_buffer->append(str); } tmp>>=1; diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 5d76af832ae..652b0045885 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -1383,7 +1383,7 @@ static BDB_SHARE *get_share(const char *table_name) { BDB_SHARE *share; pthread_mutex_lock(&bdb_mutex); - uint length=strlen(table_name); + uint length=(uint) strlen(table_name); if (!(share=(BDB_SHARE*) hash_search(&bdb_open_tables, table_name, length))) { if ((share=(BDB_SHARE *) my_malloc(sizeof(*share)+length+1, diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 97204c48650..f45309ddaeb 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -349,7 +349,6 @@ int ha_myisam::analyze(THD *thd) int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) { if (!file) return HA_CHECK_INTERNAL_ERROR; - int error ; MI_CHECK param; myisamchk_init(¶m); @@ -438,7 +437,6 @@ void ha_myisam::deactivate_non_unique_index(ha_rows rows) bool ha_myisam::activate_all_index(THD *thd) { int error=0; - char fixed_name[FN_REFLEN]; MI_CHECK param; MYISAM_SHARE* share = file->s; DBUG_ENTER("activate_all_index"); diff --git a/sql/handler.cc b/sql/handler.cc index 817e3fa79dc..592861e176b 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -462,7 +462,7 @@ void handler::print_error(int error, myf errflag) char key[MAX_KEY_LENGTH]; String str(key,sizeof(key)); key_unpack(&str,table,(uint) key_nr); - uint max_length=MYSQL_ERRMSG_SIZE-strlen(ER(ER_DUP_ENTRY)); + uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(ER(ER_DUP_ENTRY)); if (str.length() >= max_length) { str.length(max_length-4); diff --git a/sql/hostname.cc b/sql/hostname.cc index 0e8d6e36f0f..47953020ffb 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -77,7 +77,7 @@ static void add_hostname(struct in_addr *in,const char *name) host_entry *entry; if (!(entry=(host_entry*) hostname_cache->search((gptr) &in->s_addr,0))) { - uint length=name ? strlen(name) : 0; + uint length=name ? (uint) strlen(name) : 0; if ((entry=(host_entry*) malloc(sizeof(host_entry)+length+1))) { diff --git a/sql/item.cc b/sql/item.cc index cc3f8101601..db4ce792b27 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -125,13 +125,14 @@ const char *Item_ident::full_name() const return field_name ? field_name : name ? name : "tmp_field"; if (db_name) { - tmp=(char*) sql_alloc(strlen(db_name)+strlen(table_name)+ - strlen(field_name)+3); + tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+ + (uint) strlen(field_name)+3); strxmov(tmp,db_name,".",table_name,".",field_name,NullS); } else { - tmp=(char*) sql_alloc(strlen(table_name)+strlen(field_name)+2); + tmp=(char*) sql_alloc((uint) strlen(table_name)+ + (uint) strlen(field_name)+2); strxmov(tmp,table_name,".",field_name,NullS); } return tmp; diff --git a/sql/item_create.cc b/sql/item_create.cc index a8f41c14aad..8c62643b35a 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -364,7 +364,7 @@ Item *create_func_ucase(Item* a) Item *create_func_version(void) { - return new Item_string(NullS,server_version, strlen(server_version)); + return new Item_string(NullS,server_version, (uint) strlen(server_version)); } Item *create_func_weekday(Item* a) diff --git a/sql/item_func.cc b/sql/item_func.cc index 0f0c444cb32..66e03e72f6b 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1047,7 +1047,7 @@ udf_handler::fix_fields(THD *thd,TABLE_LIST *tables,Item_result_field *func, } else thd=current_thd; // In WHERE / const clause - udf_func *tmp_udf=find_udf(u_d->name,strlen(u_d->name),1); + udf_func *tmp_udf=find_udf(u_d->name,(uint) strlen(u_d->name),1); if (!tmp_udf) { diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 3050125f410..c839065eb45 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -997,7 +997,7 @@ String *Item_func_encrypt::val_str(String *str) } pthread_mutex_lock(&LOCK_crypt); char *tmp=crypt(res->c_ptr(),salt_ptr); - str->set(tmp,strlen(tmp)); + str->set(tmp,(uint) strlen(tmp)); str->copy(); pthread_mutex_unlock(&LOCK_crypt); return str; @@ -1049,14 +1049,14 @@ String *Item_func_database::val_str(String *str) if (!current_thd->db) str->length(0); else - str->set((const char*) current_thd->db,strlen(current_thd->db)); + str->set((const char*) current_thd->db,(uint) strlen(current_thd->db)); return str; } String *Item_func_user::val_str(String *str) { THD *thd=current_thd; - if (str->copy((const char*) thd->user,strlen(thd->user)) || + if (str->copy((const char*) thd->user,(uint) strlen(thd->user)) || str->append('@') || str->append(thd->host ? thd->host : thd->ip ? thd->ip : "")) return &empty_string; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index fcb68d07f61..5b09f58d41e 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -455,7 +455,7 @@ void Item_func_curtime::fix_length_and_dec() (int) start->tm_hour, (int) start->tm_min, (int) start->tm_sec); - buff_length=strlen(buff); + buff_length=(uint) strlen(buff); } void Item_func_now::fix_length_and_dec() @@ -478,7 +478,7 @@ void Item_func_now::fix_length_and_dec() (int) start->tm_hour, (int) start->tm_min, (int) start->tm_sec); - buff_length=strlen(buff); + buff_length=(uint) strlen(buff); /* For getdate */ ltime.year= start->tm_year+1900; ltime.month= start->tm_mon+1; @@ -522,7 +522,7 @@ String *Item_func_sec_to_time::val_str(String *str) uint sec= (uint) (seconds % 3600); sprintf(buff,"%s%02lu:%02u:%02u",sign,(long) (seconds/3600), sec/60, sec % 60); - str->copy(buff,strlen(buff)); + str->copy(buff,(uint) strlen(buff)); return str; } diff --git a/sql/lock.cc b/sql/lock.cc index be942c2ec78..228dff6b058 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -418,7 +418,11 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list) return 0; /* Create a table entry with the right key and with an old refresh version */ - if (!(table= (TABLE*) thd->calloc(sizeof(*table)+key_length))) + /* Note that we must use my_malloc() here as this is freed by the table + cache */ + + if (!(table= (TABLE*) my_malloc(sizeof(*table)+key_length, + MYF(MY_WME | MY_ZEROFILL)))) return -1; memcpy((table->table_cache_key= (char*) (table+1)), key, key_length); table->key_length=key_length; @@ -435,7 +439,7 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list) void unlock_table_name(THD *thd, TABLE_LIST *table_list) { if (table_list->table) - hash_delete(&open_cache, (gptr) table_list->table); + hash_delete(&open_cache, (byte*) table_list->table); } static bool locked_named_table(THD *thd, TABLE_LIST *table_list) @@ -461,10 +465,7 @@ bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list) break; } wait_for_refresh(thd); + pthread_mutex_lock(&LOCK_open); } - pthread_mutex_lock(&thd->mysys_var->mutex); - thd->mysys_var->current_mutex=0; - thd->mysys_var->current_cond=0; - pthread_mutex_unlock(&thd->mysys_var->mutex); return result; } diff --git a/sql/log.cc b/sql/log.cc index 3c21a1a9422..e73f0c802a5 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -221,7 +221,7 @@ int MYSQL_LOG::find_first_log(LOG_INFO* linfo, const char* log_name) if(!index_file) return LOG_INFO_INVALID; int error = 0; char* fname = linfo->log_file_name; - int log_name_len = strlen(log_name); + int log_name_len = (uint) strlen(log_name); pthread_mutex_lock(&LOCK_index); if(my_fseek(index_file, 0L, MY_SEEK_SET, MYF(MY_WME) ) == MY_FILEPOS_ERROR) @@ -296,7 +296,7 @@ void MYSQL_LOG::make_log_name(char* buf, const char* log_ident) if(inited) { int dir_len = dirname_length(log_file_name); - int ident_len = strlen(log_ident); + int ident_len = (uint) strlen(log_ident); if(dir_len + ident_len + 1 > FN_REFLEN) { buf[0] = 0; diff --git a/sql/log_event.h b/sql/log_event.h index fb585f01dea..13472938975 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -101,7 +101,7 @@ public: time(&end_time); exec_time = end_time - thd->start_time; valid_exec_time = 1; - db_len = (db) ? strlen(db) : 0; + db_len = (db) ? (uint) strlen(db) : 0; } #endif @@ -189,9 +189,9 @@ public: time(&end_time); exec_time = end_time - thd->start_time; valid_exec_time = 1; - db_len = (db) ? strlen(db) : 0; - table_name_len = (table_name) ? strlen(table_name) : 0; - fname_len = (fname) ? strlen(fname) : 0; + db_len = (db) ? (uint) strlen(db) : 0; + table_name_len = (table_name) ? (uint) strlen(table_name) : 0; + fname_len = (fname) ? (uint) strlen(fname) : 0; sql_ex.field_term = (*ex->field_term)[0]; sql_ex.enclosed = (*ex->enclosed)[0]; sql_ex.line_term = (*ex->line_term)[0]; @@ -232,7 +232,7 @@ public: while((item = li++)) { num_fields++; - uchar len = (uchar)strlen(item->name); + uchar len = (uchar) strlen(item->name); field_block_len += len + 1; fields_buf.append(item->name, len + 1); field_lens_buf.append((char*)&len, 1); @@ -333,7 +333,7 @@ public: Rotate_log_event(const char* new_log_ident_arg, uint ident_len_arg = 0) : Log_event(time(NULL)), new_log_ident(new_log_ident_arg), - ident_len(ident_len_arg ? ident_len_arg : strlen(new_log_ident_arg)), + ident_len(ident_len_arg ? ident_len_arg : (uint) strlen(new_log_ident_arg)), alloced(0) {} diff --git a/sql/mini_client.cc b/sql/mini_client.cc index c0e6b3c3cbe..b9e66911475 100644 --- a/sql/mini_client.cc +++ b/sql/mini_client.cc @@ -423,13 +423,13 @@ mc_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg arg=""; if (net_write_command(net,(uchar) command,arg, - length ? length :strlen(arg))) + length ? length :(uint) strlen(arg))) { DBUG_PRINT("error",("Can't send command to server. Error: %d",errno)); mc_end_server(mysql); if (mc_mysql_reconnect(mysql) || net_write_command(net,(uchar) command,arg, - length ? length :strlen(arg))) + length ? length :(uint) strlen(arg))) { net->last_errno=CR_SERVER_GONE_ERROR; strmov(net->last_error,ER(net->last_errno)); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 2671f0661cc..fa61102fb57 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -229,7 +229,7 @@ void flush_thread_cache(); void mysql_execute_command(void); bool do_command(THD *thd); bool check_stack_overrun(THD *thd,char *dummy); -bool reload_acl_and_cache(uint options); +bool reload_acl_and_cache(THD *thd, uint options, TABLE_LIST *tables); void mysql_rm_db(THD *thd,char *db,bool if_exists); void table_cache_init(void); void table_cache_free(void); @@ -388,7 +388,7 @@ bool rename_temporary_table(TABLE *table, const char *new_db, void remove_db_from_cache(const my_string db); void flush_tables(); bool remove_table_from_cache(THD *thd, const char *db, const char *table); -bool close_cached_tables(bool wait_for_refresh); +bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables); void copy_field_from_tmp_record(Field *field,int offset); int fill_record(List<Item> &fields,List<Item> &values); int fill_record(Field **field,List<Item> &values); diff --git a/sql/mysqlbinlog.cc b/sql/mysqlbinlog.cc index c088dc13fd3..dd34230bc1a 100644 --- a/sql/mysqlbinlog.cc +++ b/sql/mysqlbinlog.cc @@ -118,7 +118,7 @@ static void usage() static void dump_remote_file(NET* net, const char* fname) { char buf[FN_REFLEN+1]; - uint len = strlen(fname); + uint len = (uint) strlen(fname); buf[0] = 0; memcpy(buf + 1, fname, len + 1); if(my_net_write(net, buf, len +2) || net_flush(net)) @@ -234,8 +234,8 @@ static void dump_remote_table(NET* net, const char* db, const char* table) { char buf[1024]; char * p = buf; - uint table_len = strlen(table); - uint db_len = strlen(db); + uint table_len = (uint) strlen(table); + uint db_len = (uint) strlen(db); if(table_len + db_len > sizeof(buf) - 2) die("Buffer overrun"); @@ -267,7 +267,7 @@ static void dump_remote_log_entries(const char* logname) NET* net = &mysql->net; int4store(buf, position); int2store(buf + 4, binlog_flags); - len = strlen(logname); + len = (uint) strlen(logname); memcpy(buf + 6, logname,len); if(mc_simple_command(mysql, COM_BINLOG_DUMP, buf, len + 6, 1)) die("Error sending the log dump command"); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index ed3a5d38188..bf0a88bb702 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1138,7 +1138,7 @@ static void *signal_hand(void *arg __attribute__((unused))) } break; case SIGHUP: - reload_acl_and_cache(~0); // Flush everything + reload_acl_and_cache((THD*) 0,~0, (TABLE_LIST*) 0); // Flush everything mysql_print_status((THD*) 0); // Send debug some info break; #ifdef USE_ONE_SIGNAL_HAND @@ -2875,7 +2875,7 @@ static void get_options(int argc,char **argv) berkeley_lock_type=berkeley_lock_types[type-1]; else { - if (test_if_int(optarg,strlen(optarg))) + if (test_if_int(optarg,(uint) strlen(optarg))) berkeley_lock_scan_time=atoi(optarg); else { @@ -3344,7 +3344,7 @@ static char *get_relative_path(const char *path) is_prefix(path,DEFAULT_MYSQL_HOME) && strcmp(DEFAULT_MYSQL_HOME,FN_ROOTDIR)) { - path+=strlen(DEFAULT_MYSQL_HOME); + path+=(uint) strlen(DEFAULT_MYSQL_HOME); while (*path == FN_LIBCHAR) path++; } @@ -3384,7 +3384,7 @@ static void fix_paths(void) strmov(tmp,mysql_tmpdir); mysql_tmpdir=tmp; convert_dirname(mysql_tmpdir); - mysql_tmpdir=(char*) my_realloc(mysql_tmpdir,strlen(mysql_tmpdir)+1, + mysql_tmpdir=(char*) my_realloc(mysql_tmpdir,(uint) strlen(mysql_tmpdir)+1, MYF(MY_HOLD_ON_ERROR)); } } diff --git a/sql/net_pkg.cc b/sql/net_pkg.cc index 27065ee776e..2308aa40d52 100644 --- a/sql/net_pkg.cc +++ b/sql/net_pkg.cc @@ -64,7 +64,7 @@ void send_error(NET *net, uint sql_errno, const char *err) } else { - length=strlen(err); + length=(uint) strlen(err); set_if_smaller(length,MYSQL_ERRMSG_SIZE); } VOID(net_write_command(net,(uchar) 255,(char*) err,length)); @@ -98,7 +98,7 @@ net_printf(NET *net, uint errcode, ...) offset= net->return_errno ? 2 : 0; text_pos=(char*) net->buff+head_length+offset+1; (void) vsprintf(my_const_cast(char*) (text_pos),format,args); - length=strlen((char*) text_pos); + length=(uint) strlen((char*) text_pos); if (length >= sizeof(net->last_error)) length=sizeof(net->last_error)-1; /* purecov: inspected */ va_end(args); @@ -215,7 +215,7 @@ net_store_length(char *pkg, uint length) char * net_store_data(char *to,const char *from) { - uint length=strlen(from); + uint length=(uint) strlen(from); to=net_store_length(to,length); memcpy(to,from,length); return to+length; @@ -267,7 +267,7 @@ net_store_data(String *packet,const char *from,uint length) bool net_store_data(String *packet,const char *from) { - uint length=strlen(from); + uint length=(uint) strlen(from); uint packet_length=packet->length(); if (packet_length+5+length > packet->alloced_length() && packet->realloc(packet_length+5+length)) diff --git a/sql/procedure.h b/sql/procedure.h index 7632bf7347c..1583f1169ce 100644 --- a/sql/procedure.h +++ b/sql/procedure.h @@ -38,7 +38,7 @@ public: virtual void set(const char *str,uint length)=0; virtual void set(longlong nr)=0; virtual enum_field_types field_type() const=0; - void set(const char *str) { set(str,strlen(str)); } + void set(const char *str) { set(str,(uint) strlen(str)); } void make_field(Send_field *tmp_field) { init_make_field(tmp_field,field_type()); diff --git a/sql/share/swedish/errmsg.OLD b/sql/share/swedish/errmsg.OLD index 94055083e54..233a60a5221 100644 --- a/sql/share/swedish/errmsg.OLD +++ b/sql/share/swedish/errmsg.OLD @@ -193,5 +193,4 @@ "Fick nätverksfel vid läsning från master", "Fick nätverksfel vid skrivning till master", "Hittar inte ett FULLTEXT index i kolumnlist", -#ER_LOCK_OR_ACTIVE_TRANSACTION "Can't execute the given command because you have active locked tables or an active transaction", diff --git a/sql/slave.cc b/sql/slave.cc index a527f3a1485..500c29480bc 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -467,7 +467,7 @@ static int request_dump(MYSQL* mysql, MASTER_INFO* mi) char* logname = mi->log_file_name; int4store(buf, mi->pos); int2store(buf + 4, binlog_flags); - len = strlen(logname); + len = (uint) strlen(logname); memcpy(buf + 6, logname,len); if(mc_simple_command(mysql, COM_BINLOG_DUMP, buf, len + 6, 1)) // something went wrong, so we will just reconnect and retry later @@ -486,8 +486,8 @@ static int request_table_dump(MYSQL* mysql, char* db, char* table) { char buf[1024]; char * p = buf; - uint table_len = strlen(table); - uint db_len = strlen(db); + uint table_len = (uint) strlen(table); + uint db_len = (uint) strlen(db); if(table_len + db_len > sizeof(buf) - 2) { sql_print_error("request_table_dump: Buffer overrun"); diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index d2f8680aee3..3315893cbbb 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -199,7 +199,7 @@ int acl_init(bool dont_read_acl_tables) update_hostname(&user.host,get_field(&mem, table,0)); user.user=get_field(&mem, table,1); user.password=get_field(&mem, table,2); - if (user.password && (length=strlen(user.password)) == 8 && + if (user.password && (length=(uint) strlen(user.password)) == 8 && protocol_version == PROTOCOL_VERSION) { sql_print_error( @@ -217,7 +217,7 @@ int acl_init(bool dont_read_acl_tables) get_salt_from_password(user.salt,user.password); user.access=get_access(table,3); user.sort=get_sort(2,user.host.hostname,user.user); - user.hostname_length=user.host.hostname ? strlen(user.host.hostname) : 0; + user.hostname_length=user.host.hostname ? (uint) strlen(user.host.hostname) : 0; #ifndef TO_BE_REMOVED if (table->fields <= 13) { // Without grant @@ -497,7 +497,7 @@ static void acl_insert_user(const char *user, const char *host, acl_user.password=0; acl_user.access=privileges; acl_user.sort=get_sort(2,acl_user.host.hostname,acl_user.user); - acl_user.hostname_length=strlen(acl_user.host.hostname); + acl_user.hostname_length=(uint) strlen(acl_user.host.hostname); if (password) { acl_user.password=(char*) ""; // Just point at something @@ -713,7 +713,7 @@ static void init_check_host(void) (void) push_dynamic(&acl_wild_hosts,(char*) &acl_user->host); } else if (!hash_search(&acl_check_hosts,(byte*) &acl_user->host, - strlen(acl_user->host.hostname))) + (uint) strlen(acl_user->host.hostname))) { if (hash_insert(&acl_check_hosts,(byte*) acl_user)) { // End of memory @@ -737,8 +737,8 @@ bool acl_check_host(const char *host, const char *ip) return 0; VOID(pthread_mutex_lock(&acl_cache->lock)); - if (host && hash_search(&acl_check_hosts,(byte*) host,strlen(host)) || - ip && hash_search(&acl_check_hosts,(byte*) ip,strlen(ip))) + if (host && hash_search(&acl_check_hosts,(byte*) host,(uint) strlen(host)) || + ip && hash_search(&acl_check_hosts,(byte*) ip,(uint) strlen(ip))) { VOID(pthread_mutex_unlock(&acl_cache->lock)); return 0; // Found host @@ -778,10 +778,10 @@ bool change_password(THD *thd, const char *host, const char *user, if (!host) host=thd->ip; /* purecov: tested */ /* password should always be 0 or 16 chars; simple hack to avoid cracking */ - length=strlen(new_password); + length=(uint) strlen(new_password); new_password[length & 16]=0; - if (strcmp(thd->user,user) || + if (!thd || strcmp(thd->user,user) || my_strcasecmp(host,thd->host ? thd->host : thd->ip)) { if (check_access(thd, UPDATE_ACL, "mysql",0,1)) @@ -820,7 +820,7 @@ bool change_password(THD *thd, const char *host, const char *user, acl_user->user, acl_user->host.hostname ? acl_user->host.hostname : "", new_password)); - mysql_update_log.write(buff,strlen(buff)); + mysql_update_log.write(buff,(uint) strlen(buff)); mysql_bin_log.write(&qinfo); return 0; } @@ -919,8 +919,8 @@ static bool update_user_table(THD *thd, const char *host, const char *user, tables.db=(char*) "mysql"; if (!(table=open_ltable(thd,&tables,TL_WRITE))) DBUG_RETURN(1); /* purecov: deadcode */ - table->field[0]->store(host,strlen(host)); - table->field[1]->store(user,strlen(user)); + table->field[0]->store(host,(uint) strlen(host)); + table->field[1]->store(user,(uint) strlen(user)); if (table->file->index_read_idx(table->record[0],0, (byte*) table->field[0]->ptr,0, @@ -930,7 +930,7 @@ static bool update_user_table(THD *thd, const char *host, const char *user, DBUG_RETURN(1); /* purecov: deadcode */ } store_record(table,1); - table->field[2]->store(new_password,strlen(new_password)); + table->field[2]->store(new_password,(uint) strlen(new_password)); if ((error=table->file->update_row(table->record[1],table->record[0]))) { table->file->print_error(error,MYF(0)); /* purecov: deadcode */ @@ -982,14 +982,14 @@ static int replace_user_table(TABLE *table, const LEX_USER &combo, restore_record(table,2); // cp empty row from record[2] table->field[0]->store(combo.host.str,combo.host.length); table->field[1]->store(combo.user.str,combo.user.length); - table->field[2]->store(password,strlen(password)); + table->field[2]->store(password,(uint) strlen(password)); } else { ima = 1; store_record(table,1); // Save copy for update if (combo.password.str) // If password given - table->field[2]->store(password,strlen(password)); + table->field[2]->store(password,(uint) strlen(password)); } for (i = 3, j = SELECT_ACL; // starting from reload @@ -1064,7 +1064,7 @@ static int replace_db_table(TABLE *table, const char *db, } table->field[0]->store(combo.host.str,combo.host.length); - table->field[1]->store(db,strlen(db)); + table->field[1]->store(db,(uint) strlen(db)); table->field[2]->store(combo.user.str,combo.user.length); table->file->index_init(0); if (table->file->index_read(table->record[0],(byte*) table->field[0]->ptr,0, @@ -1079,7 +1079,7 @@ static int replace_db_table(TABLE *table, const char *db, ima = 0; // no row restore_record(table,2); // cp empty row from record[2] table->field[0]->store(combo.host.str,combo.host.length); - table->field[1]->store(db,strlen(db)); + table->field[1]->store(db,(uint) strlen(db)); table->field[2]->store(combo.user.str,combo.user.length); } else @@ -1166,7 +1166,7 @@ public: db = strdup_root(&memex,d); user = strdup_root(&memex,u); tname= strdup_root(&memex,t); - key_length =strlen(d)+strlen(u)+strlen(t)+3; + key_length =(uint) strlen(d)+(uint) strlen(u)+(uint) strlen(t)+3; hash_key = (char*) alloc_root(&memex,key_length); strmov(strmov(strmov(hash_key,user)+1,db)+1,tname); (void) hash_init(&hash_columns,0,0,0, (hash_get_key) get_key_column,0, @@ -1187,7 +1187,7 @@ public: privs = cols = 0; /* purecov: inspected */ return; /* purecov: inspected */ } - key_length = strlen(db) + strlen(user) + strlen (tname) + 3; + key_length = (uint) strlen(db) + (uint) strlen(user) + (uint) strlen (tname) + 3; hash_key = (char*) alloc_root(&memex,key_length); strmov(strmov(strmov(hash_key,user)+1,db)+1,tname); privs = (uint) form->field[6]->val_int(); @@ -1200,10 +1200,10 @@ public: if (cols) { int key_len; - col_privs->field[0]->store(host,strlen(host)); - col_privs->field[1]->store(db,strlen(db)); - col_privs->field[2]->store(user,strlen(user)); - col_privs->field[3]->store(tname,strlen(tname)); + col_privs->field[0]->store(host,(uint) strlen(host)); + col_privs->field[1]->store(db,(uint) strlen(db)); + col_privs->field[2]->store(user,(uint) strlen(user)); + col_privs->field[3]->store(tname,(uint) strlen(tname)); key_len=(col_privs->field[0]->pack_length()+ col_privs->field[1]->pack_length()+ col_privs->field[2]->pack_length()+ @@ -1307,9 +1307,9 @@ static int replace_column_table(GRANT_TABLE *g_t, DBUG_ENTER("replace_column_table"); table->field[0]->store(combo.host.str,combo.host.length); - table->field[1]->store(db,strlen(db)); + table->field[1]->store(db,(uint) strlen(db)); table->field[2]->store(combo.user.str,combo.user.length); - table->field[3]->store(table_name,strlen(table_name)); + table->field[3]->store(table_name,(uint) strlen(table_name)); key_length=(table->field[0]->pack_length()+ table->field[1]->pack_length()+ table->field[2]->pack_length()+ table->field[3]->pack_length()); key_copy(key,table,0,key_length); @@ -1483,9 +1483,9 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, restore_record(table,2); // Get empty record table->field[0]->store(combo.host.str,combo.host.length); - table->field[1]->store(db,strlen(db)); + table->field[1]->store(db,(uint) strlen(db)); table->field[2]->store(combo.user.str,combo.user.length); - table->field[3]->store(table_name,strlen(table_name)); + table->field[3]->store(table_name,(uint) strlen(table_name)); store_record(table,1); // store at pos 1 if (table->file->index_read_idx(table->record[0],0, @@ -1530,7 +1530,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, } } - table->field[4]->store(grantor,strlen(grantor)); + table->field[4]->store(grantor,(uint) strlen(grantor)); table->field[6]->store((longlong) store_table_rights); table->field[7]->store((longlong) store_col_rights); rights=fix_rights_for_table(store_table_rights); @@ -2150,7 +2150,7 @@ bool check_grant_all_columns(THD *thd,uint want_access, TABLE *table) for (ptr=table->field; (field= *ptr) ; ptr++) { grant_column=column_hash_search(grant_table, field->field_name, - strlen(field->field_name)); + (uint) strlen(field->field_name)); if (!grant_column || (~grant_column->rights & want_access)) goto err; } @@ -2253,7 +2253,7 @@ uint get_column_grant(THD *thd, TABLE_LIST *table, Field *field) else { grant_column=column_hash_search(grant_table, field->field_name, - strlen(field->field_name)); + (uint) strlen(field->field_name)); if (!grant_column) priv=table->grant.privilege; else diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index 4794a23976b..96525822c52 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -352,14 +352,19 @@ void field_real::add() if ((decs = decimals()) == NOT_FIXED_DEC) { sprintf(buff, "%g", num); - length = strlen(buff); + length = (uint) strlen(buff); if (rint(num) != num) max_notzero_dec_len = 1; } else { +#ifdef HAVE_SNPRINTF + snprintf(buff, sizeof(buff), "%-.*f", (int) decs, num); +#else sprintf(buff, "%-.*f", (int) decs, num); - length = strlen(buff); +#endif + + length = (uint) strlen(buff); // We never need to check further than this end = buff + length - 1 - decs + max_notzero_dec_len; @@ -686,7 +691,7 @@ void field_str::get_opt_type(String *answer, ha_rows total_rows) sprintf(buff, "INT(%d)", num_info.integers); else sprintf(buff, "BIGINT(%d)", num_info.integers); - answer->append(buff, strlen(buff)); + answer->append(buff, (uint) strlen(buff)); if (ev_num_info.llval >= 0 && ev_num_info.min_dval >= 0) answer->append(" UNSIGNED"); if (num_info.zerofill) @@ -704,12 +709,12 @@ void field_str::get_opt_type(String *answer, ha_rows total_rows) else if ((max_length * (total_rows - nulls)) < (sum + total_rows)) { sprintf(buff, "CHAR(%d)", (int) max_length); - answer->append(buff, strlen(buff)); + answer->append(buff, (uint) strlen(buff)); } else { sprintf(buff, "VARCHAR(%d)", (int) max_length); - answer->append(buff, strlen(buff)); + answer->append(buff, (uint) strlen(buff)); } } else if (max_length < (1L << 16)) @@ -756,7 +761,7 @@ void field_real::get_opt_type(String *answer, sprintf(buff, "INT(%d)", (int) max_length - (item->decimals + 1)); else sprintf(buff, "BIGINT(%d)", (int) max_length - (item->decimals + 1)); - answer->append(buff, strlen(buff)); + answer->append(buff, (uint) strlen(buff)); if (min_arg >= 0) answer->append(" UNSIGNED"); } @@ -768,7 +773,7 @@ void field_real::get_opt_type(String *answer, else sprintf(buff, "DOUBLE(%d,%d)", (int) max_length - (item->decimals + 1), max_notzero_dec_len); - answer->append(buff, strlen(buff)); + answer->append(buff, (uint) strlen(buff)); } // if item is FIELD_ITEM, it _must_be_ Field_num in this class if (item->type() == Item::FIELD_ITEM && @@ -797,7 +802,7 @@ void field_longlong::get_opt_type(String *answer, sprintf(buff, "INT(%d)", (int) max_length); else sprintf(buff, "BIGINT(%d)", (int) max_length); - answer->append(buff, strlen(buff)); + answer->append(buff, (uint) strlen(buff)); if (min_arg >= 0) answer->append(" UNSIGNED"); @@ -826,7 +831,7 @@ void field_ulonglong::get_opt_type(String *answer, else sprintf(buff, "BIGINT(%d) UNSIGNED", (int) max_length); // if item is FIELD_ITEM, it _must_be_ Field_num in this class - answer->append(buff, strlen(buff)); + answer->append(buff, (uint) strlen(buff)); if (item->type() == Item::FIELD_ITEM && // a single number shouldn't be zerofill max_length != 1 && diff --git a/sql/sql_analyse.h b/sql/sql_analyse.h index f9cedcde2f6..e1cab3d5949 100644 --- a/sql/sql_analyse.h +++ b/sql/sql_analyse.h @@ -51,7 +51,7 @@ typedef struct st_tree_info uint check_ulonglong(const char *str, uint length); bool get_ev_num_info(EV_NUM_INFO *ev_info, NUM_INFO *info, const char *num); -bool test_if_number(NUM_INFO *info, const char *str, uint strlen); +bool test_if_number(NUM_INFO *info, const char *str, uint str_len); int compare_double(const double *s, const double *t); int compare_longlong(const longlong *s, const longlong *t); int compare_ulonglong(const ulonglong *s, const ulonglong *t); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index e4e0bf14a3d..e6468890ed6 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -127,7 +127,7 @@ void table_cache_init(void) void table_cache_free(void) { DBUG_ENTER("table_cache_free"); - close_cached_tables(0); + close_cached_tables((THD*) 0,0,(TABLE_LIST*) 0); if (!open_cache.records) // Safety first hash_free(&open_cache); DBUG_VOID_RETURN; @@ -373,7 +373,7 @@ void mysql_binlog_send(THD* thd, char* log_ident, ulong pos, ushort flags) else p = log_file_name; - uint ident_len = strlen(p); + uint ident_len = (uint) strlen(p); ulong event_len = ident_len + sizeof(header); int4store(header + 5, event_len); packet->append(header, sizeof(header)); @@ -433,8 +433,10 @@ send_fields(THD *thd,List<Item> &list,uint flag) if (convert) { - if (convert->store(packet,field.table_name,strlen(field.table_name)) || - convert->store(packet,field.col_name, strlen(field.col_name)) || + if (convert->store(packet,field.table_name, + (uint) strlen(field.table_name)) || + convert->store(packet,field.col_name, + (uint) strlen(field.col_name)) || packet->realloc(packet->length()+10)) goto err; } @@ -531,35 +533,50 @@ void free_io_cache(TABLE *table) /* Close all tables which aren't in use by any thread */ -bool close_cached_tables(bool if_wait_for_refresh) +bool close_cached_tables(THD *thd, bool if_wait_for_refresh, + TABLE_LIST *tables) { bool result=0; DBUG_ENTER("close_cached_tables"); VOID(pthread_mutex_lock(&LOCK_open)); - while (unused_tables) + if (!tables) { + while (unused_tables) + { #ifdef EXTRA_DEBUG - if (hash_delete(&open_cache,(byte*) unused_tables)) - printf("Warning: Couldn't delete open table from hash\n"); + if (hash_delete(&open_cache,(byte*) unused_tables)) + printf("Warning: Couldn't delete open table from hash\n"); #else - VOID(hash_delete(&open_cache,(byte*) unused_tables)); + VOID(hash_delete(&open_cache,(byte*) unused_tables)); #endif + } + if (!open_cache.records) + { + end_key_cache(); /* No tables in memory */ + key_cache_used=0; + } + refresh_version++; // Force close of open tables } - if (!open_cache.records) + else { - end_key_cache(); /* No tables in memory */ - key_cache_used=0; + bool found=0; + for (TABLE_LIST *table=tables ; table ; table=table->next) + { + if (remove_table_from_cache(thd, table->db, table->name)) + found=1; + } + if (!found) + if_wait_for_refresh=0; // Nothing to wait for } - refresh_version++; // Force close of open tables if (if_wait_for_refresh) { /* If there is any table that has a lower refresh_version, wait until this is closed (or this thread is killed) before returning */ - kill_delayed_threads(); - THD *thd=current_thd; + if (!tables) + kill_delayed_threads(); pthread_mutex_lock(&thd->mysys_var->mutex); thd->mysys_var->current_mutex= &LOCK_open; thd->mysys_var->current_cond= &COND_refresh; @@ -737,7 +754,8 @@ bool rename_temporary_table(TABLE *table, const char *db, { char *key; if (!(key=(char*) alloc_root(&table->mem_root, - strlen(db)+ strlen(table_name)+2))) + (uint) strlen(db)+ + (uint) strlen(table_name)+2))) return 1; /* purecov: inspected */ table->key_length=(uint) (strmov((table->real_name=strmov(table->table_cache_key=key, @@ -804,7 +822,7 @@ TABLE *unlink_open_table(THD *thd, TABLE *list, TABLE *find) /* When we call the following function we must have a lock on - LOCK_OPEN ; This lock will be freed on return + LOCK_OPEN ; This lock will be unlocked on return. */ void wait_for_refresh(THD *thd) @@ -946,8 +964,8 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, // remember the name of the non-existent table // so we can try to download it from the master { - int table_name_len = strlen(table_name); - int db_len = strlen(db); + int table_name_len = (uint) strlen(table_name); + int db_len = (uint) strlen(db); thd->last_nx_db = alloc_root(glob_alloc,db_len + table_name_len + 2); if(thd->last_nx_db) { @@ -987,7 +1005,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, /* Fix alias if table name changes */ if (strcmp(table->table_name,alias)) { - uint length=strlen(alias)+1; + uint length=(uint) strlen(alias)+1; table->table_name= (char*) my_realloc(table->table_name,length, MYF(MY_WME)); memcpy(table->table_name,alias,length); @@ -1509,8 +1527,8 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db, { TABLE *tmp_table; DBUG_ENTER("open_temporary_table"); - if (!(tmp_table=(TABLE*) my_malloc(sizeof(*tmp_table)+strlen(db)+ - strlen(table_name)+2, + if (!(tmp_table=(TABLE*) my_malloc(sizeof(*tmp_table)+(uint) strlen(db)+ + (uint) strlen(table_name)+2, MYF(MY_WME)))) DBUG_RETURN(0); /* purecov: inspected */ @@ -1611,7 +1629,7 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) const char *db=item->db_name; const char *table_name=item->table_name; const char *name=item->field_name; - uint length=strlen(name); + uint length=(uint) strlen(name); if (table_name) { /* Qualified field */ diff --git a/sql/sql_class.cc b/sql/sql_class.cc index cdf100cb9a7..f2fe6f5fe50 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -266,7 +266,7 @@ select_export::prepare(List<Item> &list) #ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS option|=1; // Force use of db directory #endif - if (strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN) + if ((uint) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN) strmake(path,exchange->file_name,FN_REFLEN-1); (void) fn_format(path,exchange->file_name, thd->db ? thd->db : "", "", option); diff --git a/sql/sql_class.h b/sql/sql_class.h index 7e561cf9d80..4389512c1b3 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -45,7 +45,7 @@ typedef struct st_log_info typedef struct st_master_info { char log_file_name[FN_REFLEN]; - ulong pos; + ulonglong pos; FILE* file; // we keep the file open, so we need to remember the file pointer // the variables below are needed because we can change masters on the fly @@ -58,7 +58,7 @@ typedef struct st_master_info bool inited; st_master_info():inited(0) { host[0] = 0; user[0] = 0; password[0] = 0;} - inline void inc_pos(ulong val) + inline void inc_pos(ulonglong val) { pthread_mutex_lock(&lock); pos += val; @@ -66,7 +66,7 @@ typedef struct st_master_info } // thread safe read of position - not needed if we are in the slave thread, // but required otherwise - inline void read_pos(ulong& var) + inline void read_pos(ulonglong& var) { pthread_mutex_lock(&lock); var = pos; @@ -470,7 +470,7 @@ class Table_ident :public Sql_alloc { } inline Table_ident(LEX_STRING table_arg) :table(table_arg) {db.str=0;} inline void change_db(char *db_name) - { db.str= db_name; db.length=strlen(db_name); } + { db.str= db_name; db.length=(uint) strlen(db_name); } }; // this is needed for user_vars hash diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index de50855b9de..e62e6185441 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -458,7 +458,7 @@ int handle_bootstrap(THD *thd,FILE *file) char *buff= (char*) thd->net.buff; while (fgets(buff, thd->net.max_packet, file)) { - uint length=strlen(buff); + uint length=(uint) strlen(buff); while (length && (isspace(buff[length-1]) || buff[length-1] == ';')) length--; buff[length]=0; @@ -726,7 +726,7 @@ bool do_command(THD *thd) if (check_access(thd,RELOAD_ACL,any_db)) break; mysql_log.write(command,NullS); - if (reload_acl_and_cache(options)) + if (reload_acl_and_cache(thd, options, (TABLE_LIST*) 0)) send_error(net,0); else send_eof(net); @@ -765,7 +765,7 @@ bool do_command(THD *thd) sprintf(strend(buff), " Memory in use: %ldK Max memory used: %ldK", (lCurMemory+1023L)/1024L,(lMaxMemory+1023L)/1024L); #endif - VOID(my_net_write(net, buff,strlen(buff))); + VOID(my_net_write(net, buff,(uint) strlen(buff))); VOID(net_flush(net)); break; } @@ -1131,15 +1131,32 @@ mysql_execute_command(void) } #endif case SQLCOM_RENAME_TABLE: - if (check_db_used(thd,tables) || - check_table_access(thd,ALTER_ACL,tables)) + { + TABLE_LIST *table; + if (check_db_used(thd,tables)) goto error; + for (table=tables ; table ; table=table->next->next) + { + if (check_access(thd, ALTER_ACL, table->db, &table->grant.privilege) || + check_access(thd, INSERT_ACL | CREATE_ACL, table->next->db, + &table->next->grant.privilege)) + goto error; + if (grant_option) + { + if (check_grant(thd,ALTER_ACL,table) || + (!test_all_bits(table->next->grant.privilege, + INSERT_ACL | CREATE_ACL) && + check_grant(thd,INSERT_ACL | CREATE_ACL, table->next))) + goto error; + } + } if (mysql_rename_tables(thd,tables)) res= -1; break; + } case SQLCOM_SHOW_CREATE: #ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(&thd->net,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + send_error(&thd->net,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ DBUG_VOID_RETURN; #else { @@ -1623,9 +1640,9 @@ mysql_execute_command(void) break; } case SQLCOM_FLUSH: - if (check_access(thd,RELOAD_ACL,any_db)) + if (check_access(thd,RELOAD_ACL,any_db) || check_db_used(thd, tables)) goto error; - if (reload_acl_and_cache(lex->type)) + if (reload_acl_and_cache(thd, lex->type, tables)) send_error(&thd->net,0); else send_ok(&thd->net); @@ -2099,7 +2116,7 @@ bool add_field_to_list(char *field_name, enum_field_types type, new_field->interval=interval; new_field->length=0; for (const char **pos=interval->type_names; *pos ; pos++) - new_field->length+=strlen(*pos)+1; + new_field->length+=(uint) strlen(*pos)+1; new_field->length--; set_if_smaller(new_field->length,MAX_FIELD_WIDTH-1); if (default_value) @@ -2120,10 +2137,10 @@ bool add_field_to_list(char *field_name, enum_field_types type, { new_field->interval=interval; new_field->pack_length=interval->count < 256 ? 1 : 2; // Should be safe - new_field->length=strlen(interval->type_names[0]); + new_field->length=(uint) strlen(interval->type_names[0]); for (const char **pos=interval->type_names+1; *pos ; pos++) { - uint length=strlen(*pos); + uint length=(uint) strlen(*pos); set_if_bigger(new_field->length,length); } set_if_smaller(new_field->length,MAX_FIELD_WIDTH-1); @@ -2196,7 +2213,7 @@ static void remove_escape(char *name) { char *to; #ifdef USE_MB - char *strend=name+strlen(name); + char *strend=name+(uint) strlen(name); #endif for (to=name; *name ; name++) { @@ -2329,7 +2346,7 @@ static bool check_dup(THD *thd,const char *db,const char *name, return 0; } -bool reload_acl_and_cache(uint options) +bool reload_acl_and_cache(THD *thd, uint options, TABLE_LIST *tables) { bool result=0; @@ -2351,12 +2368,12 @@ bool reload_acl_and_cache(uint options) } if (options & (REFRESH_TABLES | REFRESH_READ_LOCK)) { - if ((options & REFRESH_READ_LOCK) && ! current_thd->global_read_lock) + if ((options & REFRESH_READ_LOCK) && thd && ! thd->global_read_lock) { - current_thd->global_read_lock=1; + thd->global_read_lock=1; thread_safe_increment(global_read_lock,&LOCK_open); } - result=close_cached_tables((options & REFRESH_FAST) ? 0 : 1); + result=close_cached_tables(thd,(options & REFRESH_FAST) ? 0 : 1, tables); } if (options & REFRESH_HOSTS) hostname_cache_refresh(); diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index ac7b0bbdc41..ee6771d4b25 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -21,8 +21,8 @@ #include "mysql_priv.h" -static TABLE_LIST *mysql_rename_tables(THD *thd, TABLE_LIST *table_list, - bool skip_error); +static TABLE_LIST *rename_tables(THD *thd, TABLE_LIST *table_list, + bool skip_error); /* Every second entry in the table_list is the original name and every @@ -58,7 +58,7 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list) if (!got_all_locks && wait_for_locked_table_names(thd,table_list)) goto end; - if (!(ren_table=mysql_rename_tables(thd,table_list,0))) + if (!(ren_table=rename_tables(thd,table_list,0))) error=0; end: @@ -66,25 +66,24 @@ end: { /* Rename didn't succeed; rename back the tables in reverse order */ TABLE_LIST *prev=0,*table; - /* - Reverse the table list ; Note that we need to handle the case that - every second entry must stay in place in respect to the previous - */ + /* Reverse the table list */ + while (table_list) { - TABLE_LIST *next=table_list->next->next; - table_list->next->next=prev; + TABLE_LIST *next=table_list->next; + table_list->next=prev; prev=table_list; table_list=next; } table_list=prev; /* Find the last renamed table */ - for (table=table_list ; table->next != ren_table ; + for (table=table_list ; + table->next != ren_table ; table=table->next->next) ; table=table->next->next; // Skipp error table /* Revert to old names */ - mysql_rename_tables(thd, table, 1); + rename_tables(thd, table, 1); /* Note that lock_table == 0 here, so the unlock loop will work */ } if (!error) @@ -92,6 +91,7 @@ end: mysql_update_log.write(thd->query,thd->query_length); Query_log_event qinfo(thd, thd->query); mysql_bin_log.write(&qinfo); + send_ok(&thd->net); } for (TABLE_LIST *table=table_list ; table != lock_table ; table=table->next) unlock_table_name(thd,table); @@ -103,30 +103,45 @@ end: /* Rename all tables in list; Return pointer to wrong entry if something goes - wrong. + wrong. Note that the table_list may be empty! */ static TABLE_LIST * -mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) +rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) { - TABLE_LIST *ren_table; - for (ren_table=table_list ; ren_table ; ren_table=ren_table->next) + TABLE_LIST *ren_table,*new_table; + DBUG_ENTER("rename_tables"); + + for (ren_table=table_list ; ren_table ; ren_table=new_table->next) { db_type table_type; char name[FN_REFLEN]; - TABLE_LIST *new_table=ren_table->next; + new_table=ren_table->next; sprintf(name,"%s/%s/%s%s",mysql_data_home, + new_table->db,new_table->name, + reg_ext); + if (!access(name,F_OK)) + { + my_error(ER_TABLE_EXISTS_ERROR,MYF(0),name); + return ren_table; // This can't be skipped + } + sprintf(name,"%s/%s/%s%s",mysql_data_home, ren_table->db,ren_table->name, reg_ext); - if ((table_type=get_table_type(name)) == DB_TYPE_UNKNOWN || - mysql_rename_table(table_type, - ren_table->db, ren_table->name, - new_table->db, new_table->name)) + if ((table_type=get_table_type(name)) == DB_TYPE_UNKNOWN) + { + my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno); + if (!skip_error) + return ren_table; + } + else if (mysql_rename_table(table_type, + ren_table->db, ren_table->name, + new_table->db, new_table->name)) { if (!skip_error) return ren_table; } } - return 0; + DBUG_RETURN(0); } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index c027f6397c2..695c815a500 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -55,7 +55,7 @@ mysqld_show_dbs(THD *thd,const char *wild) char *file_name; DBUG_ENTER("mysqld_show_dbs"); - field->name=(char*) thd->alloc(20+ (wild ? strlen(wild)+4: 0)); + field->name=(char*) thd->alloc(20+ (wild ? (uint) strlen(wild)+4: 0)); field->max_length=NAME_LEN; end=strmov(field->name,"Database"); if (wild && wild[0]) @@ -92,7 +92,7 @@ int mysqld_show_tables(THD *thd,const char *db,const char *wild) char *file_name; DBUG_ENTER("mysqld_show_tables"); - field->name=(char*) thd->alloc(20+strlen(db)+(wild ? strlen(wild)+4:0)); + field->name=(char*) thd->alloc(20+(uint) strlen(db)+(wild ? (uint) strlen(wild)+4:0)); end=strxmov(field->name,"Tables_in_",db,NullS); if (wild && wild[0]) strxmov(end," (",wild,")",NullS); @@ -405,7 +405,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild) #ifdef NOT_USED if (thd->col_access & TABLE_ACLS || ! check_grant_column(thd,table,field->field_name, - strlen(field->field_name),1)) + (uint) strlen(field->field_name),1)) #endif { byte *pos; @@ -899,7 +899,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) thd_info->query=0; if (tmp->query) { - uint length=strlen(tmp->query); + uint length=(uint) strlen(tmp->query); if (length > max_query_length) length=max_query_length; thd_info->query=(char*) thd->memdup(tmp->query,length+1); diff --git a/sql/sql_string.cc b/sql/sql_string.cc index c18f9e3807e..e3cf8cc7abc 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -126,7 +126,7 @@ bool String::set(double num,uint decimals) if (decimals >= NOT_FIXED_DEC) { sprintf(buff,"%.14g",num); // Enough for a DATETIME - return copy(buff,strlen(buff)); + return copy(buff,(uint) strlen(buff)); } #ifdef HAVE_FCONVERT int decpt,sign; @@ -141,7 +141,7 @@ bool String::set(double num,uint decimals) buff[0]='-'; pos=buff; } - return copy(pos,strlen(pos)); + return copy(pos,(uint) strlen(pos)); } if (alloc((uint32) ((uint32) decpt+3+decimals))) return TRUE; @@ -185,12 +185,12 @@ end: str_length=(uint32) (to-Ptr); return FALSE; #else -#ifdef HAVE_SNPRINTF_ +#ifdef HAVE_SNPRINTF snprintf(buff,sizeof(buff), "%.*f",(int) decimals,num); #else sprintf(buff,"%.*f",(int) decimals,num); #endif - return copy(buff,strlen(buff)); + return copy(buff,(uint) strlen(buff)); #endif } @@ -259,7 +259,7 @@ bool String::append(const String &s) bool String::append(const char *s,uint32 arg_length) { if (!arg_length) // Default argument - arg_length=strlen(s); + arg_length=(uint) strlen(s); if (realloc(str_length+arg_length)) return TRUE; memcpy(Ptr+str_length,s,arg_length); diff --git a/sql/sql_string.h b/sql/sql_string.h index 5d125422c0b..d421261f9e4 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -35,7 +35,7 @@ public: String(uint32 length_arg) { alloced=0; Alloced_length=0; (void) real_alloc(length_arg); } String(const char *str) - { Ptr=(char*) str; str_length=strlen(str); Alloced_length=0; alloced=0;} + { Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;} String(const char *str,uint32 len) { Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;} String(char *str,uint32 len) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 1440929c98b..ce434fd43d7 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -653,25 +653,25 @@ mysql_rename_table(enum db_type base, { char from[FN_REFLEN],to[FN_REFLEN]; handler *file=get_new_handler((TABLE*) 0, base); - bool error=0; + int error=0; DBUG_ENTER("mysql_rename_table"); (void) sprintf(from,"%s/%s/%s",mysql_data_home,old_db,old_name); (void) sprintf(to,"%s/%s/%s",mysql_data_home,new_db,new_name); fn_format(from,from,"","",4); fn_format(to,to, "","",4); - if (file->rename_table((const char*) from,(const char *) to)) - error=1; - else + if (!(error=file->rename_table((const char*) from,(const char *) to))) { if (rename_file_ext(from,to,reg_ext)) { - error=1; + error=my_errno; /* Restore old file name */ file->rename_table((const char*) to,(const char *) from); } } delete file; - DBUG_RETURN(error); + if (error) + my_error(ER_ERROR_ON_RENAME, MYF(0), from, to, error); + DBUG_RETURN(error != 0); } /* diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 7d123141169..e5508dafe37 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -263,7 +263,7 @@ udf_func *find_udf(const char *name,uint length,bool mark_used) /* TODO: This should be changed to reader locks someday! */ pthread_mutex_lock(&THR_LOCK_udf); udf=(udf_func*) hash_search(&udf_hash,name, - length ? length : strlen(name)); + length ? length : (uint) strlen(name)); if (mark_used) udf->usage_count++; pthread_mutex_unlock(&THR_LOCK_udf); @@ -299,7 +299,7 @@ static udf_func *add_udf(char *name, Item_result ret, char *dl, return 0; bzero((char*) tmp,sizeof(*tmp)); tmp->name = name; - tmp->name_length=strlen(tmp->name); + tmp->name_length=(uint) strlen(tmp->name); tmp->dl = dl; tmp->returns = ret; tmp->type = type; @@ -395,7 +395,7 @@ int mysql_create_function(THD *thd,udf_func *udf) restore_record(table,2); // Get default values for fields table->field[0]->store(u_d->name, u_d->name_length); table->field[1]->store((longlong) u_d->returns); - table->field[2]->store(u_d->dl,strlen(u_d->dl)); + table->field[2]->store(u_d->dl,(uint) strlen(u_d->dl)); if (table->fields >= 4) // If not old func format table->field[3]->store((longlong) u_d->type); error = table->file->write_row(table->record[0]); @@ -430,7 +430,7 @@ int mysql_drop_function(THD *thd,const char *udf_name) DBUG_RETURN(1); } pthread_mutex_lock(&THR_LOCK_udf); - if (!(udf=(udf_func*) hash_search(&udf_hash,udf_name, strlen(udf_name)))) + if (!(udf=(udf_func*) hash_search(&udf_hash,udf_name, (uint) strlen(udf_name)))) { net_printf(&thd->net, ER_FUNCTION_NOT_DEFINED, udf_name); goto err; @@ -445,7 +445,7 @@ int mysql_drop_function(THD *thd,const char *udf_name) if (!(table = open_ltable(thd,&tables,TL_WRITE))) goto err; if (!table->file->index_read_idx(table->record[0],0,(byte*) udf_name, - strlen(udf_name), + (uint) strlen(udf_name), HA_READ_KEY_EXACT)) { int error; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 5cfc05406c4..1cd0f664c53 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -505,7 +505,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); flush_options flush_option insert_lock_option replace_lock_option equal optional_braces opt_key_definition key_usage_list2 opt_mi_check_type opt_to mi_check_types normal_join - table_to_table_list table_to_table + table_to_table_list table_to_table opt_table_list END_OF_INPUT %type <NONE> @@ -590,7 +590,7 @@ master_def: Lex->mi.log_file_name = $3.str; } | - MASTER_PORT_SYM EQ ULONGLONG_NUM + MASTER_PORT_SYM EQ ULONG_NUM { Lex->mi.port = $3; } @@ -600,7 +600,7 @@ master_def: Lex->mi.pos = $3; } | - MASTER_CONNECT_RETRY_SYM EQ ULONGLONG_NUM + MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM { Lex->mi.connect_retry = $3; } @@ -1151,8 +1151,8 @@ table_to_table_list: table_to_table: table_ident TO_SYM table_ident - { if (add_table_to_list($1,NULL,TL_IGNORE) || - add_table_to_list($3,NULL,TL_IGNORE)) + { if (!add_table_to_list($1,NULL,TL_IGNORE) || + !add_table_to_list($3,NULL,TL_IGNORE)) YYABORT; } @@ -2160,7 +2160,7 @@ flush_options: | flush_option flush_option: - TABLES { Lex->type|= REFRESH_TABLES; } + TABLES { Lex->type|= REFRESH_TABLES; } opt_table_list | TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; } | HOSTS_SYM { Lex->type|= REFRESH_HOSTS; } | PRIVILEGES { Lex->type|= REFRESH_GRANT; } @@ -2169,6 +2169,10 @@ flush_option: | SLAVE { Lex->type|= REFRESH_SLAVE; } | MASTER_SYM { Lex->type|= REFRESH_MASTER; } +opt_table_list: + /* empty */ {} + | table_list {} + /* kill threads */ kill: diff --git a/sql/table.cc b/sql/table.cc index 98f7b089b19..82ad1f13606 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -33,7 +33,7 @@ static uint find_field(TABLE *form,uint start,uint length); static byte* get_field_name(Field *buff,uint *length, my_bool not_used __attribute__((unused))) { - *length= strlen(buff->field_name); + *length= (uint) strlen(buff->field_name); return (byte*) buff->field_name; } @@ -670,7 +670,7 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, uchar *pos; DBUG_ENTER("make_new_entry"); - length=strlen(newname)+1; + length=(uint) strlen(newname)+1; n_length=uint2korr(fileinfo+4); maxlength=uint2korr(fileinfo+6); names=uint2korr(fileinfo+8); @@ -680,7 +680,7 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, { /* Expand file */ newpos+=IO_SIZE; int4store(fileinfo+10,newpos); - endpos=(ulong) my_seek(file,0L,MY_SEEK_END,MYF(0)); /* Copy from file-end */ + endpos=(ulong) my_seek(file,0L,MY_SEEK_END,MYF(0));/* Copy from file-end */ bufflength= (uint) (endpos & (IO_SIZE-1)); /* IO_SIZE is a power of 2 */ while (endpos > maxlength) diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc index 9273b3eb5a5..e890019553f 100644 --- a/sql/thr_malloc.cc +++ b/sql/thr_malloc.cc @@ -53,7 +53,7 @@ gptr sql_calloc(uint size) char *sql_strdup(const char *str) { - uint len=strlen(str)+1; + uint len=(uint) strlen(str)+1; char *pos; if ((pos= (char*) sql_alloc(len))) memcpy(pos,str,len); diff --git a/sql/time.cc b/sql/time.cc index 066979d1c9a..5cf7d0ee074 100644 --- a/sql/time.cc +++ b/sql/time.cc @@ -267,7 +267,7 @@ void find_date(string pos,uint *vek,uint flag) bzero((char*) vek,sizeof(int)*4); while (*pos && !isdigit(*pos)) pos++; - length=strlen(pos); + length=(uint) strlen(pos); for (uint i=0 ; i< 3; i++) { start=pos; value=0; diff --git a/sql/unireg.cc b/sql/unireg.cc index 611a4f04ec9..49f4a9fbfac 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -186,7 +186,7 @@ static uchar * pack_screens(List<create_field> &create_fields, create_field *field; while ((field=it++)) - length+=strlen(field->field_name)+1+TE_INFO_LENGTH+cols/2; + length+=(uint) strlen(field->field_name)+1+TE_INFO_LENGTH+cols/2; if (!(info=(uchar*) my_malloc(length,MYF(MY_WME)))) DBUG_RETURN(0); @@ -216,7 +216,7 @@ static uchar * pack_screens(List<create_field> &create_fields, strfill((my_string) pos+3,(uint) (cols >> 1),' '); pos+=(cols >> 1)+4; } - length=strlen(cfield->field_name); + length=(uint) strlen(cfield->field_name); if (length > cols-3) length=cols-3; @@ -352,7 +352,7 @@ static bool pack_header(uchar *forminfo, enum db_type table_type, if (old_int_count != int_count) { for (const char **pos=field->interval->type_names ; *pos ; pos++) - int_length+=strlen(*pos)+1; // field + suffix prefix + int_length+=(uint) strlen(*pos)+1; // field + suffix prefix int_parts+=field->interval->count+1; } } @@ -567,9 +567,9 @@ static bool make_empty_rec(File file,enum db_type table_type, regfield->store((longlong) 1); } else if (type == Field::YES) // Old unireg type - regfield->store(ER(ER_YES),strlen(ER(ER_YES))); + regfield->store(ER(ER_YES),(uint) strlen(ER(ER_YES))); else if (type == Field::NO) // Old unireg type - regfield->store(ER(ER_NO),strlen(ER(ER_NO))); + regfield->store(ER(ER_NO), (uint) strlen(ER(ER_NO))); else regfield->reset(); delete regfield; |