diff options
author | unknown <gluh@gluh.mysql.r18.ru> | 2004-11-15 19:20:45 +0300 |
---|---|---|
committer | unknown <gluh@gluh.mysql.r18.ru> | 2004-11-15 19:20:45 +0300 |
commit | a59b0fbfd6b7627a4fdf2233482e732480dbe437 (patch) | |
tree | eb94b65480a6078dc19e33e6e67ae51d41558240 | |
parent | 9ec34a400aa386ce539176632f5dda830912cc2c (diff) | |
download | mariadb-git-a59b0fbfd6b7627a4fdf2233482e732480dbe437.tar.gz |
Fixes for information_schema
sql/sql_acl.cc:
Fix for bug 'If user has column privilege with grant option is_grantable is 'NO' in
INFORMATION_SCHEMA.COLUMN_PRIVILEGES'
sql/sql_show.cc:
removed sprinf
Fix for 'sp with select from information_schema table crashes server'
typo fixes
-rw-r--r-- | mysql-test/r/information_schema.result | 63 | ||||
-rw-r--r-- | mysql-test/t/information_schema.test | 36 | ||||
-rw-r--r-- | sql/sql_acl.cc | 4 | ||||
-rw-r--r-- | sql/sql_show.cc | 41 |
4 files changed, 117 insertions, 27 deletions
diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 6267fd204c4..3c35c6d557d 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_swedish_ci -NULL test latin1_swedish_ci +NULL mysql latin1 +NULL test latin1 select schema_name from information_schema.schemata; schema_name mysql test show databases *; CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME -NULL mysql latin1_swedish_ci -NULL test latin1_swedish_ci +NULL mysql latin1 +NULL test latin1 show databases like 't%'; Database (t%) test @@ -20,7 +20,7 @@ mysql test show databases * where schema_name like 't%'; CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME -NULL test latin1_swedish_ci +NULL test latin1 show databases * where schema_name = 't%'; CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME create database testtets; @@ -119,10 +119,10 @@ Field Type Collation Null Key Default Extra Privileges Comment c char(64) latin1_swedish_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 PRIVILIGES COMMENT +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 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 PRIVILIGES COMMENT +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 NULL testtets t1 b 2 varchar 30 30 30 31 latin1 varchar(30) latin1_swedish_ci YES MUL NULL drop view v1; @@ -352,7 +352,7 @@ t1 CREATE TABLE `t1` ( select * from information_schema.TABLE_CONSTRAINTS where TABLE_SCHEMA= "test"; CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE CONSTRAINT_METHOD -NULL test PRIMARY test t1 PRIMARY NULL +NULL test PRIMARY test t1 PRIMARY KEY NULL NULL test constraint_1 test t1 UNIQUE NULL NULL test key_1 test t1 UNIQUE NULL NULL test key_2 test t1 UNIQUE NULL @@ -371,10 +371,10 @@ FOREIGN KEY (t1_id) REFERENCES t1(id) ON UPDATE CASCADE) ENGINE=INNODB; select * from information_schema.TABLE_CONSTRAINTS where TABLE_SCHEMA= "test"; CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE CONSTRAINT_METHOD -NULL test PRIMARY test t1 PRIMARY NULL -NULL test PRIMARY test t2 PRIMARY NULL -NULL test t2_ibfk_1 test t2 FOREIGN ON DELETE CASCADE -NULL test t2_ibfk_2 test t2 FOREIGN ON UPDATE CASCADE +NULL test PRIMARY test t1 PRIMARY KEY NULL +NULL test PRIMARY test t2 PRIMARY KEY NULL +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 @@ -400,3 +400,42 @@ drop table t2; drop table t1; drop procedure sel2; drop function sub1; +create table t1(a int); +create view v1 (c) as select a from t1 with check option; +create view v2 (c) as select a from t1 WITH LOCAL CHECK OPTION; +create view v3 (c) as select a from t1 WITH CASCADED CHECK OPTION; +select * from information_schema.views; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME VIEW_DEFINITION CHECK_OPTION IS_UPDATABLE +NULL test v1 select `test`.`t1`.`a` AS `c` from `test`.`t1` WITH CASCADED CHECK OPTION YES +NULL test v2 select `test`.`t1`.`a` AS `c` from `test`.`t1` WITH LOCAL CHECK OPTION YES +NULL test v3 select `test`.`t1`.`a` AS `c` from `test`.`t1` WITH CASCADED CHECK OPTION YES +grant select (a) on test.t1 to joe@localhost with grant option; +select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES; +GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME PRIVILEGE_TYPE IS_GRANTABLE +'joe'@'localhost' NULL test t1 a SELECT YES +select * from INFORMATION_SCHEMA.TABLE_PRIVILEGES; +GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PRIVILEGE_TYPE IS_GRANTABLE +'joe'@'localhost' NULL test t1 USAGE YES +drop view v1, v2, v3; +drop table t1; +delete from mysql.user where user='joe'; +delete from mysql.db where user='joe'; +delete from mysql.tables_priv where user='joe'; +delete from mysql.columns_priv where user='joe'; +flush privileges; +create procedure px5 () +begin +declare v int; +declare c cursor for select version from +information_schema.tables; +open c; +fetch c into v; +select v; +close c; +end;// +call px5()// +v +9 +call px5()// +v +9 diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 017bf465d53..fb1d15dbb4c 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -185,4 +185,40 @@ drop table t2; drop table t1; drop procedure sel2; drop function sub1; + +create table t1(a int); +create view v1 (c) as select a from t1 with check option; +create view v2 (c) as select a from t1 WITH LOCAL CHECK OPTION; +create view v3 (c) as select a from t1 WITH CASCADED CHECK OPTION; +select * from information_schema.views; +grant select (a) on test.t1 to joe@localhost with grant option; +select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES; +select * from INFORMATION_SCHEMA.TABLE_PRIVILEGES; +drop view v1, v2, v3; +drop table t1; +delete from mysql.user where user='joe'; +delete from mysql.db where user='joe'; +delete from mysql.tables_priv where user='joe'; +delete from mysql.columns_priv where user='joe'; +flush privileges; + +delimiter //; +create procedure px5 () +begin +declare v int; +declare c cursor for select version from +information_schema.tables; +open c; +fetch c into v; +select v; +close c; +end;// + +call px5()// +call px5()// +delimiter ;// + + + +
\ No newline at end of file diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 036ccb91260..8ffba2579f3 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -4107,10 +4107,10 @@ int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond) ulong table_access= grant_table->cols; if (table_access != 0) { - ulong test_access= grant_table->cols & ~GRANT_ACL; - if (!(table_access & GRANT_ACL)) + if (!(grant_table->privs & GRANT_ACL)) is_grantable= "NO"; + ulong test_access= table_access & ~GRANT_ACL; strxmov(buff,"'",user,"'@'",grant_table->orig_host,"'",NullS); if (!test_access) continue; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index c92369685ea..17e6866f565 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1891,10 +1891,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) LEX *lex= thd->lex; TABLE *table= tables->table; SELECT_LEX *select_lex= &lex->select_lex; + SELECT_LEX *lsel= tables->schema_select_lex; ST_SCHEMA_TABLE *schema_table= tables->schema_table; DBUG_ENTER("fill_schema_tables"); - SELECT_LEX *lsel= tables->schema_select_lex; if (lsel) { TABLE *old_open_tables= thd->open_tables; @@ -1947,7 +1947,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) #endif { List<char> files; - (void) sprintf(path,"%s/%s",mysql_data_home,base_name); + strxmov(path, mysql_data_home, "/", base_name, NullS); end= path + (len= unpack_dirname(path,path)); len= FN_LEN - len; if (mysql_find_files(thd, &files, base_name, @@ -2035,7 +2035,7 @@ int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond) (grant_option && !check_grant_db(thd, file_name))) #endif { - (void) sprintf(path,"%s/%s",mysql_data_home, file_name); + strxmov(path, mysql_data_home, "/", file_name, NullS); length=unpack_dirname(path,path); // Convert if not unix found_libchar= 0; if (length && path[length-1] == FN_LIBCHAR) @@ -2050,8 +2050,8 @@ int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond) load_db_opt(thd, path, &create); restore_record(table, default_values); table->field[1]->store(file_name, strlen(file_name), system_charset_info); - table->field[2]->store(create.default_table_charset->name, - strlen(create.default_table_charset->name), + table->field[2]->store(create.default_table_charset->csname, + strlen(create.default_table_charset->csname), system_charset_info); table->file->write_row(table->record[0]); } @@ -2187,9 +2187,10 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables, if (file->raid_type) { char buff[100]; - 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_snprintf(buff,sizeof(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); ptr=strmov(ptr,buff); } table->field[19]->store(option_buff+1, @@ -2630,7 +2631,17 @@ static int get_schema_views_record(THD *thd, struct st_table_list *tables, table->field[1]->store(tables->view_db.str, tables->view_db.length, cs); table->field[2]->store(tables->view_name.str,tables->view_name.length,cs); table->field[3]->store(tables->query.str, tables->query.length, cs); - table->field[4]->store("NONE", 4, cs); + + if (tables->with_check != VIEW_CHECK_NONE) + { + if (tables->with_check == VIEW_CHECK_LOCAL) + table->field[4]->store("WITH LOCAL CHECK OPTION", 23, cs); + else + table->field[4]->store("WITH CASCADED CHECK OPTION", 26, cs); + } + else + table->field[4]->store("NONE", 4, cs); + if (tables->updatable_view) table->field[5]->store("YES", 3, cs); else @@ -2668,7 +2679,7 @@ static int get_schema_constarints_record(THD *thd, struct st_table_list *tables, table->field[3]->store(base_name, strlen(base_name), cs); table->field[4]->store(file_name, strlen(file_name), cs); if (i == primary_key && !strcmp(key_info->name, primary_key_name)) - table->field[5]->store("PRIMARY", 7, cs); + table->field[5]->store("PRIMARY KEY", 11, cs); else if (key_info->flags & HA_NOSAME) table->field[5]->store("UNIQUE", 6, cs); table->file->write_row(table->record[0]); @@ -2685,7 +2696,7 @@ static int get_schema_constarints_record(THD *thd, struct st_table_list *tables, 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("FOREIGN", 7, system_charset_info); + table->field[5]->store("FOREIGN KEY", 11, system_charset_info); table->field[6]->store(f_key_info->constraint_method->str, f_key_info->constraint_method->length, cs); table->field[6]->set_notnull(); @@ -3099,6 +3110,8 @@ bool get_schema_tables_result(JOIN *join) if (!tab->table || !tab->table->pos_in_table_list) break; TABLE_LIST *table_list= tab->table->pos_in_table_list; + TABLE_LIST *save_next_global= table_list->next_global; + if (table_list->schema_table && thd->fill_derived_tables()) { TABLE *old_derived_tables= thd->derived_tables; @@ -3112,11 +3125,13 @@ bool get_schema_tables_result(JOIN *join) { thd->derived_tables= old_derived_tables; thd->lock= sql_lock; + table_list->next_global= save_next_global; DBUG_RETURN(TRUE); } thd->lock= sql_lock; thd->lex->sql_command= SQLCOM_SELECT; thd->derived_tables= old_derived_tables; + table_list->next_global= save_next_global; } } DBUG_RETURN(FALSE); @@ -3178,7 +3193,7 @@ ST_FIELD_INFO columns_fields_info[]= {"KEY", 3, MYSQL_TYPE_STRING, 0, 0, 1, "Key"}, {"COLUMN_DEFAULT", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, "Default"}, {"EXTRA", 20, MYSQL_TYPE_STRING, 0, 0, 1, "Extra"}, - {"PRIVILIGES", 80, MYSQL_TYPE_STRING, 0, 0, 1, "Privileges"}, + {"PRIVILEGES", 80, MYSQL_TYPE_STRING, 0, 0, 1, "Privileges"}, {"COMMENT", 255, MYSQL_TYPE_STRING, 0, 0, 1, "Comment"}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} }; @@ -3265,7 +3280,7 @@ ST_FIELD_INFO view_fields_info[]= {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, {"VIEW_DEFINITION", 65535, MYSQL_TYPE_STRING, 0, 0, 1, 0}, - {"CHECK_OPTION", 4, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"CHECK_OPTION", 30, MYSQL_TYPE_STRING, 0, 0, 1, 0}, {"IS_UPDATABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} }; |