From b58cb7c4a283ea9775d55d1d133cec9359f86dfa Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 30 Apr 2010 12:12:25 +0200 Subject: [PATCH] small changes to WL#43: consistency: don't use "index" and "key" interchangeably => rename "key" to "index" consistency: all option types are logical, besides ULL => rename ULL to NUMBER don't accept floats where integers are expected accept hexadecimal where integers are expected --- mysql-test/r/plugin.result | 11 ++++++++++ mysql-test/t/plugin.test | 11 ++++++++++ sql/handler.h | 38 +++++++++++++++++------------------ sql/sql_table.cc | 4 ++-- sql/sql_yacc.yy | 7 ++++--- storage/example/ha_example.cc | 2 +- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/mysql-test/r/plugin.result b/mysql-test/r/plugin.result index 45224ba44c3..8621534c135 100644 --- a/mysql-test/r/plugin.result +++ b/mysql-test/r/plugin.result @@ -101,6 +101,17 @@ drop table t1; SET SQL_MODE=''; CREATE TABLE t1 (a int) ENGINE=example ULL=10000000000000000000 one_or_two='ttt' YESNO=SSS; ERROR HY000: Incorrect value '10000000000000000000' for option 'ULL' +CREATE TABLE t1 (a int) ENGINE=example ULL=10.00; +ERROR 42000: Only integers allowed as number here near '10.00' at line 1 +CREATE TABLE t1 (a int) ENGINE=example ULL=1e2; +ERROR 42000: Only integers allowed as number here near '1e2' at line 1 +CREATE TABLE t1 (a int) ENGINE=example ULL=0x1234; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ULL`=4660 +DROP TABLE t1; SET @@SQL_MODE=@OLD_SQL_MODE; select 1; 1 diff --git a/mysql-test/t/plugin.test b/mysql-test/t/plugin.test index a7f3c693389..f57fedaa32d 100644 --- a/mysql-test/t/plugin.test +++ b/mysql-test/t/plugin.test @@ -110,6 +110,17 @@ drop table t1; SET SQL_MODE=''; --error ER_BAD_OPTION_VALUE CREATE TABLE t1 (a int) ENGINE=example ULL=10000000000000000000 one_or_two='ttt' YESNO=SSS; + +--error ER_PARSE_ERROR +CREATE TABLE t1 (a int) ENGINE=example ULL=10.00; + +--error ER_PARSE_ERROR +CREATE TABLE t1 (a int) ENGINE=example ULL=1e2; + +CREATE TABLE t1 (a int) ENGINE=example ULL=0x1234; +SHOW CREATE TABLE t1; +DROP TABLE t1; + SET @@SQL_MODE=@OLD_SQL_MODE; # diff --git a/sql/handler.h b/sql/handler.h index ef69c18e846..81e0eab141c 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -555,19 +555,19 @@ struct handler_log_file_data { /* Definitions for engine-specific table/field/index options in the CREATE TABLE. - Options are declared with HA_*OPTION_* macros (HA_TOPTION_ULL, HA_FOPTION_ENUM, - HA_KOPTION_STRING, etc). + Options are declared with HA_*OPTION_* macros (HA_TOPTION_NUMBER, + HA_FOPTION_ENUM, HA_IOPTION_STRING, etc). Every macros takes the option name, and the name of the underlying field of the appropriate C structure. The "appropriate C structure" is ha_table_option_struct for table level options, ha_field_option_struct for field level options, - ha_key_option_struct for key level options. The engine either + ha_index_option_struct for key level options. The engine either defines a structure of this name, or uses #define's to map these "appropriate" names to the actual structure type name. ULL options use a ulonglong as the backing store. - HA_*OPTION_ULL() takes the option name, the structure field name, + HA_*OPTION_NUMBER() takes the option name, the structure field name, the default value for the option, min, max, and blk_siz values. STRING options use a char* as a backing store. @@ -595,7 +595,7 @@ enum ha_option_type { HA_OPTION_TYPE_ULL, /* unsigned long long */ HA_OPTION_TYPE_ENUM, /* uint */ HA_OPTION_TYPE_BOOL}; /* bool */ -#define HA_xOPTION_ULL(name, struc, field, def, min, max, blk_siz) \ +#define HA_xOPTION_NUMBER(name, struc, field, def, min, max, blk_siz) \ { HA_OPTION_TYPE_ULL, name, sizeof(name)-1, \ offsetof(struc, field), def, min, max, blk_siz, 0 } #define HA_xOPTION_STRING(name, struc, field) \ @@ -610,8 +610,8 @@ enum ha_option_type { HA_OPTION_TYPE_ULL, /* unsigned long long */ offsetof(struc, field), def, 0, 1, 0, 0 } #define HA_xOPTION_END { HA_OPTION_TYPE_ULL, 0, 0, 0, 0, 0, 0, 0, 0 } -#define HA_TOPTION_ULL(name, field, def, min, max, blk_siz) \ - HA_xOPTION_ULL(name, ha_table_option_struct, field, def, min, max, blk_siz) +#define HA_TOPTION_NUMBER(name, field, def, min, max, blk_siz) \ + HA_xOPTION_NUMBER(name, ha_table_option_struct, field, def, min, max, blk_siz) #define HA_TOPTION_STRING(name, field) \ HA_xOPTION_STRING(name, ha_table_option_struct, field) #define HA_TOPTION_ENUM(name, field, values, def) \ @@ -620,8 +620,8 @@ enum ha_option_type { HA_OPTION_TYPE_ULL, /* unsigned long long */ HA_xOPTION_BOOL(name, ha_table_option_struct, field, def) #define HA_TOPTION_END HA_xOPTION_END -#define HA_FOPTION_ULL(name, field, def, min, max, blk_siz) \ - HA_xOPTION_ULL(name, ha_field_option_struct, field, def, min, max, blk_siz) +#define HA_FOPTION_NUMBER(name, field, def, min, max, blk_siz) \ + HA_xOPTION_NUMBER(name, ha_field_option_struct, field, def, min, max, blk_siz) #define HA_FOPTION_STRING(name, field) \ HA_xOPTION_STRING(name, ha_field_option_struct, field) #define HA_FOPTION_ENUM(name, field, values, def) \ @@ -630,15 +630,15 @@ enum ha_option_type { HA_OPTION_TYPE_ULL, /* unsigned long long */ HA_xOPTION_BOOL(name, ha_field_option_struct, field, def) #define HA_FOPTION_END HA_xOPTION_END -#define HA_KOPTION_ULL(name, field, def, min, max, blk_siz) \ - HA_xOPTION_ULL(name, ha_key_option_struct, field, def, min, max, blk_siz) -#define HA_KOPTION_STRING(name, field) \ - HA_xOPTION_STRING(name, ha_key_option_struct, field) -#define HA_KOPTION_ENUM(name, field, values, def) \ - HA_xOPTION_ENUM(name, ha_key_option_struct, field, values, def) -#define HA_KOPTION_BOOL(name, field, values, def) \ - HA_xOPTION_BOOL(name, ha_key_option_struct, field, values, def) -#define HA_KOPTION_END HA_xOPTION_END +#define HA_IOPTION_NUMBER(name, field, def, min, max, blk_siz) \ + HA_xOPTION_NUMBER(name, ha_index_option_struct, field, def, min, max, blk_siz) +#define HA_IOPTION_STRING(name, field) \ + HA_xOPTION_STRING(name, ha_index_option_struct, field) +#define HA_IOPTION_ENUM(name, field, values, def) \ + HA_xOPTION_ENUM(name, ha_index_option_struct, field, values, def) +#define HA_IOPTION_BOOL(name, field, values, def) \ + HA_xOPTION_BOOL(name, ha_index_option_struct, field, values, def) +#define HA_IOPTION_END HA_xOPTION_END typedef struct st_ha_create_table_option { enum ha_option_type type; @@ -1060,7 +1060,7 @@ typedef struct st_ha_create_information /* 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 **keys_option_struct; ///< array of key option structures + void **indexes_option_struct; ///< array of index option structures } HA_CREATE_INFO; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index fb71cc82efe..5f38a3432f3 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5783,7 +5783,7 @@ compare_tables(TABLE *table, if ((create_info->fileds_option_struct= (void**)thd->calloc(sizeof(void*) * table->s->fields)) == NULL || - (create_info->keys_option_struct= + (create_info->indexes_option_struct= (void**)thd->calloc(sizeof(void*) * table->s->keys)) == NULL) DBUG_RETURN(1); @@ -5984,7 +5984,7 @@ compare_tables(TABLE *table, else { DBUG_ASSERT(i < table->s->keys); - create_info->keys_option_struct[i]= new_key->option_struct; + create_info->indexes_option_struct[i]= new_key->option_struct; } } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index cae37ddf2e6..e5deb2c7768 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -4769,7 +4769,7 @@ create_table_option: engine_option_value($1, $3, false, &Lex->create_info.option_list, &Lex->option_list_last); } - | IDENT_sys equal ulonglong_num + | IDENT_sys equal real_ulonglong_num { new (YYTHD->mem_root) engine_option_value($1, $3, &Lex->create_info.option_list, @@ -5434,7 +5434,7 @@ attribute: engine_option_value($1, $3, false, &Lex->option_list, &Lex->option_list_last); } - | IDENT_sys equal ulonglong_num + | IDENT_sys equal real_ulonglong_num { new (YYTHD->mem_root) engine_option_value($1, $3, &Lex->option_list, @@ -5746,7 +5746,7 @@ all_key_opt: engine_option_value($1, $3, false, &Lex->option_list, &Lex->option_list_last); } - | IDENT_sys equal ulonglong_num + | IDENT_sys equal real_ulonglong_num { new (YYTHD->mem_root) engine_option_value($1, $3, &Lex->option_list, @@ -9472,6 +9472,7 @@ ulonglong_num: real_ulonglong_num: NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); } | ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); } + | HEX_NUM { $$= strtoull($1.str, (char**) 0, 16); } | LONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); } | dec_num_error { MYSQL_YYABORT; } ; diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index d932fe60131..98ab6c6be31 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -151,7 +151,7 @@ ha_create_table_option example_table_option_list[]= range of values 0..UINT_MAX32, and a "block size" of 10 (any value must be divisible by 10). */ - HA_TOPTION_ULL("ULL", ullparam, UINT_MAX32, 0, UINT_MAX32, 10), + HA_TOPTION_NUMBER("ULL", ullparam, UINT_MAX32, 0, UINT_MAX32, 10), /* one option that takes an arbitrary string */