From 5bc4965d70c0a0340c8ab34deabe4b9ca4dd6ae6 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Thu, 21 Aug 2003 20:21:07 +0200 Subject: fix for SHOW CREATE TABLE to report corerct second field's length --- sql/item.cc | 5 +++++ sql/sql_show.cc | 70 ++++++++++++++++++++++++++++----------------------------- 2 files changed, 39 insertions(+), 36 deletions(-) (limited to 'sql') diff --git a/sql/item.cc b/sql/item.cc index a2d9f0b2575..a09aa9962bc 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -355,6 +355,11 @@ void Item_string::make_field(Send_field *tmp_field) init_make_field(tmp_field,FIELD_TYPE_STRING); } +void Item_empty_string::make_field(Send_field *tmp_field) +{ + init_make_field(tmp_field,FIELD_TYPE_VAR_STRING); +} + void Item_datetime::make_field(Send_field *tmp_field) { init_make_field(tmp_field,FIELD_TYPE_DATETIME); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index dc81510051b..6acdb1cc72b 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -564,49 +564,47 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) DBUG_RETURN(1); } + String packet; + packet.length(0); + net_store_data(&packet, table->table_name); + /* + A hack - we need to reserve some space for the length before + we know what it is - let's assume that the length of create table + statement will fit into 3 bytes ( 16 MB max :-) ) + */ + ulong store_len_offset = packet.length(); + packet.length(store_len_offset + 4); + if (store_create_info(thd, table, &packet)) + DBUG_RETURN(-1); + ulong create_len = packet.length() - store_len_offset - 4; + if (create_len > 0x00ffffff) // better readable in HEX ... + { + /* + Just in case somebody manages to create a table + with *that* much stuff in the definition + */ + DBUG_RETURN(1); + } + + /* + Now we have to store the length in three bytes, even if it would fit + into fewer bytes, so we cannot use net_store_data() anymore, + and do it ourselves + */ + char* p = (char*)packet.ptr() + store_len_offset; + *p++ = (char) 253; // The client the length is stored using 3-bytes + int3store(p, create_len); + List field_list; field_list.push_back(new Item_empty_string("Table",NAME_LEN)); - field_list.push_back(new Item_empty_string("Create Table",1024)); + field_list.push_back(new Item_empty_string("Create Table",packet.length())); if (send_fields(thd,field_list,1)) DBUG_RETURN(1); - String *packet = &thd->packet; - { - packet->length(0); - net_store_data(packet, table->table_name); - /* - A hack - we need to reserve some space for the length before - we know what it is - let's assume that the length of create table - statement will fit into 3 bytes ( 16 MB max :-) ) - */ - ulong store_len_offset = packet->length(); - packet->length(store_len_offset + 4); - if (store_create_info(thd, table, packet)) - DBUG_RETURN(-1); - ulong create_len = packet->length() - store_len_offset - 4; - if (create_len > 0x00ffffff) // better readable in HEX ... - { - /* - Just in case somebody manages to create a table - with *that* much stuff in the definition - */ - DBUG_RETURN(1); - } - - /* - Now we have to store the length in three bytes, even if it would fit - into fewer bytes, so we cannot use net_store_data() anymore, - and do it ourselves - */ - char* p = (char*)packet->ptr() + store_len_offset; - *p++ = (char) 253; // The client the length is stored using 3-bytes - int3store(p, create_len); + if (my_net_write(&thd->net, (char*)packet.ptr(), packet.length())) + DBUG_RETURN(1); - // now we are in business :-) - if (my_net_write(&thd->net, (char*)packet->ptr(), packet->length())) - DBUG_RETURN(1); - } send_eof(&thd->net); DBUG_RETURN(0); } -- cgit v1.2.1 From 7f1ffcc453a47d9ccc344498db4556a09a7cdb6e Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Thu, 21 Aug 2003 21:14:02 +0200 Subject: Bug #1064: SHOW CREATE TABLE: avoid allocations for simple tables, old client compatibility --- sql/item.h | 1 + sql/sql_show.cc | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'sql') diff --git a/sql/item.h b/sql/item.h index 3cf5a17805c..d9d125b8bd4 100644 --- a/sql/item.h +++ b/sql/item.h @@ -275,6 +275,7 @@ class Item_empty_string :public Item_string public: Item_empty_string(const char *header,uint length) :Item_string("",0) { name=(char*) header; max_length=length;} + void make_field(Send_field *field); }; class Item_varbinary :public Item diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 6acdb1cc72b..f2d6dd8e058 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -564,7 +564,8 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) DBUG_RETURN(1); } - String packet; + char buff[1024]; + String packet(buff,sizeof(buff)); packet.length(0); net_store_data(&packet, table->table_name); /* @@ -597,7 +598,8 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) List field_list; field_list.push_back(new Item_empty_string("Table",NAME_LEN)); - field_list.push_back(new Item_empty_string("Create Table",packet.length())); + field_list.push_back(new Item_empty_string("Create Table", + max(packet.length(),1024))); // 1024 is for not to confuse old clients if (send_fields(thd,field_list,1)) DBUG_RETURN(1); -- cgit v1.2.1