~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.cc

  • Committer: Brian Aker
  • Date: 2008-12-15 07:35:25 UTC
  • mfrom: (673.3.1 drizzle-nopath)
  • Revision ID: brian@tangent.org-20081215073525-gzec3o8z2d15oqgn
Merge from Stewart.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2889
2889
  return(error != 0);
2890
2890
}
2891
2891
 
2892
 
/**
2893
 
  Try to discover table from engine.
2894
 
 
2895
 
  @note
2896
 
    If found, write the frm file to disk.
2897
 
 
2898
 
  @retval
2899
 
  -1    Table did not exists
2900
 
  @retval
2901
 
   0    Table created ok
2902
 
  @retval
2903
 
   > 0  Error, table existed but could not be created
2904
 
*/
2905
 
int ha_create_table_from_engine(Session* session, const char *db, const char *name)
2906
 
{
2907
 
  int error;
2908
 
  unsigned char *frmblob;
2909
 
  size_t frmlen;
2910
 
  char path[FN_REFLEN];
2911
 
  HA_CREATE_INFO create_info;
2912
 
  Table table;
2913
 
  TABLE_SHARE share;
2914
 
 
2915
 
  memset(&create_info, 0, sizeof(create_info));
2916
 
  if ((error= ha_discover(session, db, name, &frmblob, &frmlen)))
2917
 
  {
2918
 
    /* Table could not be discovered and thus not created */
2919
 
    return(error);
2920
 
  }
2921
 
 
2922
 
  /*
2923
 
    Table exists in handler and could be discovered
2924
 
    frmblob and frmlen are set, write the frm to disk
2925
 
  */
2926
 
 
2927
 
  build_table_filename(path, FN_REFLEN-1, db, name, "", 0);
2928
 
  // Save the frm file
2929
 
  error= writefrm(path, frmblob, frmlen);
2930
 
  free(frmblob);
2931
 
  if (error)
2932
 
    return(2);
2933
 
 
2934
 
  init_tmp_table_share(session, &share, db, 0, name, path);
2935
 
  if (open_table_def(session, &share, 0))
2936
 
  {
2937
 
    return(3);
2938
 
  }
2939
 
  if (open_table_from_share(session, &share, "" ,0, 0, 0, &table, OTM_OPEN))
2940
 
  {
2941
 
    free_table_share(&share);
2942
 
    return(3);
2943
 
  }
2944
 
 
2945
 
  table.updateCreateInfo(&create_info);
2946
 
  create_info.table_options|= HA_OPTION_CREATE_FROM_ENGINE;
2947
 
 
2948
 
  check_lowercase_names(table.file, path, path);
2949
 
  error=table.file->ha_create(path, &table, &create_info);
2950
 
  closefrm(&table, 1);
2951
 
 
2952
 
  return(error != 0);
2953
 
}
2954
 
 
2955
2892
void st_ha_check_opt::init()
2956
2893
{
2957
2894
  flags= sql_flags= 0;
3048
2985
  return 0;
3049
2986
}
3050
2987
 
3051
 
 
3052
 
/**
3053
 
  Try to discover one table from handler(s).
3054
 
 
3055
 
  @retval
3056
 
    -1   Table did not exists
3057
 
  @retval
3058
 
    0   OK. In this case *frmblob and *frmlen are set
3059
 
  @retval
3060
 
    >0   error.  frmblob and frmlen may not be set
3061
 
*/
3062
 
struct st_discover_args
3063
 
{
3064
 
  const char *db;
3065
 
  const char *name;
3066
 
  unsigned char **frmblob;
3067
 
  size_t *frmlen;
3068
 
};
3069
 
 
3070
 
static bool discover_handlerton(Session *session, plugin_ref plugin,
3071
 
                                void *arg)
3072
 
{
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,
3077
 
                        vargs->frmblob,
3078
 
                        vargs->frmlen))))
3079
 
    return true;
3080
 
 
3081
 
  return false;
3082
 
}
3083
 
 
3084
 
int ha_discover(Session *session, const char *db, const char *name,
3085
 
                unsigned char **frmblob, size_t *frmlen)
3086
 
{
3087
 
  int error= -1; // Table does not exist in any handler
3088
 
  st_discover_args args= {db, name, frmblob, frmlen};
3089
 
 
3090
 
  if (is_prefix(name, TMP_FILE_PREFIX)) /* skip temporary tables */
3091
 
    return(error);
3092
 
 
3093
 
  if (plugin_foreach(session, discover_handlerton,
3094
 
                 DRIZZLE_STORAGE_ENGINE_PLUGIN, &args))
3095
 
    error= 0;
3096
 
 
3097
 
  if (!error)
3098
 
    status_var_increment(session->status_var.ha_discover_count);
3099
 
  return(error);
3100
 
}
3101
 
 
3102
 
 
3103
2988
/**
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