| 397 | */ |
| 398 | |
| 399 | bool mysql_create_view(THD *thd, TABLE_LIST *views, |
| 400 | enum_view_create_mode mode) |
| 401 | { |
| 402 | LEX *lex= thd->lex; |
| 403 | bool link_to_local; |
| 404 | /* first table in list is target VIEW name => cut off it */ |
| 405 | TABLE_LIST *view= lex->unlink_first_table(&link_to_local); |
| 406 | TABLE_LIST *tables= lex->query_tables; |
| 407 | TABLE_LIST *tbl; |
| 408 | SELECT_LEX *select_lex= lex->first_select_lex(); |
| 409 | SELECT_LEX *sl; |
| 410 | SELECT_LEX_UNIT *unit= &lex->unit; |
| 411 | DDL_LOG_STATE ddl_log_state, ddl_log_state_tmp_file; |
| 412 | char backup_file_name[FN_REFLEN+2]; |
| 413 | bool res= FALSE; |
| 414 | DBUG_ENTER("mysql_create_view"); |
| 415 | |
| 416 | /* |
| 417 | This is ensured in the parser. |
| 418 | NOTE: Originally, the assert below contained the extra condition |
| 419 | && !lex->result |
| 420 | but in this form the assert is failed in case CREATE VIEW run under |
| 421 | cursor (the case when the byte 'flags' in the COM_STMT_EXECUTE packet has |
| 422 | the flag CURSOR_TYPE_READ_ONLY set). For the cursor use case |
| 423 | thd->lex->result is assigned a pointer to the class Select_materialize |
| 424 | inside the function mysql_open_cursor() just before handling of a statement |
| 425 | will be started and the function mysql_create_view() called. |
| 426 | */ |
| 427 | DBUG_ASSERT(!lex->proc_list.first && |
| 428 | !lex->param_list.elements); |
| 429 | |
| 430 | bzero(&ddl_log_state, sizeof(ddl_log_state)); |
| 431 | bzero(&ddl_log_state_tmp_file, sizeof(ddl_log_state_tmp_file)); |
| 432 | backup_file_name[0]= 0; |
| 433 | /* |
| 434 | We can't allow taking exclusive meta-data locks of unlocked view under |
| 435 | LOCK TABLES since this might lead to deadlock. Since at the moment we |
| 436 | can't really lock view with LOCK TABLES we simply prohibit creation/ |
| 437 | alteration of views under LOCK TABLES. |
| 438 | */ |
| 439 | |
| 440 | if (thd->locked_tables_mode) |
| 441 | { |
| 442 | my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); |
| 443 | res= TRUE; |
| 444 | goto err; |
| 445 | } |
| 446 | |
| 447 | if ((res= create_view_precheck(thd, tables, view, mode))) |
| 448 | goto err; |
| 449 | |
| 450 | lex->link_first_table_back(view, link_to_local); |
| 451 | view->open_type= OT_BASE_ONLY; |
| 452 | |
| 453 | /* |
| 454 | ignore lock specs for CREATE statement |
| 455 | */ |
| 456 | if (lex->current_select->lock_type != TL_READ_DEFAULT) |
no test coverage detected