| 660 | */ |
| 661 | |
| 662 | enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags) |
| 663 | { |
| 664 | bool error_given= false; |
| 665 | File file; |
| 666 | uchar *buf; |
| 667 | uchar head[FRM_HEADER_SIZE]; |
| 668 | char path[FN_REFLEN + 1]; |
| 669 | size_t frmlen, read_length; |
| 670 | uint length; |
| 671 | DBUG_ENTER("open_table_def"); |
| 672 | DBUG_PRINT("enter", ("table: '%s'.'%s' path: '%s'", share->db.str, |
| 673 | share->table_name.str, share->normalized_path.str)); |
| 674 | |
| 675 | share->error= OPEN_FRM_OPEN_ERROR; |
| 676 | |
| 677 | length=(uint) (strxnmov(path, sizeof(path) - 1, |
| 678 | share->normalized_path.str, reg_ext, NullS) - path); |
| 679 | if (flags & GTS_FORCE_DISCOVERY) |
| 680 | { |
| 681 | const char *path2= share->normalized_path.str; |
| 682 | DBUG_ASSERT(flags & GTS_TABLE); |
| 683 | DBUG_ASSERT(flags & GTS_USE_DISCOVERY); |
| 684 | /* Delete .frm and .par files */ |
| 685 | mysql_file_delete_with_symlink(key_file_frm, path2, reg_ext, MYF(0)); |
| 686 | mysql_file_delete_with_symlink(key_file_partition_ddl_log, path2, PAR_EXT, |
| 687 | MYF(0)); |
| 688 | file= -1; |
| 689 | } |
| 690 | else |
| 691 | file= mysql_file_open(key_file_frm, path, O_RDONLY | O_SHARE, MYF(0)); |
| 692 | |
| 693 | if (file < 0) |
| 694 | { |
| 695 | if ((flags & GTS_TABLE) && (flags & GTS_USE_DISCOVERY)) |
| 696 | { |
| 697 | ha_discover_table(thd, share); |
| 698 | error_given= true; |
| 699 | } |
| 700 | goto err_not_open; |
| 701 | } |
| 702 | |
| 703 | if (mysql_file_read(file, head, sizeof(head), MYF(MY_NABP))) |
| 704 | { |
| 705 | share->error = my_errno == HA_ERR_FILE_TOO_SHORT |
| 706 | ? OPEN_FRM_CORRUPTED : OPEN_FRM_READ_ERROR; |
| 707 | goto err; |
| 708 | } |
| 709 | |
| 710 | if (memcmp(head, STRING_WITH_LEN("TYPE=VIEW\n")) == 0) |
| 711 | { |
| 712 | share->is_view= 1; |
| 713 | if (flags & GTS_VIEW) |
| 714 | { |
| 715 | LEX_CSTRING pathstr= { path, length }; |
| 716 | /* |
| 717 | Create view file parser and hold it in TABLE_SHARE member |
| 718 | view_def. |
| 719 | */ |
no test coverage detected