mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
small enhancement of the create table options feature:
no unnecessary casting from void*, more type safety. typos fixed.
This commit is contained in:
parent
27fb650b8b
commit
e343a2c134
8 changed files with 58 additions and 47 deletions
|
@ -258,7 +258,7 @@ static const size_t ha_option_type_sizeof[]=
|
|||
@retval FALSE OK
|
||||
*/
|
||||
|
||||
my_bool parse_option_list(THD* thd, void **option_struct,
|
||||
my_bool parse_option_list(THD* thd, void *option_struct_arg,
|
||||
engine_option_value *option_list,
|
||||
ha_create_table_option *rules,
|
||||
my_bool suppress_warning,
|
||||
|
@ -267,6 +267,7 @@ my_bool parse_option_list(THD* thd, void **option_struct,
|
|||
ha_create_table_option *opt;
|
||||
size_t option_struct_size= 0;
|
||||
engine_option_value *val= option_list;
|
||||
void **option_struct= (void**)option_struct_arg;
|
||||
DBUG_ENTER("parse_option_list");
|
||||
DBUG_PRINT("enter",
|
||||
("struct: 0x%lx list: 0x%lx rules: 0x%lx suppres %u root 0x%lx",
|
||||
|
|
|
@ -70,7 +70,7 @@ class Create_field;
|
|||
|
||||
my_bool parse_engine_table_options(THD *thd, handlerton *ht,
|
||||
TABLE_SHARE *share);
|
||||
my_bool parse_option_list(THD* thd, void **option_struct,
|
||||
my_bool parse_option_list(THD* thd, void *option_struct,
|
||||
engine_option_value *option_list,
|
||||
ha_create_table_option *rules,
|
||||
my_bool suppress_warning,
|
||||
|
|
|
@ -32,6 +32,7 @@ class Send_field;
|
|||
class Protocol;
|
||||
class Create_field;
|
||||
class Relay_log_info;
|
||||
struct ha_field_option_struct;
|
||||
|
||||
struct st_cache_field;
|
||||
int field_conv(Field *to,Field *from);
|
||||
|
@ -137,7 +138,7 @@ public:
|
|||
const char *field_name;
|
||||
/** reference to the list of options or NULL */
|
||||
engine_option_value *option_list;
|
||||
void *option_struct; /* structure with parsed options */
|
||||
ha_field_option_struct *option_struct; /* structure with parsed options */
|
||||
LEX_STRING comment;
|
||||
/* Field is part of the following keys */
|
||||
key_map key_start, part_of_key, part_of_key_not_clustered;
|
||||
|
@ -2155,7 +2156,7 @@ public:
|
|||
Field *field; // For alter table
|
||||
engine_option_value *option_list;
|
||||
/** structure with parsed options (for comparing fields in ALTER TABLE) */
|
||||
void *option_struct;
|
||||
ha_field_option_struct *option_struct;
|
||||
|
||||
uint8 row,col,sc_length,interval_id; // For rea_create_table
|
||||
uint offset,pack_flag;
|
||||
|
|
|
@ -593,6 +593,11 @@ struct handler_log_file_data {
|
|||
|
||||
See ha_example.cc for an example.
|
||||
*/
|
||||
|
||||
struct ha_table_option_struct;
|
||||
struct ha_field_option_struct;
|
||||
struct ha_index_option_struct;
|
||||
|
||||
enum ha_option_type { HA_OPTION_TYPE_ULL, /* unsigned long long */
|
||||
HA_OPTION_TYPE_STRING, /* char * */
|
||||
HA_OPTION_TYPE_ENUM, /* uint */
|
||||
|
@ -1060,9 +1065,9 @@ typedef struct st_ha_create_information
|
|||
enum ha_choice page_checksum; ///< If we have page_checksums
|
||||
engine_option_value *option_list; ///< list of table create options
|
||||
/* the following three are only for ALTER TABLE, check_if_incompatible_data() */
|
||||
void *option_struct; ///< structure with parsed table options
|
||||
void **fileds_option_struct; ///< array of field option structures
|
||||
void **indexes_option_struct; ///< array of index option structures
|
||||
ha_table_option_struct *option_struct; ///< structure with parsed table options
|
||||
ha_field_option_struct **fields_option_struct; ///< array of field option structures
|
||||
ha_index_option_struct **indexes_option_struct; ///< array of index option structures
|
||||
} HA_CREATE_INFO;
|
||||
|
||||
|
||||
|
|
|
@ -5855,10 +5855,10 @@ compare_tables(TABLE *table,
|
|||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
if ((create_info->fileds_option_struct=
|
||||
(void**)thd->calloc(sizeof(void*) * table->s->fields)) == NULL ||
|
||||
(create_info->indexes_option_struct=
|
||||
(void**)thd->calloc(sizeof(void*) * table->s->keys)) == NULL)
|
||||
if ((create_info->fields_option_struct= (ha_field_option_struct**)
|
||||
thd->calloc(sizeof(void*) * table->s->fields)) == NULL ||
|
||||
(create_info->indexes_option_struct= (ha_index_option_struct**)
|
||||
thd->calloc(sizeof(void*) * table->s->keys)) == NULL)
|
||||
DBUG_RETURN(1);
|
||||
|
||||
/*
|
||||
|
@ -5879,7 +5879,7 @@ compare_tables(TABLE *table,
|
|||
tmp_new_field= tmp_new_field_it++)
|
||||
{
|
||||
DBUG_ASSERT(i < table->s->fields);
|
||||
create_info->fileds_option_struct[i]= tmp_new_field->option_struct;
|
||||
create_info->fields_option_struct[i]= tmp_new_field->option_struct;
|
||||
|
||||
/* Make sure we have at least the default charset in use. */
|
||||
if (!new_field->charset)
|
||||
|
|
|
@ -69,6 +69,7 @@ typedef struct st_key_part_info { /* Info about a key part */
|
|||
} KEY_PART_INFO ;
|
||||
|
||||
class engine_option_value;
|
||||
struct ha_index_option_struct;
|
||||
|
||||
typedef struct st_key {
|
||||
uint key_length; /* Tot length of key */
|
||||
|
@ -104,7 +105,7 @@ typedef struct st_key {
|
|||
struct st_table *table;
|
||||
/** reference to the list of options or NULL */
|
||||
engine_option_value *option_list;
|
||||
void *option_struct; /* structure with parsed options */
|
||||
ha_index_option_struct *option_struct; /* structure with parsed options */
|
||||
} KEY;
|
||||
|
||||
|
||||
|
|
|
@ -343,7 +343,7 @@ typedef struct st_table_share
|
|||
struct st_table *open_tables; /* link to open tables */
|
||||
#endif
|
||||
engine_option_value *option_list; /* text options for table */
|
||||
void *option_struct; /* structure with parsed options */
|
||||
ha_table_option_struct *option_struct; /* structure with parsed options */
|
||||
|
||||
/* The following is copied to each TABLE on OPEN */
|
||||
Field **field;
|
||||
|
|
|
@ -115,13 +115,14 @@ pthread_mutex_t example_mutex;
|
|||
|
||||
|
||||
/**
|
||||
structure for CREATE TABLE options (table options)
|
||||
Structure for CREATE TABLE options (table options).
|
||||
It needs to be called ha_table_option_struct.
|
||||
|
||||
These can be specified in the CREATE TABLE:
|
||||
CREATE TABLE ( ... ) {...here...}
|
||||
The option values can be specified in the CREATE TABLE at the end:
|
||||
CREATE TABLE ( ... ) *here*
|
||||
*/
|
||||
|
||||
struct example_table_options_struct
|
||||
struct ha_table_option_struct
|
||||
{
|
||||
const char *strparam;
|
||||
ulonglong ullparam;
|
||||
|
@ -131,19 +132,26 @@ struct example_table_options_struct
|
|||
|
||||
|
||||
/**
|
||||
structure for CREATE TABLE options (field options)
|
||||
Structure for CREATE TABLE options (field options).
|
||||
It needs to be called ha_field_option_struct.
|
||||
|
||||
These can be specified in the CREATE TABLE per field:
|
||||
CREATE TABLE ( field ... {...here...}, ... )
|
||||
The option values can be specified in the CREATE TABLE per field:
|
||||
CREATE TABLE ( field ... *here*, ... )
|
||||
*/
|
||||
|
||||
struct example_field_options_struct
|
||||
struct ha_field_option_struct
|
||||
{
|
||||
const char *compex_param_to_parse_it_in_engine;
|
||||
const char *complex_param_to_parse_it_in_engine;
|
||||
};
|
||||
|
||||
/* HA_TOPTION_* macros expect the structure called ha_table_option_struct */
|
||||
#define ha_table_option_struct example_table_options_struct
|
||||
/*
|
||||
no example here, but index options can be declared similarly
|
||||
using the ha_index_option_struct structure.
|
||||
|
||||
Their values can be specified in the CREATE TABLE per index:
|
||||
CREATE TABLE ( field ..., .., INDEX .... *here*, ... )
|
||||
*/
|
||||
|
||||
ha_create_table_option example_table_option_list[]=
|
||||
{
|
||||
/*
|
||||
|
@ -169,8 +177,6 @@ ha_create_table_option example_table_option_list[]=
|
|||
HA_TOPTION_END
|
||||
};
|
||||
|
||||
/* HA_FOPTION_* macros expect the structure called ha_field_option_struct */
|
||||
#define ha_field_option_struct example_field_options_struct
|
||||
ha_create_table_option example_field_option_list[]=
|
||||
{
|
||||
/*
|
||||
|
@ -178,7 +184,7 @@ ha_create_table_option example_field_option_list[]=
|
|||
or boolean - for example a list - it needs to specify the option
|
||||
as a string and parse it internally.
|
||||
*/
|
||||
HA_FOPTION_STRING("COMPLEX", compex_param_to_parse_it_in_engine),
|
||||
HA_FOPTION_STRING("COMPLEX", complex_param_to_parse_it_in_engine),
|
||||
HA_FOPTION_END
|
||||
};
|
||||
|
||||
|
@ -368,8 +374,7 @@ int ha_example::open(const char *name, int mode, uint test_if_locked)
|
|||
thr_lock_data_init(&share->lock,&lock,NULL);
|
||||
|
||||
#ifndef DBUG_OFF
|
||||
example_table_options_struct *options=
|
||||
(example_table_options_struct *)table->s->option_struct;
|
||||
ha_table_option_struct *options= table->s->option_struct;
|
||||
|
||||
DBUG_ASSERT(options);
|
||||
DBUG_PRINT("info", ("strparam: '%-.64s' ullparam: %llu enumparam: %u "\
|
||||
|
@ -899,8 +904,7 @@ int ha_example::create(const char *name, TABLE *table_arg,
|
|||
HA_CREATE_INFO *create_info)
|
||||
{
|
||||
#ifndef DBUG_OFF
|
||||
example_table_options_struct *options=
|
||||
(example_table_options_struct *)table_arg->s->option_struct;
|
||||
ha_table_option_struct *options= table_arg->s->option_struct;
|
||||
DBUG_ENTER("ha_example::create");
|
||||
/*
|
||||
This example shows how to support custom engine specific table and field
|
||||
|
@ -913,13 +917,12 @@ int ha_example::create(const char *name, TABLE *table_arg,
|
|||
options->ullparam, options->enumparam, options->boolparam));
|
||||
for (Field **field= table_arg->s->field; *field; field++)
|
||||
{
|
||||
example_field_options_struct *field_options=
|
||||
(example_field_options_struct *)(*field)->option_struct;
|
||||
ha_field_option_struct *field_options= (*field)->option_struct;
|
||||
DBUG_ASSERT(field_options);
|
||||
DBUG_PRINT("info", ("field: %s complex: '%-.64s'",
|
||||
(*field)->field_name,
|
||||
(field_options->compex_param_to_parse_it_in_engine ?
|
||||
field_options->compex_param_to_parse_it_in_engine :
|
||||
(field_options->complex_param_to_parse_it_in_engine ?
|
||||
field_options->complex_param_to_parse_it_in_engine :
|
||||
"<NULL>")));
|
||||
}
|
||||
#endif
|
||||
|
@ -941,21 +944,21 @@ int ha_example::create(const char *name, TABLE *table_arg,
|
|||
bool ha_example::check_if_incompatible_data(HA_CREATE_INFO *info,
|
||||
uint table_changes)
|
||||
{
|
||||
example_table_options_struct *param_old, *param_new;
|
||||
ha_table_option_struct *param_old, *param_new;
|
||||
uint i;
|
||||
DBUG_ENTER("ha_example::check_if_incompatible_data");
|
||||
/*
|
||||
This example shows how custom engine specific table and field
|
||||
options can be accessed from this function to be compared.
|
||||
*/
|
||||
param_new= (example_table_options_struct *)info->option_struct;
|
||||
param_new= info->option_struct;
|
||||
DBUG_PRINT("info", ("new strparam: '%-.64s' ullparam: %llu enumparam: %u "
|
||||
"boolparam: %u",
|
||||
(param_new->strparam ? param_new->strparam : "<NULL>"),
|
||||
param_new->ullparam, param_new->enumparam,
|
||||
param_new->boolparam));
|
||||
|
||||
param_old= (example_table_options_struct *)table->s->option_struct;
|
||||
param_old= table->s->option_struct;
|
||||
DBUG_PRINT("info", ("old strparam: '%-.64s' ullparam: %llu enumparam: %u "
|
||||
"boolparam: %u",
|
||||
(param_old->strparam ? param_old->strparam : "<NULL>"),
|
||||
|
@ -974,19 +977,19 @@ bool ha_example::check_if_incompatible_data(HA_CREATE_INFO *info,
|
|||
|
||||
for (i= 0; i < table->s->fields; i++)
|
||||
{
|
||||
example_field_options_struct *f_old, *f_new;
|
||||
f_old= (example_field_options_struct *)table->s->field[i]->option_struct;
|
||||
ha_field_option_struct *f_old, *f_new;
|
||||
f_old= table->s->field[i]->option_struct;
|
||||
DBUG_ASSERT(f_old);
|
||||
DBUG_PRINT("info", ("old field: %u old complex: '%-.64s'", i,
|
||||
(f_old->compex_param_to_parse_it_in_engine ?
|
||||
f_old->compex_param_to_parse_it_in_engine :
|
||||
(f_old->complex_param_to_parse_it_in_engine ?
|
||||
f_old->complex_param_to_parse_it_in_engine :
|
||||
"<NULL>")));
|
||||
if (info->fileds_option_struct[i])
|
||||
if (info->fields_option_struct[i])
|
||||
{
|
||||
f_new= (example_field_options_struct *)info->fileds_option_struct[i];
|
||||
f_new= info->fields_option_struct[i];
|
||||
DBUG_PRINT("info", ("old field: %u new complex: '%-.64s'", i,
|
||||
(f_new->compex_param_to_parse_it_in_engine ?
|
||||
f_new->compex_param_to_parse_it_in_engine :
|
||||
(f_new->complex_param_to_parse_it_in_engine ?
|
||||
f_new->complex_param_to_parse_it_in_engine :
|
||||
"<NULL>")));
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue