@@ -39,25 +39,27 @@ static int read_string(File file, uchar**to, size_t length)
39
39
/* *
40
40
Check type of .frm if we are not going to parse it.
41
41
42
- @param[in] thd The current session.
43
- @param[in] path path to FRM file.
44
- @param[out] dbt db_type of the table if FRMTYPE_TABLE, otherwise undefined.
42
+ @param[in] thd The current session.
43
+ @param[in] path path to FRM file.
44
+ @param[in/out] engine_name table engine name (length < NAME_CHAR_LEN)
45
+
46
+ engine_name is a LEX_STRING, where engine_name->str must point to
47
+ a buffer of at least NAME_CHAR_LEN+1 bytes.
45
48
46
49
@retval FRMTYPE_ERROR error
47
50
@retval FRMTYPE_TABLE table
48
51
@retval FRMTYPE_VIEW view
49
52
*/
50
53
51
- frm_type_enum dd_frm_type (THD *thd, char *path, enum legacy_db_type *dbt )
54
+ frm_type_enum dd_frm_type (THD *thd, char *path, LEX_STRING *engine_name )
52
55
{
53
56
File file;
54
57
uchar header[10 ]; // "TYPE=VIEW\n" it is 10 characters
55
58
size_t error;
56
59
frm_type_enum type= FRMTYPE_ERROR;
60
+ uchar dbt;
57
61
DBUG_ENTER (" dd_frm_type" );
58
62
59
- *dbt= DB_TYPE_UNKNOWN;
60
-
61
63
if ((file= mysql_file_open (key_file_frm, path, O_RDONLY | O_SHARE, MYF (0 ))) < 0 )
62
64
DBUG_RETURN (FRMTYPE_ERROR);
63
65
error= mysql_file_read (file, (uchar*) header, sizeof (header), MYF (MY_NABP));
@@ -72,17 +74,24 @@ frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
72
74
73
75
type= FRMTYPE_TABLE;
74
76
75
- /*
76
- This is just a check for DB_TYPE. We'll return default unknown type
77
- if the following test is true (arg #3). This should not have effect
78
- on return value from this function (default FRMTYPE_TABLE)
79
- */
80
- if (!is_binary_frm_header (header))
77
+ if (!is_binary_frm_header (header) || !engine_name)
81
78
goto err;
82
79
83
- *dbt= (enum legacy_db_type) (uint) *(header + 3 );
80
+ engine_name->length = 0 ;
81
+ dbt= header[3 ];
82
+
83
+ /* cannot use ha_resolve_by_legacy_type without a THD */
84
+ if (thd && dbt < DB_TYPE_FIRST_DYNAMIC)
85
+ {
86
+ handlerton *ht= ha_resolve_by_legacy_type (thd, (enum legacy_db_type)dbt);
87
+ if (ht)
88
+ {
89
+ *engine_name= hton2plugin[ht->slot ]->name ;
90
+ goto err;
91
+ }
92
+ }
84
93
85
- if (*dbt >= DB_TYPE_FIRST_DYNAMIC) /* read the true engine name */
94
+ /* read the true engine name */
86
95
{
87
96
MY_STAT state;
88
97
uchar *frm_image= 0 ;
@@ -110,15 +119,10 @@ frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
110
119
next_chunk+= connect_string_length + 2 ;
111
120
if (next_chunk + 2 < buff_end)
112
121
{
113
- uint str_db_type_length= uint2korr (next_chunk);
114
- LEX_STRING name;
115
- name.str = (char *) next_chunk + 2 ;
116
- name.length = str_db_type_length;
117
- plugin_ref tmp_plugin= ha_resolve_by_name (thd, &name, false );
118
- if (tmp_plugin)
119
- *dbt= plugin_data (tmp_plugin, handlerton *)->db_type ;
120
- else
121
- *dbt= DB_TYPE_UNKNOWN;
122
+ uint len= uint2korr (next_chunk);
123
+ if (len <= NAME_CHAR_LEN)
124
+ strmake (engine_name->str , (char *)next_chunk + 2 ,
125
+ engine_name->length = len);
122
126
}
123
127
}
124
128
0 commit comments