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
...@@ -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()
...@@ -705,8 +706,7 @@ store_create_info(THD *thd, TABLE *table, String* packet) ...@@ -705,8 +706,7 @@ store_create_info(THD *thd, TABLE *table, String* packet)
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)
{ {
...@@ -727,8 +727,6 @@ store_create_info(THD *thd, TABLE *table, String* packet) ...@@ -727,8 +727,6 @@ store_create_info(THD *thd, TABLE *table, String* packet)
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);
...@@ -774,40 +772,38 @@ store_create_info(THD *thd, TABLE *table, String* packet) ...@@ -774,40 +772,38 @@ store_create_info(THD *thd, TABLE *table, String* packet)
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);
......
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