2889
2889
return(error != 0);
2893
Try to discover table from engine.
2896
If found, write the frm file to disk.
2899
-1 Table did not exists
2903
> 0 Error, table existed but could not be created
2905
int ha_create_table_from_engine(Session* session, const char *db, const char *name)
2908
unsigned char *frmblob;
2910
char path[FN_REFLEN];
2911
HA_CREATE_INFO create_info;
2915
memset(&create_info, 0, sizeof(create_info));
2916
if ((error= ha_discover(session, db, name, &frmblob, &frmlen)))
2918
/* Table could not be discovered and thus not created */
2923
Table exists in handler and could be discovered
2924
frmblob and frmlen are set, write the frm to disk
2927
build_table_filename(path, FN_REFLEN-1, db, name, "", 0);
2928
// Save the frm file
2929
error= writefrm(path, frmblob, frmlen);
2934
init_tmp_table_share(session, &share, db, 0, name, path);
2935
if (open_table_def(session, &share, 0))
2939
if (open_table_from_share(session, &share, "" ,0, 0, 0, &table, OTM_OPEN))
2941
free_table_share(&share);
2945
table.updateCreateInfo(&create_info);
2946
create_info.table_options|= HA_OPTION_CREATE_FROM_ENGINE;
2948
check_lowercase_names(table.file, path, path);
2949
error=table.file->ha_create(path, &table, &create_info);
2950
closefrm(&table, 1);
2955
2892
void st_ha_check_opt::init()
2957
2894
flags= sql_flags= 0;
3053
Try to discover one table from handler(s).
3056
-1 Table did not exists
3058
0 OK. In this case *frmblob and *frmlen are set
3060
>0 error. frmblob and frmlen may not be set
3062
struct st_discover_args
3066
unsigned char **frmblob;
3070
static bool discover_handlerton(Session *session, plugin_ref plugin,
3073
st_discover_args *vargs= (st_discover_args *)arg;
3074
handlerton *hton= plugin_data(plugin, handlerton *);
3075
if (hton->state == SHOW_OPTION_YES && hton->discover &&
3076
(!(hton->discover(hton, session, vargs->db, vargs->name,
3084
int ha_discover(Session *session, const char *db, const char *name,
3085
unsigned char **frmblob, size_t *frmlen)
3087
int error= -1; // Table does not exist in any handler
3088
st_discover_args args= {db, name, frmblob, frmlen};
3090
if (is_prefix(name, TMP_FILE_PREFIX)) /* skip temporary tables */
3093
if (plugin_foreach(session, discover_handlerton,
3094
DRIZZLE_STORAGE_ENGINE_PLUGIN, &args))
3098
status_var_increment(session->status_var.ha_discover_count);
3104
2989
Call this function in order to give the handler the possiblity
3105
2990
to ask engine if there are any new tables that should be written to disk