Commit 57b13026 authored by unknown's avatar unknown

sql_show.cc SHOW CREATE now return nicely formatted statement


sql/sql_show.cc:
  SHOW CREATE now return nicely formatted statement
parent 69e962c4
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#undef USE_RAID #undef USE_RAID
#define USE_RAID #define USE_RAID
#include "mysql_priv.h" #include "mysql_priv.h"
#include "sql_select.h" // For select_describe #include "sql_select.h" // For select_describe
#include "sql_acl.h" #include "sql_acl.h"
#include <my_dir.h> #include <my_dir.h>
extern "C" pthread_mutex_t THR_LOCK_keycache; extern "C" pthread_mutex_t THR_LOCK_keycache;
...@@ -30,11 +30,11 @@ static const char *grant_names[]={ ...@@ -30,11 +30,11 @@ static const char *grant_names[]={
"process","file","grant","references","index","alter"}; "process","file","grant","references","index","alter"};
static TYPELIB grant_types = { sizeof(grant_names)/sizeof(char **), static TYPELIB grant_types = { sizeof(grant_names)/sizeof(char **),
"grant_types", "grant_types",
grant_names}; grant_names};
static int mysql_find_files(THD *thd,List<char> *files, const char *db, static int mysql_find_files(THD *thd,List<char> *files, const char *db,
const char *path, const char *wild, bool dir); const char *path, const char *wild, bool dir);
static int static int
store_create_info(THD *thd, TABLE *table, String* packet); store_create_info(THD *thd, TABLE *table, String* packet);
...@@ -119,7 +119,7 @@ int mysqld_show_tables(THD *thd,const char *db,const char *wild) ...@@ -119,7 +119,7 @@ int mysqld_show_tables(THD *thd,const char *db,const char *wild)
static int static int
mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path, mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
const char *wild, bool dir) const char *wild, bool dir)
{ {
uint i; uint i;
char *ext; char *ext;
...@@ -134,32 +134,32 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path, ...@@ -134,32 +134,32 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
if (!(dirp = my_dir(path,MYF(MY_WME | (dir ? MY_WANT_STAT : 0))))) if (!(dirp = my_dir(path,MYF(MY_WME | (dir ? MY_WANT_STAT : 0)))))
DBUG_RETURN(-1); DBUG_RETURN(-1);
for (i=0 ; i < (uint) dirp->number_off_files ; i++) for (i=0 ; i < (uint) dirp->number_off_files ; i++)
{ {
file=dirp->dir_entry+i; file=dirp->dir_entry+i;
if (dir) if (dir)
{ /* Return databases */ { /* Return databases */
#ifdef USE_SYMDIR #ifdef USE_SYMDIR
char *ext; char *ext;
if (my_use_symdir && !strcmp(ext=fn_ext(file->name), ".sym")) if (my_use_symdir && !strcmp(ext=fn_ext(file->name), ".sym"))
*ext=0; /* Remove extension */ *ext=0; /* Remove extension */
else else
#endif #endif
{ {
if (file->name[0] == '.' || !MY_S_ISDIR(file->mystat.st_mode) || if (file->name[0] == '.' || !MY_S_ISDIR(file->mystat.st_mode) ||
(wild && wild[0] && wild_compare(file->name,wild))) (wild && wild[0] && wild_compare(file->name,wild)))
continue; continue;
} }
} }
else else
{ {
// Return only .frm files which isn't temp files. // Return only .frm files which isn't temp files.
if (my_strcasecmp(ext=fn_ext(file->name),reg_ext) || if (my_strcasecmp(ext=fn_ext(file->name),reg_ext) ||
is_prefix(file->name,tmp_file_prefix)) // Mysql temp table is_prefix(file->name,tmp_file_prefix)) // Mysql temp table
continue; continue;
*ext=0; *ext=0;
if (wild && wild[0] && wild_compare(file->name,wild)) if (wild && wild[0] && wild_compare(file->name,wild))
continue; continue;
} }
/* Don't show tables where we don't have any privileges */ /* Don't show tables where we don't have any privileges */
if (db && !(col_access & TABLE_ACLS)) if (db && !(col_access & TABLE_ACLS))
...@@ -168,7 +168,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path, ...@@ -168,7 +168,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
table_list.real_name=file->name; table_list.real_name=file->name;
table_list.grant.privilege=col_access; table_list.grant.privilege=col_access;
if (check_grant(thd,TABLE_ACLS,&table_list,1)) if (check_grant(thd,TABLE_ACLS,&table_list,1))
continue; continue;
} }
if (files->push_back(thd->strdup(file->name))) if (files->push_back(thd->strdup(file->name)))
{ {
...@@ -245,7 +245,7 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) ...@@ -245,7 +245,7 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
if (!(table = open_ltable(thd, &table_list, TL_READ))) if (!(table = open_ltable(thd, &table_list, TL_READ)))
{ {
for (uint i=0 ; i < field_list.elements ; i++) for (uint i=0 ; i < field_list.elements ; i++)
net_store_null(packet); net_store_null(packet);
net_store_data(packet,thd->net.last_error); net_store_data(packet,thd->net.last_error);
thd->net.last_error[0]=0; thd->net.last_error[0]=0;
} }
...@@ -256,95 +256,95 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) ...@@ -256,95 +256,95 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK); file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK);
net_store_data(packet, file->table_type()); net_store_data(packet, file->table_type());
net_store_data(packet, net_store_data(packet,
(table->db_options_in_use & HA_OPTION_PACK_RECORD) ? (table->db_options_in_use & HA_OPTION_PACK_RECORD) ?
"Dynamic" : "Dynamic" :
(table->db_options_in_use & HA_OPTION_COMPRESS_RECORD) (table->db_options_in_use & HA_OPTION_COMPRESS_RECORD)
? "Compressed" : "Fixed"); ? "Compressed" : "Fixed");
net_store_data(packet, (longlong) file->records); net_store_data(packet, (longlong) file->records);
net_store_data(packet, (uint32) file->mean_rec_length); net_store_data(packet, (uint32) file->mean_rec_length);
net_store_data(packet, (longlong) file->data_file_length); net_store_data(packet, (longlong) file->data_file_length);
if (file->max_data_file_length) if (file->max_data_file_length)
net_store_data(packet, (longlong) file->max_data_file_length); net_store_data(packet, (longlong) file->max_data_file_length);
else else
net_store_null(packet); net_store_null(packet);
net_store_data(packet, (longlong) file->index_file_length); net_store_data(packet, (longlong) file->index_file_length);
net_store_data(packet, (longlong) file->delete_length); net_store_data(packet, (longlong) file->delete_length);
if (table->found_next_number_field) if (table->found_next_number_field)
{ {
table->next_number_field=table->found_next_number_field; table->next_number_field=table->found_next_number_field;
table->next_number_field->reset(); table->next_number_field->reset();
file->update_auto_increment(); file->update_auto_increment();
net_store_data(packet, table->next_number_field->val_int()); net_store_data(packet, table->next_number_field->val_int());
table->next_number_field=0; table->next_number_field=0;
} }
else else
net_store_null(packet); net_store_null(packet);
if (!file->create_time) if (!file->create_time)
net_store_null(packet); net_store_null(packet);
else else
{ {
localtime_r(&file->create_time,&tm_tmp); localtime_r(&file->create_time,&tm_tmp);
net_store_data(packet, &tm_tmp); net_store_data(packet, &tm_tmp);
} }
if (!file->update_time) if (!file->update_time)
net_store_null(packet); net_store_null(packet);
else else
{ {
localtime_r(&file->update_time,&tm_tmp); localtime_r(&file->update_time,&tm_tmp);
net_store_data(packet, &tm_tmp); net_store_data(packet, &tm_tmp);
} }
if (!file->check_time) if (!file->check_time)
net_store_null(packet); net_store_null(packet);
else else
{ {
localtime_r(&file->check_time,&tm_tmp); localtime_r(&file->check_time,&tm_tmp);
net_store_data(packet, &tm_tmp); net_store_data(packet, &tm_tmp);
} }
{ {
char option_buff[350],*ptr; char option_buff[350],*ptr;
ptr=option_buff; ptr=option_buff;
if (table->min_rows) if (table->min_rows)
{ {
ptr=strmov(ptr," min_rows="); ptr=strmov(ptr," min_rows=");
ptr=longlong10_to_str(table->min_rows,ptr,10); ptr=longlong10_to_str(table->min_rows,ptr,10);
} }
if (table->max_rows) if (table->max_rows)
{ {
ptr=strmov(ptr," max_rows="); ptr=strmov(ptr," max_rows=");
ptr=longlong10_to_str(table->max_rows,ptr,10); ptr=longlong10_to_str(table->max_rows,ptr,10);
} }
if (table->avg_row_length) if (table->avg_row_length)
{ {
ptr=strmov(ptr," avg_row_length="); ptr=strmov(ptr," avg_row_length=");
ptr=longlong10_to_str(table->avg_row_length,ptr,10); ptr=longlong10_to_str(table->avg_row_length,ptr,10);
} }
if (table->db_create_options & HA_OPTION_PACK_KEYS) if (table->db_create_options & HA_OPTION_PACK_KEYS)
ptr=strmov(ptr," pack_keys=1"); ptr=strmov(ptr," pack_keys=1");
if (table->db_create_options & HA_OPTION_NO_PACK_KEYS) if (table->db_create_options & HA_OPTION_NO_PACK_KEYS)
ptr=strmov(ptr," pack_keys=0"); ptr=strmov(ptr," pack_keys=0");
if (table->db_create_options & HA_OPTION_CHECKSUM) if (table->db_create_options & HA_OPTION_CHECKSUM)
ptr=strmov(ptr," checksum=1"); ptr=strmov(ptr," checksum=1");
if (table->db_create_options & HA_OPTION_DELAY_KEY_WRITE) if (table->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
ptr=strmov(ptr," delay_key_write=1"); ptr=strmov(ptr," delay_key_write=1");
if (table->row_type != ROW_TYPE_DEFAULT) if (table->row_type != ROW_TYPE_DEFAULT)
ptr=strxmov(ptr, " format=", ha_row_type[(uint) table->row_type], ptr=strxmov(ptr, " format=", ha_row_type[(uint) table->row_type],
NullS); NullS);
if (file->raid_type) if (file->raid_type)
{ {
char buff[100]; char buff[100];
sprintf(buff," raid_type=%s raid_chunks=%d raid_chunksize=%ld", sprintf(buff," raid_type=%s raid_chunks=%d raid_chunksize=%ld",
my_raid_type(file->raid_type), file->raid_chunks, file->raid_chunksize/RAID_BLOCK_SIZE); my_raid_type(file->raid_type), file->raid_chunks, file->raid_chunksize/RAID_BLOCK_SIZE);
ptr=strmov(ptr,buff); ptr=strmov(ptr,buff);
} }
net_store_data(packet, option_buff+1, net_store_data(packet, option_buff+1,
(ptr == option_buff ? 0 : (uint) (ptr-option_buff)-1)); (ptr == option_buff ? 0 : (uint) (ptr-option_buff)-1));
} }
net_store_data(packet, table->comment); net_store_data(packet, table->comment);
close_thread_tables(thd,0); close_thread_tables(thd,0);
} }
if (my_net_write(&thd->net,(char*) packet->ptr(), if (my_net_write(&thd->net,(char*) packet->ptr(),
packet->length())) packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
send_eof(&thd->net); send_eof(&thd->net);
...@@ -365,7 +365,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild) ...@@ -365,7 +365,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild)
char tmp[MAX_FIELD_WIDTH]; char tmp[MAX_FIELD_WIDTH];
DBUG_ENTER("mysqld_show_fields"); DBUG_ENTER("mysqld_show_fields");
DBUG_PRINT("enter",("db: %s table: %s",table_list->db, DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
table_list->real_name)); table_list->real_name));
if (!(table = open_ltable(thd, table_list, TL_UNLOCK))) if (!(table = open_ltable(thd, table_list, TL_UNLOCK)))
{ {
...@@ -385,7 +385,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild) ...@@ -385,7 +385,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild)
field_list.push_back(new Item_empty_string("Extra",20)); field_list.push_back(new Item_empty_string("Extra",20));
field_list.push_back(new Item_empty_string("Privileges",80)); field_list.push_back(new Item_empty_string("Privileges",80));
// Send first number of fields and records // Send first number of fields and records
{ {
char *pos; char *pos;
pos=net_store_length(tmp, (uint) field_list.elements); pos=net_store_length(tmp, (uint) field_list.elements);
...@@ -395,7 +395,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild) ...@@ -395,7 +395,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild)
if (send_fields(thd,field_list,0)) if (send_fields(thd,field_list,0))
DBUG_RETURN(1); DBUG_RETURN(1);
restore_record(table,2); // Get empty record restore_record(table,2); // Get empty record
Field **ptr,*field; Field **ptr,*field;
for (ptr=table->field; (field= *ptr) ; ptr++) for (ptr=table->field; (field= *ptr) ; ptr++)
...@@ -404,63 +404,63 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild) ...@@ -404,63 +404,63 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild)
{ {
#ifdef NOT_USED #ifdef NOT_USED
if (thd->col_access & TABLE_ACLS || if (thd->col_access & TABLE_ACLS ||
! check_grant_column(thd,table,field->field_name, ! check_grant_column(thd,table,field->field_name,
(uint) strlen(field->field_name),1)) (uint) strlen(field->field_name),1))
#endif #endif
{ {
byte *pos; byte *pos;
uint flags=field->flags; uint flags=field->flags;
String *packet= &thd->packet,type(tmp,sizeof(tmp)); String *packet= &thd->packet,type(tmp,sizeof(tmp));
uint col_access; uint col_access;
bool null_default_value=0; bool null_default_value=0;
packet->length(0); packet->length(0);
net_store_data(packet,field->field_name); net_store_data(packet,field->field_name);
field->sql_type(type); field->sql_type(type);
net_store_data(packet,type.ptr(),type.length()); net_store_data(packet,type.ptr(),type.length());
pos=(byte*) ((flags & NOT_NULL_FLAG) && pos=(byte*) ((flags & NOT_NULL_FLAG) &&
field->type() != FIELD_TYPE_TIMESTAMP ? field->type() != FIELD_TYPE_TIMESTAMP ?
"" : "YES"); "" : "YES");
net_store_data(packet,(const char*) pos); net_store_data(packet,(const char*) pos);
pos=(byte*) ((field->flags & PRI_KEY_FLAG) ? "PRI" : pos=(byte*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" : (field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":""); (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
net_store_data(packet,(char*) pos); net_store_data(packet,(char*) pos);
if (field->type() == FIELD_TYPE_TIMESTAMP || if (field->type() == FIELD_TYPE_TIMESTAMP ||
field->unireg_check == Field::NEXT_NUMBER) field->unireg_check == Field::NEXT_NUMBER)
null_default_value=1; null_default_value=1;
if (!null_default_value && !field->is_null()) if (!null_default_value && !field->is_null())
{ // Not null by default { // Not null by default
type.set(tmp,sizeof(tmp)); type.set(tmp,sizeof(tmp));
field->val_str(&type,&type); field->val_str(&type,&type);
net_store_data(packet,type.ptr(),type.length()); net_store_data(packet,type.ptr(),type.length());
} }
else if (field->maybe_null() || null_default_value) else if (field->maybe_null() || null_default_value)
net_store_null(packet); // Null as default net_store_null(packet); // Null as default
else else
net_store_data(packet,tmp,0); net_store_data(packet,tmp,0);
char *end=tmp; char *end=tmp;
if (field->unireg_check == Field::NEXT_NUMBER) if (field->unireg_check == Field::NEXT_NUMBER)
end=strmov(tmp,"auto_increment"); end=strmov(tmp,"auto_increment");
net_store_data(packet,tmp,(uint) (end-tmp)); net_store_data(packet,tmp,(uint) (end-tmp));
/* Add grant options */ /* Add grant options */
col_access= get_column_grant(thd,table_list,field) & COL_ACLS; col_access= get_column_grant(thd,table_list,field) & COL_ACLS;
end=tmp; end=tmp;
for (uint bitnr=0; col_access ; col_access>>=1,bitnr++) for (uint bitnr=0; col_access ; col_access>>=1,bitnr++)
{ {
if (col_access & 1) if (col_access & 1)
{ {
*end++=','; *end++=',';
end=strmov(end,grant_types.type_names[bitnr]); end=strmov(end,grant_types.type_names[bitnr]);
} }
} }
net_store_data(packet,tmp+1,end == tmp ? 0 : (uint) (end-tmp-1)); net_store_data(packet,tmp+1,end == tmp ? 0 : (uint) (end-tmp-1));
if (my_net_write(&thd->net,(char*) packet->ptr(),packet->length())) if (my_net_write(&thd->net,(char*) packet->ptr(),packet->length()))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
} }
} }
...@@ -474,7 +474,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) ...@@ -474,7 +474,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
TABLE *table; TABLE *table;
DBUG_ENTER("mysqld_show_create"); DBUG_ENTER("mysqld_show_create");
DBUG_PRINT("enter",("db: %s table: %s",table_list->db, DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
table_list->real_name)); table_list->real_name));
if (!(table = open_ltable(thd, table_list, TL_UNLOCK))) if (!(table = open_ltable(thd, table_list, TL_UNLOCK)))
{ {
...@@ -500,10 +500,10 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) ...@@ -500,10 +500,10 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
ulong store_len_offset = packet->length(); ulong store_len_offset = packet->length();
packet->length(store_len_offset + 4); packet->length(store_len_offset + 4);
if(store_create_info(thd, table, packet)) if(store_create_info(thd, table, packet))
DBUG_RETURN(-1); DBUG_RETURN(-1);
ulong create_len = packet->length() - store_len_offset - 4; ulong create_len = packet->length() - store_len_offset - 4;
if(create_len > 0x00ffffff) // better readable in HEX ... if(create_len > 0x00ffffff) // better readable in HEX ...
DBUG_RETURN(1); // just in case somebody manages to create a table DBUG_RETURN(1); // just in case somebody manages to create a table
// with *that* much stuff in the definition // with *that* much stuff in the definition
// now we have to store the length in three bytes, even if it would fit // now we have to store the length in three bytes, even if it would fit
...@@ -515,7 +515,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) ...@@ -515,7 +515,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
// now we are in business :-) // now we are in business :-)
if(my_net_write(&thd->net, (char*)packet->ptr(), packet->length())) if(my_net_write(&thd->net, (char*)packet->ptr(), packet->length()))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
send_eof(&thd->net); send_eof(&thd->net);
...@@ -530,7 +530,7 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list) ...@@ -530,7 +530,7 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list)
char buff[256]; char buff[256];
DBUG_ENTER("mysqld_show_keys"); DBUG_ENTER("mysqld_show_keys");
DBUG_PRINT("enter",("db: %s table: %s",table_list->db, DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
table_list->real_name)); table_list->real_name));
if (!(table = open_ltable(thd, table_list, TL_UNLOCK))) if (!(table = open_ltable(thd, table_list, TL_UNLOCK)))
{ {
...@@ -575,34 +575,34 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list) ...@@ -575,34 +575,34 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list)
end=int10_to_str((long) (j+1),(char*) buff,10); end=int10_to_str((long) (j+1),(char*) buff,10);
net_store_data(packet,buff,(uint) (end-buff)); net_store_data(packet,buff,(uint) (end-buff));
net_store_data(packet,key_part->field ? key_part->field->field_name : net_store_data(packet,key_part->field ? key_part->field->field_name :
"?unknown field?"); "?unknown field?");
if (table->file->option_flag() & HA_READ_ORDER) if (table->file->option_flag() & HA_READ_ORDER)
net_store_data(packet,((key_part->key_part_flag & HA_REVERSE_SORT) net_store_data(packet,((key_part->key_part_flag & HA_REVERSE_SORT)
? "D" : "A"), 1); ? "D" : "A"), 1);
else else
net_store_null(packet); /* purecov: inspected */ net_store_null(packet); /* purecov: inspected */
KEY *key=table->key_info+i; KEY *key=table->key_info+i;
if (key->rec_per_key[j]) if (key->rec_per_key[j])
{ {
ulong records=(table->file->records / key->rec_per_key[j]); ulong records=(table->file->records / key->rec_per_key[j]);
end=int10_to_str((long) records, buff, 10); end=int10_to_str((long) records, buff, 10);
net_store_data(packet,buff,(uint) (end-buff)); net_store_data(packet,buff,(uint) (end-buff));
} }
else else
net_store_null(packet); net_store_null(packet);
if (!key_part->field || if (!key_part->field ||
key_part->length != key_part->length !=
table->field[key_part->fieldnr-1]->key_length()) table->field[key_part->fieldnr-1]->key_length())
{ {
end=int10_to_str((long) key_part->length, buff,10); /* purecov: inspected */ end=int10_to_str((long) key_part->length, buff,10); /* purecov: inspected */
net_store_data(packet,buff,(uint) (end-buff)); /* purecov: inspected */ net_store_data(packet,buff,(uint) (end-buff)); /* purecov: inspected */
} }
else else
net_store_null(packet); net_store_null(packet);
net_store_null(packet); // No pack_information yet net_store_null(packet); // No pack_information yet
net_store_null(packet); // No comments yet net_store_null(packet); // No comments yet
if (my_net_write(&thd->net,(char*) packet->ptr(),packet->length())) if (my_net_write(&thd->net,(char*) packet->ptr(),packet->length()))
DBUG_RETURN(1); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */
} }
} }
send_eof(&thd->net); send_eof(&thd->net);
...@@ -635,7 +635,7 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild) ...@@ -635,7 +635,7 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
if (!wild || !wild[0] || !wild_case_compare(field->field_name,wild)) if (!wild || !wild[0] || !wild_case_compare(field->field_name,wild))
field_list.push_back(new Item_field(field)); field_list.push_back(new Item_field(field));
} }
restore_record(table,2); // Get empty record restore_record(table,2); // Get empty record
if (send_fields(thd,field_list,2)) if (send_fields(thd,field_list,2))
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
VOID(net_flush(&thd->net)); VOID(net_flush(&thd->net));
...@@ -654,17 +654,17 @@ mysqld_dump_create_info(THD *thd, TABLE *table, int fd) ...@@ -654,17 +654,17 @@ mysqld_dump_create_info(THD *thd, TABLE *table, int fd)
DBUG_RETURN(-1); DBUG_RETURN(-1);
if(fd < 0) if(fd < 0)
{ {
if(my_net_write(&thd->net, (char*)packet->ptr(), packet->length())) if(my_net_write(&thd->net, (char*)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
VOID(net_flush(&thd->net)); VOID(net_flush(&thd->net));
} }
else else
{ {
if(my_write(fd, (const byte*) packet->ptr(), packet->length(), if(my_write(fd, (const byte*) packet->ptr(), packet->length(),
MYF(MY_WME))) MYF(MY_WME)))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -680,17 +680,18 @@ store_create_info(THD *thd, TABLE *table, String* packet) ...@@ -680,17 +680,18 @@ store_create_info(THD *thd, TABLE *table, String* packet)
List<Item> field_list; List<Item> field_list;
char tmp[MAX_FIELD_WIDTH]; char tmp[MAX_FIELD_WIDTH];
String type(tmp, sizeof(tmp)); String type(tmp, sizeof(tmp));
packet->append("create table ", 13); packet->append("CREATE TABLE ", 13);
packet->append(table->real_name); packet->append(table->real_name);
packet->append('('); packet->append(" (\n", 3);
Field **ptr,*field; Field **ptr,*field;
for (ptr=table->field ; (field= *ptr); ptr++) for (ptr=table->field ; (field= *ptr); ptr++)
{ {
if(ptr != table->field) if(ptr != table->field)
packet->append(','); packet->append(",\n", 2);
uint flags = field->flags; uint flags = field->flags;
packet->append(" ", 2);
packet->append(field->field_name); packet->append(field->field_name);
packet->append(' '); packet->append(' ');
// check for surprises from the previous call to Field::sql_type() // check for surprises from the previous call to Field::sql_type()
...@@ -701,34 +702,31 @@ store_create_info(THD *thd, TABLE *table, String* packet) ...@@ -701,34 +702,31 @@ store_create_info(THD *thd, TABLE *table, String* packet)
packet->append(type.ptr(),type.length()); packet->append(type.ptr(),type.length());
bool null_default_value = (field->type() == FIELD_TYPE_TIMESTAMP || bool null_default_value = (field->type() == FIELD_TYPE_TIMESTAMP ||
field->unireg_check == Field::NEXT_NUMBER); field->unireg_check == Field::NEXT_NUMBER);
bool has_default = (field->type() != FIELD_TYPE_BLOB); bool has_default = (field->type() != FIELD_TYPE_BLOB);
if((flags & NOT_NULL_FLAG) && !null_default_value) if((flags & NOT_NULL_FLAG) && !null_default_value)
packet->append(" not null", 9); packet->append(" NOT NULL", 9);
if(has_default) if(has_default)
{ {
packet->append(" default ", 9); packet->append(" default ", 9);
if (!null_default_value && !field->is_null()) if (!null_default_value && !field->is_null())
{ // Not null by default { // Not null by default
type.set(tmp,sizeof(tmp)); type.set(tmp,sizeof(tmp));
field->val_str(&type,&type); field->val_str(&type,&type);
packet->append('\''); packet->append('\'');
packet->append(type.ptr(),type.length()); packet->append(type.ptr(),type.length());
packet->append('\''); packet->append('\'');
}
else if (field->maybe_null() || null_default_value)
packet->append("NULL", 4); // Null as default
else
packet->append(tmp,0);
} }
else if (field->maybe_null() || null_default_value)
packet->append("NULL", 4); // Null as default
else
packet->append(tmp,0);
}
if (field->unireg_check == Field::NEXT_NUMBER) if (field->unireg_check == Field::NEXT_NUMBER)
packet->append(" auto_increment", 15 ); packet->append(" auto_increment", 15 );
} }
KEY *key_info=table->key_info; KEY *key_info=table->key_info;
...@@ -737,16 +735,16 @@ store_create_info(THD *thd, TABLE *table, String* packet) ...@@ -737,16 +735,16 @@ store_create_info(THD *thd, TABLE *table, String* packet)
for (uint i=0 ; i < table->keys ; i++,key_info++) for (uint i=0 ; i < table->keys ; i++,key_info++)
{ {
packet->append(','); packet->append(",\n ", 4);
KEY_PART_INFO *key_part= key_info->key_part; KEY_PART_INFO *key_part= key_info->key_part;
if(i == primary_key) if(i == primary_key)
packet->append("primary", 7); packet->append("PRIMARY ", 8);
else if(key_info->flags & HA_NOSAME) else if(key_info->flags & HA_NOSAME)
packet->append("unique", 6); packet->append("UNIQUE ", 7);
else if(key_info->flags & HA_FULLTEXT) else if(key_info->flags & HA_FULLTEXT)
packet->append("fulltext", 8); packet->append("FULLTEXT ", 9);
packet->append(" key ", 5); packet->append("KEY ", 4);
if(i != primary_key) if(i != primary_key)
packet->append(key_info->name); packet->append(key_info->name);
...@@ -756,58 +754,56 @@ store_create_info(THD *thd, TABLE *table, String* packet) ...@@ -756,58 +754,56 @@ store_create_info(THD *thd, TABLE *table, String* packet)
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++) for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
{ {
if(j) if(j)
packet->append(','); packet->append(',');
if(key_part->field) if(key_part->field)
packet->append(key_part->field->field_name); packet->append(key_part->field->field_name);
KEY *key=table->key_info+i; KEY *key=table->key_info+i;
if (!key_part->field || if (!key_part->field ||
(key_part->length != (key_part->length !=
table->field[key_part->fieldnr-1]->key_length() && table->field[key_part->fieldnr-1]->key_length() &&
!(key_info->flags & HA_FULLTEXT))) !(key_info->flags & HA_FULLTEXT)))
{ {
char buff[64]; char buff[64];
buff[0] = '('; buff[0] = '(';
char* end=int10_to_str((long) key_part->length, buff + 1,10); char* end=int10_to_str((long) key_part->length, buff + 1,10);
*end++ = ')'; *end++ = ')';
packet->append(buff,(uint) (end-buff)); packet->append(buff,(uint) (end-buff));
} }
} }
packet->append(')'); packet->append(')');
} }
packet->append("\n)", 2);
packet->append(')');
handler *file = table->file; handler *file = table->file;
packet->append(" type=", 6); packet->append(" TYPE=", 6);
packet->append(file->table_type()); packet->append(file->table_type());
char buff[128]; char buff[128];
char* p; char* p;
if(table->min_rows) if(table->min_rows)
{ {
packet->append(" min_rows="); packet->append(" MIN_ROWS=");
p = longlong10_to_str(table->min_rows, buff, 10); p = longlong10_to_str(table->min_rows, buff, 10);
packet->append(buff, (uint) (p - buff)); packet->append(buff, (uint) (p - buff));
} }
if(table->max_rows) if(table->max_rows)
{ {
packet->append(" max_rows="); packet->append(" MAX_ROWS=");
p = longlong10_to_str(table->max_rows, buff, 10); p = longlong10_to_str(table->max_rows, buff, 10);
packet->append(buff, (uint) (p - buff)); packet->append(buff, (uint) (p - buff));
} }
if (table->db_create_options & HA_OPTION_PACK_KEYS) if (table->db_create_options & HA_OPTION_PACK_KEYS)
packet->append(" pack_keys=1", 12); packet->append(" PACK_KEYS=1", 12);
if (table->db_create_options & HA_OPTION_NO_PACK_KEYS) if (table->db_create_options & HA_OPTION_NO_PACK_KEYS)
packet->append(" pack_keys=0", 12); packet->append(" PACK_KEYS=0", 12);
if (table->db_create_options & HA_OPTION_CHECKSUM) if (table->db_create_options & HA_OPTION_CHECKSUM)
packet->append(" checksum=1", 11); packet->append(" CHECKSUM=1", 11);
if (table->db_create_options & HA_OPTION_DELAY_KEY_WRITE) if (table->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
packet->append(" delay_key_write=1",18); packet->append(" DELAY_KEY_WRITE=1",18);
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -823,11 +819,11 @@ class thread_info :public ilink { ...@@ -823,11 +819,11 @@ class thread_info :public ilink {
public: public:
static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); } static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); }
static void operator delete(void *ptr __attribute__((unused)), static void operator delete(void *ptr __attribute__((unused)),
size_t size __attribute__((unused))) {} /*lint -e715 */ size_t size __attribute__((unused))) {} /*lint -e715 */
ulong thread_id; ulong thread_id;
time_t start_time; time_t start_time;
uint command; uint command;
const char *user,*host,*db,*proc_info,*state_info; const char *user,*host,*db,*proc_info,*state_info;
char *query; char *query;
}; };
...@@ -867,49 +863,49 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) ...@@ -867,49 +863,49 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
while ((tmp=it++)) while ((tmp=it++))
{ {
if ((tmp->net.vio || tmp->system_thread) && if ((tmp->net.vio || tmp->system_thread) &&
(!user || (tmp->user && !strcmp(tmp->user,user)))) (!user || (tmp->user && !strcmp(tmp->user,user))))
{ {
thread_info *thd_info=new thread_info; thread_info *thd_info=new thread_info;
thd_info->thread_id=tmp->thread_id; thd_info->thread_id=tmp->thread_id;
thd_info->user=thd->strdup(tmp->user ? tmp->user : (tmp->system_thread ? thd_info->user=thd->strdup(tmp->user ? tmp->user : (tmp->system_thread ?
"system user" : "unauthenticated user")); "system user" : "unauthenticated user"));
thd_info->host=thd->strdup(tmp->host ? tmp->host : (tmp->ip ? tmp->ip : thd_info->host=thd->strdup(tmp->host ? tmp->host : (tmp->ip ? tmp->ip :
(tmp->system_thread ? "none" : "connecting host"))); (tmp->system_thread ? "none" : "connecting host")));
if ((thd_info->db=tmp->db)) // Safe test if ((thd_info->db=tmp->db)) // Safe test
thd_info->db=thd->strdup(thd_info->db); thd_info->db=thd->strdup(thd_info->db);
thd_info->command=(int) tmp->command; thd_info->command=(int) tmp->command;
if (tmp->mysys_var) if (tmp->mysys_var)
pthread_mutex_lock(&tmp->mysys_var->mutex); pthread_mutex_lock(&tmp->mysys_var->mutex);
thd_info->proc_info= (char*) (tmp->killed ? "Killed" : 0); thd_info->proc_info= (char*) (tmp->killed ? "Killed" : 0);
thd_info->state_info= (char*) (tmp->locked ? "Locked" : thd_info->state_info= (char*) (tmp->locked ? "Locked" :
tmp->net.reading_or_writing ? tmp->net.reading_or_writing ?
(tmp->net.reading_or_writing == 2 ? (tmp->net.reading_or_writing == 2 ?
"Writing to net" : "Writing to net" :
thd_info->command == COM_SLEEP ? "" : thd_info->command == COM_SLEEP ? "" :
"Reading from net") : "Reading from net") :
tmp->proc_info ? tmp->proc_info : tmp->proc_info ? tmp->proc_info :
tmp->mysys_var && tmp->mysys_var &&
tmp->mysys_var->current_cond ? tmp->mysys_var->current_cond ?
"Waiting on cond" : NullS); "Waiting on cond" : NullS);
if (tmp->mysys_var) if (tmp->mysys_var)
pthread_mutex_unlock(&tmp->mysys_var->mutex); pthread_mutex_unlock(&tmp->mysys_var->mutex);
#if !defined(DONT_USE_THR_ALARM) && ! defined(SCO) #if !defined(DONT_USE_THR_ALARM) && ! defined(SCO)
if (pthread_kill(tmp->real_id,0)) if (pthread_kill(tmp->real_id,0))
tmp->proc_info="*** DEAD ***"; // This shouldn't happen tmp->proc_info="*** DEAD ***"; // This shouldn't happen
#endif #endif
thd_info->start_time= tmp->start_time; thd_info->start_time= tmp->start_time;
thd_info->query=0; thd_info->query=0;
if (tmp->query) if (tmp->query)
{ {
uint length=(uint) strlen(tmp->query); uint length=(uint) strlen(tmp->query);
if (length > max_query_length) if (length > max_query_length)
length=max_query_length; length=max_query_length;
thd_info->query=(char*) thd->memdup(tmp->query,length+1); thd_info->query=(char*) thd->memdup(tmp->query,length+1);
thd_info->query[length]=0; thd_info->query[length]=0;
} }
thread_infos.append(thd_info); thread_infos.append(thd_info);
} }
} }
} }
...@@ -935,7 +931,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) ...@@ -935,7 +931,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
net_store_data(packet,command_name[thd_info->command]); net_store_data(packet,command_name[thd_info->command]);
if (thd_info->start_time) if (thd_info->start_time)
net_store_data(packet,(uint32) net_store_data(packet,(uint32)
(time((time_t*) 0) - thd_info->start_time)); (time((time_t*) 0) - thd_info->start_time));
else else
net_store_null(packet); net_store_null(packet);
if (thd_info->state_info) if (thd_info->state_info)
...@@ -982,41 +978,41 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables) ...@@ -982,41 +978,41 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables)
switch (variables[i].type){ switch (variables[i].type){
case SHOW_LONG: case SHOW_LONG:
case SHOW_LONG_CONST: case SHOW_LONG_CONST:
net_store_data(&packet2,(uint32) *(ulong*) variables[i].value); net_store_data(&packet2,(uint32) *(ulong*) variables[i].value);
break; break;
case SHOW_BOOL: case SHOW_BOOL:
net_store_data(&packet2,(ulong) *(bool*) variables[i].value ? net_store_data(&packet2,(ulong) *(bool*) variables[i].value ?
"ON" : "OFF"); "ON" : "OFF");
break; break;
case SHOW_MY_BOOL: case SHOW_MY_BOOL:
net_store_data(&packet2,(ulong) *(my_bool*) variables[i].value ? net_store_data(&packet2,(ulong) *(my_bool*) variables[i].value ?
"ON" : "OFF"); "ON" : "OFF");
break; break;
case SHOW_INT_CONST: case SHOW_INT_CONST:
case SHOW_INT: case SHOW_INT:
net_store_data(&packet2,(uint32) *(int*) variables[i].value); net_store_data(&packet2,(uint32) *(int*) variables[i].value);
break; break;
case SHOW_CHAR: case SHOW_CHAR:
net_store_data(&packet2,variables[i].value); net_store_data(&packet2,variables[i].value);
break; break;
case SHOW_STARTTIME: case SHOW_STARTTIME:
net_store_data(&packet2,(uint32) (thd->query_start() - start_time)); net_store_data(&packet2,(uint32) (thd->query_start() - start_time));
break; break;
case SHOW_QUESTION: case SHOW_QUESTION:
net_store_data(&packet2,(uint32) thd->query_id); net_store_data(&packet2,(uint32) thd->query_id);
break; break;
case SHOW_OPENTABLES: case SHOW_OPENTABLES:
net_store_data(&packet2,(uint32) cached_tables()); net_store_data(&packet2,(uint32) cached_tables());
break; break;
case SHOW_CHAR_PTR: case SHOW_CHAR_PTR:
{ {
char *value= *(char**) variables[i].value; char *value= *(char**) variables[i].value;
net_store_data(&packet2,value ? value : ""); net_store_data(&packet2,value ? value : "");
break; break;
} }
} }
if (my_net_write(&thd->net, (char*) packet2.ptr(),packet2.length())) if (my_net_write(&thd->net, (char*) packet2.ptr(),packet2.length()))
goto err; /* purecov: inspected */ goto err; /* purecov: inspected */
} }
} }
pthread_mutex_unlock(&LOCK_status); pthread_mutex_unlock(&LOCK_status);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment