Checks foreign key's parent table access. @param thd [in] Thread handler @param create_info [in] Create information (like MAX_ROWS, ENGINE or temporary table flag) @param alter_info [in] Initial list of columns and indexes for the table to be created @param create_db [in] Database of the created ta
| 7243 | true error or access denied. Error is sent to client in this case. |
| 7244 | */ |
| 7245 | bool check_fk_parent_table_access(THD *thd, |
| 7246 | HA_CREATE_INFO *create_info, |
| 7247 | Alter_info *alter_info, |
| 7248 | const LEX_CSTRING &create_db) |
| 7249 | { |
| 7250 | Key *key; |
| 7251 | List_iterator<Key> key_iterator(alter_info->key_list); |
| 7252 | |
| 7253 | while ((key= key_iterator++)) |
| 7254 | { |
| 7255 | if (key->type == Key::FOREIGN_KEY) |
| 7256 | { |
| 7257 | TABLE_LIST parent_table; |
| 7258 | Foreign_key *fk_key= (Foreign_key *)key; |
| 7259 | LEX_CSTRING db_name; |
| 7260 | LEX_CSTRING table_name= { fk_key->ref_table.str, |
| 7261 | fk_key->ref_table.length }; |
| 7262 | const privilege_t privileges(COL_DML_ACLS | REFERENCES_ACL); |
| 7263 | |
| 7264 | // Check if tablename is valid or not. |
| 7265 | DBUG_ASSERT(table_name.str != NULL); |
| 7266 | if (Lex_ident_table::check_name(table_name, false)) |
| 7267 | { |
| 7268 | my_error(ER_WRONG_TABLE_NAME, MYF(0), table_name.str); |
| 7269 | return true; |
| 7270 | } |
| 7271 | // if lower_case_table_names is set then convert tablename to lower case. |
| 7272 | if (lower_case_table_names && |
| 7273 | !(table_name= thd->make_ident_casedn(fk_key->ref_table)).str) |
| 7274 | return true; |
| 7275 | |
| 7276 | if (fk_key->ref_db.str) |
| 7277 | { |
| 7278 | if (Lex_ident_db::check_name_with_error(fk_key->ref_db) || |
| 7279 | !(db_name= thd->make_ident_opt_casedn(fk_key->ref_db, |
| 7280 | lower_case_table_names)).str) |
| 7281 | return true; |
| 7282 | } |
| 7283 | else |
| 7284 | { |
| 7285 | if (!thd->db.str) |
| 7286 | { |
| 7287 | DBUG_ASSERT(create_db.str); |
| 7288 | if (Lex_ident_db::check_name_with_error(create_db) || |
| 7289 | !(db_name= thd->make_ident_opt_casedn(create_db, |
| 7290 | lower_case_table_names)).str) |
| 7291 | return true; |
| 7292 | } |
| 7293 | else |
| 7294 | { |
| 7295 | if (thd->lex->copy_db_to(&db_name) || |
| 7296 | (lower_case_table_names && |
| 7297 | !(db_name= thd->make_ident_casedn(db_name)).str)) |
| 7298 | return true; |
| 7299 | } |
| 7300 | } |
| 7301 | |
| 7302 | parent_table.init_one_table(&db_name, &table_name, 0, TL_IGNORE); |
no test coverage detected