diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index f3dcdf6639922073b2582af831c43cbab3dc3b8e..9ebf33be5bdd5db5f22b8527c81b5f6197f7d12a 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1,16 +1,16 @@ grant all privileges on test.* to mysqltest_1@localhost; select * from information_schema.SCHEMATA where schema_name > 'm'; -CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME -NULL mysql latin1 -NULL test latin1 +CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME SQL_PATH +NULL mysql latin1 NULL +NULL test latin1 NULL select schema_name from information_schema.schemata; schema_name mysql test show databases *; -CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME -NULL mysql latin1 -NULL test latin1 +CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME SQL_PATH +NULL mysql latin1 NULL +NULL test latin1 NULL show databases like 't%'; Database (t%) test @@ -19,10 +19,10 @@ Database mysql test show databases * where schema_name like 't%'; -CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME -NULL test latin1 +CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME SQL_PATH +NULL test latin1 NULL show databases * where schema_name = 't%'; -CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME +CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME SQL_PATH create database testtets; create table testtets.t1(a int, b VARCHAR(30), KEY string_data (b)); create table test.t2(a int); @@ -119,24 +119,24 @@ Field Type Collation Null Key Default Extra Privileges Comment c char(64) utf8_general_ci select,insert,update,references select * from information_schema.COLUMNS where table_name="t1" and column_name= "a"; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME TYPE COLLATION_NAME IS_NULLABLE KEY COLUMN_DEFAULT EXTRA PRIVILEGES COMMENT -NULL testtets t1 a 1 int 0 11 4 0 NULL int(11) NULL YES NULL select,insert,update,references +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA PRIVILEGES COLUMN_COMMENT +NULL testtets t1 a 1 NULL YES int 11 11 11 0 NULL NULL int(11) select,insert,update,references show columns * where table_name = "t1"; -TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME TYPE COLLATION_NAME IS_NULLABLE KEY COLUMN_DEFAULT EXTRA PRIVILEGES COMMENT -NULL testtets t1 a 1 int 0 11 4 0 NULL int(11) NULL YES NULL select,insert,update,references -NULL testtets t1 b 2 varchar 30 30 30 31 latin1 varchar(30) latin1_swedish_ci YES MUL NULL select,insert,update,references +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA PRIVILEGES COLUMN_COMMENT +NULL testtets t1 a 1 NULL YES int 11 11 11 0 NULL NULL int(11) select,insert,update,references +NULL testtets t1 b 2 NULL YES varchar 30 30 NULL NULL latin1 latin1_swedish_ci varchar(30) MUL select,insert,update,references drop view v1; drop tables testtets.t4, testtets.t1, t2, t3; drop database testtets; select * from information_schema.CHARACTER_SETS where CHARACTER_SET_NAME like 'latin1%'; -CHARACTER_SET_NAME Description DEFAULT_COLLATE_NAME Maxlen +CHARACTER_SET_NAME DESCRIPTION DEFAULT_COLLATE_NAME MAXLEN latin1 ISO 8859-1 West European latin1_swedish_ci 1 SHOW CHARACTER SET LIKE 'latin1%'; Charset Description Default collation Maxlen latin1 ISO 8859-1 West European latin1_swedish_ci 1 SHOW CHARACTER SET * LIKE 'latin1%'; -CHARACTER_SET_NAME Description DEFAULT_COLLATE_NAME Maxlen +CHARACTER_SET_NAME DESCRIPTION DEFAULT_COLLATE_NAME MAXLEN latin1 ISO 8859-1 West European latin1_swedish_ci 1 SHOW CHARACTER SET WHERE CHARACTER_SET_NAME like 'latin1%'; Charset Description Default collation Maxlen @@ -145,11 +145,11 @@ SHOW CHARACTER SET CHARACTER_SET_NAME WHERE CHARACTER_SET_NAME like 'latin1%'; CHARACTER_SET_NAME latin1 SHOW CHARACTER SET * WHERE CHARACTER_SET_NAME like 'latin1%'; -CHARACTER_SET_NAME Description DEFAULT_COLLATE_NAME Maxlen +CHARACTER_SET_NAME DESCRIPTION DEFAULT_COLLATE_NAME MAXLEN latin1 ISO 8859-1 West European latin1_swedish_ci 1 select * from information_schema.COLLATIONS where COLLATION_NAME like 'latin1%'; -COLLATION_NAME Charset Id Default Compiled Sortlen +COLLATION_NAME CHARSET ID DEFAULT COMPILED SORTLEN latin1_german1_ci latin1 5 0 latin1_swedish_ci latin1 8 Yes Yes 1 latin1_danish_ci latin1 15 0 @@ -169,7 +169,7 @@ latin1_general_ci latin1 48 0 latin1_general_cs latin1 49 0 latin1_spanish_ci latin1 94 0 SHOW COLLATION * LIKE 'latin1%'; -COLLATION_NAME Charset Id Default Compiled Sortlen +COLLATION_NAME CHARSET ID DEFAULT COMPILED SORTLEN latin1_german1_ci latin1 5 0 latin1_swedish_ci latin1 8 Yes Yes 1 latin1_danish_ci latin1 15 0 @@ -199,7 +199,7 @@ latin1_general_ci latin1_general_cs latin1_spanish_ci SHOW COLLATION * WHERE COLLATION_NAME like 'latin1%'; -COLLATION_NAME Charset Id Default Compiled Sortlen +COLLATION_NAME CHARSET ID DEFAULT COMPILED SORTLEN latin1_german1_ci latin1 5 0 latin1_swedish_ci latin1 8 Yes Yes 1 latin1_danish_ci latin1 15 0 @@ -358,11 +358,11 @@ NULL test key_1 test t1 UNIQUE NULL NULL test key_2 test t1 UNIQUE NULL select * from information_schema.KEY_COLUMN_USAGE where TABLE_SCHEMA= "test"; -CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME -NULL test PRIMARY test t1 a 1 NULL NULL NULL -NULL test constraint_1 test t1 a 1 NULL NULL NULL -NULL test key_1 test t1 a 1 NULL NULL NULL -NULL test key_2 test t1 a 1 NULL NULL NULL +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME +NULL test PRIMARY NULL test t1 a 1 NULL NULL NULL +NULL test constraint_1 NULL test t1 a 1 NULL NULL NULL +NULL test key_1 NULL test t1 a 1 NULL NULL NULL +NULL test key_2 NULL test t1 a 1 NULL NULL NULL drop table t1; CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB; CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), @@ -377,11 +377,11 @@ NULL test t2_ibfk_1 test t2 FOREIGN KEY ON DELETE CASCADE NULL test t2_ibfk_2 test t2 FOREIGN KEY ON UPDATE CASCADE select * from information_schema.KEY_COLUMN_USAGE where TABLE_SCHEMA= "test"; -CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME -NULL test PRIMARY test t1 id 1 NULL NULL NULL -NULL test PRIMARY test t2 id 1 NULL NULL NULL -NULL test t2_ibfk_1 test t2 t1_id 1 test t1 id -NULL test t2_ibfk_2 test t2 t1_id 1 test t1 id +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME +NULL test PRIMARY NULL test t1 id 1 NULL NULL NULL +NULL test PRIMARY NULL test t2 id 1 NULL NULL NULL +NULL test t2_ibfk_1 NULL test t2 t1_id 1 NULL id +NULL test t2_ibfk_2 NULL test t2 t1_id 1 NULL id select table_name from information_schema.TABLES where table_schema like "test%"; table_name t1 @@ -439,6 +439,9 @@ v call px5()// v 9 +select sql_mode from information_schema.ROUTINES; +sql_mode + create table t1 (a int not null auto_increment,b int, primary key (a)); insert into t1 values (1,1),(NULL,3),(NULL,4); select AUTO_INCREMENT from information_schema.tables where table_name = 't1'; @@ -457,32 +460,51 @@ SHOW CREATE TABLE INFORMATION_SCHEMA.CHARACTER_SETS; Table Create Table CHARACTER_SETS CREATE TEMPORARY TABLE `CHARACTER_SETS` ( `CHARACTER_SET_NAME` char(30) NOT NULL default '', - `Description` char(60) NOT NULL default '', + `DESCRIPTION` char(60) NOT NULL default '', `DEFAULT_COLLATE_NAME` char(60) NOT NULL default '', - `Maxlen` bigint(3) NOT NULL default '0' + `MAXLEN` bigint(3) NOT NULL default '0' ) ENGINE=HEAP DEFAULT CHARSET=utf8 MAX_ROWS=2282 set names latin2; SHOW CREATE TABLE INFORMATION_SCHEMA.CHARACTER_SETS; Table Create Table CHARACTER_SETS CREATE TEMPORARY TABLE `CHARACTER_SETS` ( `CHARACTER_SET_NAME` char(30) NOT NULL default '', - `Description` char(60) NOT NULL default '', + `DESCRIPTION` char(60) NOT NULL default '', `DEFAULT_COLLATE_NAME` char(60) NOT NULL default '', - `Maxlen` bigint(3) NOT NULL default '0' + `MAXLEN` bigint(3) NOT NULL default '0' ) ENGINE=HEAP DEFAULT CHARSET=utf8 MAX_ROWS=2282 set names latin1; create table t1 select * from information_schema.CHARACTER_SETS where CHARACTER_SET_NAME like "latin1"; select * from t1; -CHARACTER_SET_NAME Description DEFAULT_COLLATE_NAME Maxlen +CHARACTER_SET_NAME DESCRIPTION DEFAULT_COLLATE_NAME MAXLEN latin1 ISO 8859-1 West European latin1_swedish_ci 1 alter table t1 default character set utf8; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `CHARACTER_SET_NAME` char(30) NOT NULL default '', - `Description` char(60) NOT NULL default '', + `DESCRIPTION` char(60) NOT NULL default '', `DEFAULT_COLLATE_NAME` char(60) NOT NULL default '', - `Maxlen` bigint(3) NOT NULL default '0' + `MAXLEN` bigint(3) NOT NULL default '0' ) ENGINE=MyISAM DEFAULT CHARSET=utf8 drop table t1; +create view v1 as select * from information_schema.TABLES; +drop view v1; +create table t1(a NUMERIC(5,3), b NUMERIC(5,1), c float(5,2), +d NUMERIC(6,4), e float, f DECIMAL(6,3), g int(11), h DOUBLE(10,3), +i DOUBLE); +select COLUMN_NAME,COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH, +CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE +from information_schema.columns where table_name= 't1'; +COLUMN_NAME COLUMN_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE +a decimal(5,3) 7 7 5 3 +b decimal(5,1) 7 7 5 1 +c float(5,2) 5 5 5 2 +d decimal(6,4) 8 8 6 4 +e float 12 12 12 NULL +f decimal(6,3) 8 8 6 3 +g int(11) 11 11 11 0 +h double(10,3) 10 10 10 3 +i double 22 22 22 NULL +drop table t1; diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 5132717707e907e60453b71de9294ef753d9f39c..ce8dc0290e94250c434b9612a72d3f684046c38a 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -217,6 +217,7 @@ end;// call px5()// call px5()// delimiter ;// +select sql_mode from information_schema.ROUTINES; create table t1 (a int not null auto_increment,b int, primary key (a)); insert into t1 values (1,1),(NULL,3),(NULL,4); @@ -240,5 +241,14 @@ where CHARACTER_SET_NAME like "latin1"; select * from t1; alter table t1 default character set utf8; show create table t1; -drop table t1; +drop table t1; +create view v1 as select * from information_schema.TABLES; +drop view v1; +create table t1(a NUMERIC(5,3), b NUMERIC(5,1), c float(5,2), + d NUMERIC(6,4), e float, f DECIMAL(6,3), g int(11), h DOUBLE(10,3), + i DOUBLE); +select COLUMN_NAME,COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH, + CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE +from information_schema.columns where table_name= 't1'; +drop table t1; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 720d09b454fcbfa43b10b1d87e8af7fae10eba8d..1642a2eaa1794c59ef3626240d284867e0b105f3 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2297,17 +2297,16 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables, cs); table->field[4]->store((longlong) count); field->sql_type(type); - table->field[11]->store(type.ptr(), type.length(), cs); + table->field[14]->store(type.ptr(), type.length(), cs); tmp_buff= strchr(type.ptr(),'('); - table->field[5]->store(type.ptr(), + table->field[7]->store(type.ptr(), (tmp_buff ? tmp_buff - type.ptr() : type.length()), cs); - if (show_table->timestamp_field == field && field->unireg_check != Field::TIMESTAMP_UN_FIELD) { - table->field[15]->store("CURRENT_TIMESTAMP", 17, cs); - table->field[15]->set_notnull(); + table->field[5]->store("CURRENT_TIMESTAMP", 17, cs); + table->field[5]->set_notnull(); } else if (field->unireg_check != Field::NEXT_NUMBER && !field->is_null() && @@ -2318,46 +2317,77 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables, field->val_str(&type); uint dummy_errors; def.copy(type.ptr(), type.length(), type.charset(), cs, &dummy_errors); - table->field[15]->store(def.ptr(), def.length(), def.charset()); - table->field[15]->set_notnull(); + table->field[5]->store(def.ptr(), def.length(), def.charset()); + table->field[5]->set_notnull(); } else if (field->unireg_check == Field::NEXT_NUMBER || field->maybe_null()) - table->field[15]->set_null(); // Null as default + table->field[5]->set_null(); // Null as default else { - table->field[15]->store("",0, cs); - table->field[15]->set_notnull(); + table->field[5]->store("",0, cs); + table->field[5]->set_notnull(); } - pos=(byte*) ((flags & NOT_NULL_FLAG) && field->type() != FIELD_TYPE_TIMESTAMP ? "" : "YES"); - table->field[13]->store((const char*) pos, - strlen((const char*) pos), cs); + table->field[6]->store((const char*) pos, + strlen((const char*) pos), cs); if (field->has_charset()) - { - table->field[6]->store((longlong) field->field_length/ + table->field[8]->store((longlong) field->field_length/ field->charset()->mbmaxlen); + else + table->field[8]->store((longlong) field->field_length); + table->field[9]->store((longlong) field->field_length); + + { + uint dec =field->decimals(); + switch (field->type()) { + case FIELD_TYPE_DECIMAL: + { + uint int_part=field->field_length - (dec ? dec + 1 : 0); + table->field[10]->store((longlong) (int_part + dec - 1)); + table->field[10]->set_notnull(); + table->field[11]->store((longlong) field->decimals()); + table->field[11]->set_notnull(); + } + break; + case FIELD_TYPE_TINY: + case FIELD_TYPE_SHORT: + case FIELD_TYPE_LONG: + case FIELD_TYPE_LONGLONG: + case FIELD_TYPE_INT24: + case FIELD_TYPE_FLOAT: + case FIELD_TYPE_DOUBLE: + { + table->field[10]->store((longlong) field->field_length); + table->field[10]->set_notnull(); + if (dec != NOT_FIXED_DEC) + { + table->field[11]->store((longlong) dec); + table->field[11]->set_notnull(); + } + } + break; + default: + break; + } } - table->field[7]->store((longlong) field->field_length); - table->field[8]->store((longlong) field->pack_length()); - table->field[9]->store((longlong) field->decimals()); if (field->has_charset()) { pos=(byte*) field->charset()->csname; - table->field[10]->store((const char*) pos, - strlen((const char*) pos), cs); - table->field[10]->set_notnull(); - pos=(byte*) field->charset()->name; table->field[12]->store((const char*) pos, strlen((const char*) pos), cs); table->field[12]->set_notnull(); + pos=(byte*) field->charset()->name; + table->field[13]->store((const char*) pos, + strlen((const char*) pos), cs); + table->field[13]->set_notnull(); } pos=(byte*) ((field->flags & PRI_KEY_FLAG) ? "PRI" : (field->flags & UNIQUE_KEY_FLAG) ? "UNI" : (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":""); - table->field[14]->store((const char*) pos, + table->field[15]->store((const char*) pos, strlen((const char*) pos), cs); char *end=tmp; if (field->unireg_check == Field::NEXT_NUMBER) @@ -2511,45 +2541,46 @@ void store_schema_proc(THD *thd, TABLE *table, { table->field[3]->store(tmp_string.ptr(), tmp_string.length(), cs); tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[3], &tmp_string); + table->field[0]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); get_field(thd->mem_root, proc_table->field[0], &tmp_string); table->field[2]->store(tmp_string.ptr(), tmp_string.length(), cs); tmp_string.length(0); get_field(thd->mem_root, proc_table->field[2], &tmp_string); table->field[4]->store(tmp_string.ptr(), tmp_string.length(), cs); tmp_string.length(0); - get_field(thd->mem_root, proc_table->field[3], &tmp_string); - table->field[0]->store(tmp_string.ptr(), tmp_string.length(), cs); + get_field(thd->mem_root, proc_table->field[9], &tmp_string); + table->field[5]->store(tmp_string.ptr(), tmp_string.length(), cs); + table->field[6]->store("SQL", 3, cs); tmp_string.length(0); - get_field(thd->mem_root, proc_table->field[5], &tmp_string); - table->field[11]->store(tmp_string.ptr(), tmp_string.length(), cs); + get_field(thd->mem_root, proc_table->field[10], &tmp_string); + table->field[7]->store(tmp_string.ptr(), tmp_string.length(), cs); + table->field[8]->store("SQL", 3, cs); tmp_string.length(0); get_field(thd->mem_root, proc_table->field[6], &tmp_string); - table->field[10]->store(tmp_string.ptr(), tmp_string.length(), cs); - tmp_string.length(0); - get_field(thd->mem_root, proc_table->field[7], &tmp_string); - table->field[15]->store(tmp_string.ptr(), tmp_string.length(), cs); - tmp_string.length(0); - get_field(thd->mem_root, proc_table->field[9], &tmp_string); - table->field[6]->store(tmp_string.ptr(), tmp_string.length(), cs); + table->field[11]->store(tmp_string.ptr(), tmp_string.length(), cs); tmp_string.length(0); - get_field(thd->mem_root, proc_table->field[10], &tmp_string); - table->field[8]->store(tmp_string.ptr(), tmp_string.length(), cs); + get_field(thd->mem_root, proc_table->field[5], &tmp_string); + table->field[12]->store(tmp_string.ptr(), tmp_string.length(), cs); tmp_string.length(0); - get_field(thd->mem_root, proc_table->field[11], &tmp_string); - table->field[5]->store(tmp_string.ptr(), tmp_string.length(), cs); + get_field(thd->mem_root, proc_table->field[7], &tmp_string); + table->field[14]->store(tmp_string.ptr(), tmp_string.length(), cs); bzero((char *)&time, sizeof(time)); ((Field_timestamp *) proc_table->field[12])->get_time(&time); - table->field[14]->store_time(&time, MYSQL_TIMESTAMP_DATETIME); + table->field[15]->store_time(&time, MYSQL_TIMESTAMP_DATETIME); bzero((char *)&time, sizeof(time)); ((Field_timestamp *) proc_table->field[13])->get_time(&time); - table->field[13]->store_time(&time, MYSQL_TIMESTAMP_DATETIME); + table->field[16]->store_time(&time, MYSQL_TIMESTAMP_DATETIME); + tmp_string.length(0); get_field(thd->mem_root, proc_table->field[14], &tmp_string); - table->field[16]->store(tmp_string.ptr(), tmp_string.length(), cs); + table->field[17]->store(tmp_string.ptr(), tmp_string.length(), cs); tmp_string.length(0); get_field(thd->mem_root, proc_table->field[15], &tmp_string); - table->field[17]->store(tmp_string.ptr(), tmp_string.length(), cs); - table->field[7]->store("SQL", 3, cs); - table->field[9]->store("SQL", 3, cs); + table->field[18]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[11], &tmp_string); + table->field[19]->store(tmp_string.ptr(), tmp_string.length(), cs); table->file->write_row(table->record[0]); } } @@ -2785,11 +2816,11 @@ static int get_schema_key_column_usage_record(THD *thd, restore_record(table, default_values); table->field[1]->store(base_name, strlen(base_name), cs); table->field[2]->store(key_info->name, strlen(key_info->name), cs); - table->field[3]->store(base_name, strlen(base_name), cs); - table->field[4]->store(file_name, strlen(file_name), cs); - table->field[5]->store(key_part->field->field_name, + table->field[4]->store(base_name, strlen(base_name), cs); + table->field[5]->store(file_name, strlen(file_name), cs); + table->field[6]->store(key_part->field->field_name, strlen(key_part->field->field_name), cs); - table->field[6]->store((longlong) f_idx); + table->field[7]->store((longlong) f_idx); table->file->write_row(table->record[0]); } } @@ -2812,18 +2843,18 @@ static int get_schema_key_column_usage_record(THD *thd, table->field[1]->store(base_name, strlen(base_name), cs); table->field[2]->store(f_key_info->forein_id->str, f_key_info->forein_id->length, cs); - table->field[3]->store(base_name, strlen(base_name), cs); - table->field[4]->store(file_name, strlen(file_name), cs); - table->field[5]->store(f_info->str, f_info->length, cs); - table->field[6]->store((longlong) f_idx); - table->field[7]->store(f_key_info->referenced_db->str, + table->field[4]->store(base_name, strlen(base_name), cs); + table->field[5]->store(file_name, strlen(file_name), cs); + table->field[6]->store(f_info->str, f_info->length, cs); + table->field[7]->store((longlong) f_idx); + table->field[8]->store(f_key_info->referenced_db->str, f_key_info->referenced_db->length, cs); - table->field[7]->set_notnull(); - table->field[8]->store(f_key_info->referenced_table->str, + table->field[9]->set_notnull(); + table->field[10]->store(f_key_info->referenced_table->str, f_key_info->referenced_table->length, cs); - table->field[8]->set_notnull(); - table->field[9]->store(r_info->str, r_info->length, cs); table->field[9]->set_notnull(); + table->field[10]->store(r_info->str, r_info->length, cs); + table->field[10]->set_notnull(); table->file->write_row(table->record[0]); } } @@ -3035,24 +3066,46 @@ int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table) int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table) { - ST_FIELD_INFO *field_info= &schema_table->fields_info[3]; - int count= 2; - for ( ; field_info->field_name; field_info++) + int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1}; + int *field_num= fields_arr; + ST_FIELD_INFO *field_info; + for (; *field_num >= 0; field_num++) { - count++; - if (field_info->old_name) + field_info= &schema_table->fields_info[*field_num]; + if (!thd->lex->verbose && (*field_num == 13 || + *field_num == 17 || + *field_num == 18)) + continue; + Item_field *field= new Item_field(NullS, NullS, field_info->field_name); + if (field) { - if (!thd->lex->verbose && (count == 12 ||count == 17 || count == 18)) - continue; - Item_field *field= new Item_field(NullS, NullS, field_info->field_name); - if (field) - { - field->set_name(field_info->old_name, - strlen(field_info->old_name), - system_charset_info); - if (add_item_to_list(thd, field)) - return 1; - } + field->set_name(field_info->old_name, + strlen(field_info->old_name), + system_charset_info); + if (add_item_to_list(thd, field)) + return 1; + } + } + return 0; +} + + +int make_proc_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table) +{ + int fields_arr[]= {2, 3, 4, 19, 16, 15, 14, 18, -1}; + int *field_num= fields_arr; + ST_FIELD_INFO *field_info; + for (; *field_num >= 0; field_num++) + { + field_info= &schema_table->fields_info[*field_num]; + Item_field *field= new Item_field(NullS, NullS, field_info->field_name); + if (field) + { + field->set_name(field_info->old_name, + strlen(field_info->old_name), + system_charset_info); + if (add_item_to_list(thd, field)) + return 1; } } return 0; @@ -3197,6 +3250,7 @@ ST_FIELD_INFO schema_fields_info[]= {"CATALOG_NAME", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0}, {"SCHEMA_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Database"}, {"DEFAULT_CHARACTER_SET_NAME", 60, MYSQL_TYPE_STRING, 0, 0, 0}, + {"SQL_PATH", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0} }; @@ -3210,7 +3264,7 @@ ST_FIELD_INFO tables_fields_info[]= {"ENGINE", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, "Engine"}, {"VERSION", 21 , MYSQL_TYPE_LONG, 0, 1, "Version"}, {"ROW_FORMAT", 10, MYSQL_TYPE_STRING, 0, 1, "Row_format"}, - {"ROWS", 21 , MYSQL_TYPE_LONG, 0, 1, "Rows"}, + {"TABLE_ROWS", 21 , MYSQL_TYPE_LONG, 0, 1, "Rows"}, {"AVG_ROW_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, "Avg_row_length"}, {"DATA_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, "Data_length"}, {"MAX_DATA_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, "Max_data_length"}, @@ -3223,7 +3277,7 @@ ST_FIELD_INFO tables_fields_info[]= {"COLLATION", 60, MYSQL_TYPE_STRING, 0, 1, "Collation"}, {"CHECKSUM", 21 , MYSQL_TYPE_LONG, 0, 1, "Checksum"}, {"CREATE_OPTIONS", 255, MYSQL_TYPE_STRING, 0, 1, "Create_options"}, - {"COMMENT", 80, MYSQL_TYPE_STRING, 0, 0, "Comment"}, + {"TABLE_COMMENT", 80, MYSQL_TYPE_STRING, 0, 0, "Comment"}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0} }; @@ -3235,20 +3289,20 @@ ST_FIELD_INFO columns_fields_info[]= {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Field"}, {"ORDINAL_POSITION", 21 , MYSQL_TYPE_LONG, 0, 0, 0}, + {"COLUMN_DEFAULT", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, "Default"}, + {"IS_NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, "Null"}, {"DATA_TYPE", 40, MYSQL_TYPE_STRING, 0, 0, 0}, {"CHARACTER_MAXIMUM_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 0, 0}, {"CHARACTER_OCTET_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 0, 0}, - {"NUMERIC_PRECISION", 21 , MYSQL_TYPE_LONG, 0, 0, 0}, - {"NUMERIC_SCALE", 21 , MYSQL_TYPE_LONG, 0, 0, 0}, + {"NUMERIC_PRECISION", 21 , MYSQL_TYPE_LONG, 0, 1, 0}, + {"NUMERIC_SCALE", 21 , MYSQL_TYPE_LONG, 0, 1, 0}, {"CHARACTER_SET_NAME", 40, MYSQL_TYPE_STRING, 0, 1, 0}, - {"TYPE", 40, MYSQL_TYPE_STRING, 0, 0, "Type"}, {"COLLATION_NAME", 40, MYSQL_TYPE_STRING, 0, 1, "Collation"}, - {"IS_NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, "Null"}, - {"KEY", 3, MYSQL_TYPE_STRING, 0, 0, "Key"}, - {"COLUMN_DEFAULT", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, "Default"}, + {"COLUMN_TYPE", 40, MYSQL_TYPE_STRING, 0, 0, "Type"}, + {"COLUMN_KEY", 3, MYSQL_TYPE_STRING, 0, 0, "Key"}, {"EXTRA", 20, MYSQL_TYPE_STRING, 0, 0, "Extra"}, {"PRIVILEGES", 80, MYSQL_TYPE_STRING, 0, 0, "Privileges"}, - {"COMMENT", 255, MYSQL_TYPE_STRING, 0, 0, "Comment"}, + {"COLUMN_COMMENT", 255, MYSQL_TYPE_STRING, 0, 0, "Comment"}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0} }; @@ -3256,9 +3310,9 @@ ST_FIELD_INFO columns_fields_info[]= ST_FIELD_INFO charsets_fields_info[]= { {"CHARACTER_SET_NAME", 30, MYSQL_TYPE_STRING, 0, 0, "Charset"}, - {"Description", 60, MYSQL_TYPE_STRING, 0, 0, "Description"}, + {"DESCRIPTION", 60, MYSQL_TYPE_STRING, 0, 0, "Description"}, {"DEFAULT_COLLATE_NAME", 60, MYSQL_TYPE_STRING, 0, 0, "Default collation"}, - {"Maxlen", 3 ,MYSQL_TYPE_LONG, 0, 0, "Maxlen"}, + {"MAXLEN", 3 ,MYSQL_TYPE_LONG, 0, 0, "Maxlen"}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0} }; @@ -3266,11 +3320,11 @@ ST_FIELD_INFO charsets_fields_info[]= ST_FIELD_INFO collation_fields_info[]= { {"COLLATION_NAME", 30, MYSQL_TYPE_STRING, 0, 0, "Collation"}, - {"Charset", 30, MYSQL_TYPE_STRING, 0, 0, "Charset"}, - {"Id", 11, MYSQL_TYPE_LONG, 0, 0, "Id"}, - {"Default", 30 ,MYSQL_TYPE_STRING, 0, 0, "Default"}, - {"Compiled", 30 ,MYSQL_TYPE_STRING, 0, 0, "Compiled"}, - {"Sortlen", 3 ,MYSQL_TYPE_LONG, 0, 0, "Sortlen"}, + {"CHARSET", 30, MYSQL_TYPE_STRING, 0, 0, "Charset"}, + {"ID", 11, MYSQL_TYPE_LONG, 0, 0, "Id"}, + {"DEFAULT", 30 ,MYSQL_TYPE_STRING, 0, 0, "Default"}, + {"COMPILED", 30 ,MYSQL_TYPE_STRING, 0, 0, "Compiled"}, + {"SORTLEN", 3 ,MYSQL_TYPE_LONG, 0, 0, "Sortlen"}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0} }; @@ -3290,19 +3344,21 @@ ST_FIELD_INFO proc_fields_info[]= {"ROUTINE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Db"}, {"ROUTINE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Name"}, {"ROUTINE_TYPE", 9, MYSQL_TYPE_STRING, 0, 0, "Type"}, - {"DEFINER", 77, MYSQL_TYPE_STRING, 0, 0, "Definer"}, {"DTD_IDENTIFIER", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"ROUTINE_BODY", 3, MYSQL_TYPE_STRING, 0, 0, 0}, {"ROUTINE_DEFINITION", 65535, MYSQL_TYPE_STRING, 0, 0, 0}, + {"EXTERNAL_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0}, + {"EXTERNAL_LANGUAGE", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0}, {"PARAMETER_STYLE", 3, MYSQL_TYPE_STRING, 0, 0, 0}, {"IS_DETERMINISTIC", 3, MYSQL_TYPE_STRING, 0, 0, 0}, {"SQL_DATA_ACCESS", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"SQL_PATH", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0}, - {"LAST_ALTERED", 0, MYSQL_TYPE_TIMESTAMP, 0, 0, "Modified"}, - {"CREATED", 0, MYSQL_TYPE_TIMESTAMP, 0, 0, "Created"}, {"SECURITY_TYPE", 7, MYSQL_TYPE_STRING, 0, 0, "Security_type"}, + {"CREATED", 0, MYSQL_TYPE_TIMESTAMP, 0, 0, "Created"}, + {"LAST_ALTERED", 0, MYSQL_TYPE_TIMESTAMP, 0, 0, "Modified"}, {"SQL_MODE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"ROUTINE_COMMENT", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Comment"}, + {"DEFINER", 77, MYSQL_TYPE_STRING, 0, 0, "Definer"}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0} }; @@ -3404,6 +3460,7 @@ ST_FIELD_INFO key_column_usage_fields_info[]= {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0}, {"CONSTRAINT_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"CONSTRAINT_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, + {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0}, {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, @@ -3444,7 +3501,7 @@ ST_SCHEMA_TABLE schema_tables[]= {"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info, create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1}, {"ROUTINES", proc_fields_info, create_schema_table, - fill_schema_proc, make_old_format, 0, -1, -1}, + fill_schema_proc, make_proc_old_format, 0, -1, -1}, {"STATISTICS", stat_fields_info, create_schema_table, get_all_tables, make_old_format, get_schema_stat_record, 1, 2}, {"VIEWS", view_fields_info, create_schema_table, @@ -3460,7 +3517,7 @@ ST_SCHEMA_TABLE schema_tables[]= {"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table, get_all_tables, 0, get_schema_constarints_record, 3, 4}, {"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table, - get_all_tables, 0, get_schema_key_column_usage_record, 3, 4}, + get_all_tables, 0, get_schema_key_column_usage_record, 4, 5}, {"TABLE_NAMES", table_names_fields_info, create_schema_table, get_all_tables, make_table_names_old_format, 0, 1, 2}, {0, 0, 0, 0, 0, 0, 0, 0} diff --git a/sql/sql_view.cc b/sql/sql_view.cc index aa7fda4e3d0f6a31d546418807e123be43c5ce54..56f85667bb1344ef0eacf119c6919ea1fc6a8d3a 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -283,7 +283,7 @@ bool mysql_create_view(THD *thd, /* Do we have more privileges on view field then underlying table field? */ - if ((~fld->have_privileges & priv)) + if (!fld->field->table->tmp_table && (~fld->have_privileges & priv)) { /* VIEW column has more privileges */ my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), diff --git a/tests/client_test.c b/tests/client_test.c index 7d264d682da4fe20154ac77b42f8ba6caa56aa04..12462cd35b9e9a06a45a7b927dc821119ceae9b8 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -7263,13 +7263,13 @@ static void test_explain_bug() verify_prepare_field(result, 0, "Field", "COLUMN_NAME", MYSQL_TYPE_STRING, 0, 0, "", 192, 0); - verify_prepare_field(result, 1, "Type", "TYPE", + verify_prepare_field(result, 1, "Type", "COLUMN_TYPE", MYSQL_TYPE_STRING, 0, 0, "", 120, 0); verify_prepare_field(result, 2, "Null", "IS_NULLABLE", MYSQL_TYPE_STRING, 0, 0, "", 9, 0); - verify_prepare_field(result, 3, "Key", "KEY", + verify_prepare_field(result, 3, "Key", "COLUMN_KEY", MYSQL_TYPE_STRING, 0, 0, "", 9, 0); verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT",