summaryrefslogtreecommitdiff
path: root/sql/sql_yacc.yy
diff options
context:
space:
mode:
authorunknown <cmiller@zippy.cornsilk.net>2007-08-31 15:24:43 -0400
committerunknown <cmiller@zippy.cornsilk.net>2007-08-31 15:24:43 -0400
commit13fea36d03529eefceadaa16b8a9d1faf3802eed (patch)
treea4312c3393e59c7c903a284b76a49c01dcd7bdc4 /sql/sql_yacc.yy
parent898333f843b5c750b9863ea94d60ab81a9caca4e (diff)
downloadmariadb-git-13fea36d03529eefceadaa16b8a9d1faf3802eed.tar.gz
Bug#15776: 32-bit signed int used for length of blob
Based on contributed patch from Martin Friebe, CLA from 2007-02-24. The parser lacked support for field sizes after signed long, when it should extend to 2**32-1. Now, we correct that limitation, and also make the error handling consistent for casts. mysql-test/r/type_blob.result: Verify that blobs may be created with the size that is already documented. Additionally, test the limits of several other types. mysql-test/t/type_blob.test: Verify that blobs may be created with the size that is already documented. Additionally, test the limits of several other types. sql/field.cc: atoi() insufficient to gauge the length of some fields. Change it to strtoul(). sql/item_create.cc: atoi() insufficient to gauge the length of some fields. Change it to strtoul(). If a casted length is too long, raise an error. sql/share/errmsg.txt: Change ER_TOO_BIG_FIELDLENGTH so that it can accept sizes larger than 2**15 -- instead, 2**32. sql/sql_yacc.yy: Make lengths take, in addition to NUM, LONG_NUM, ULONGLONG_NUM, and DECIMAL_NUM. sql/unireg.h: Define new constant.
Diffstat (limited to 'sql/sql_yacc.yy')
-rw-r--r--sql/sql_yacc.yy55
1 files changed, 27 insertions, 28 deletions
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 638da3b1bb0..c270e005454 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1171,7 +1171,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
single_multi table_wild_list table_wild_one opt_wild
union_clause union_list
precision subselect_start opt_and charset
- subselect_end select_var_list select_var_list_init help opt_len
+ subselect_end select_var_list select_var_list_init help opt_field_length field_length
opt_extended_describe
prepare prepare_src execute deallocate
statement sp_suid
@@ -3010,7 +3010,7 @@ udf_type:
field_list:
field_list_item
- | field_list ',' field_list_item;
+ | field_list ',' field_list_item; /* FIXME: Should this be backward? */
field_list_item:
@@ -3111,45 +3111,38 @@ field_spec:
};
type:
- int_type opt_len field_options { $$=$1; }
+ int_type opt_field_length field_options { $$=$1; }
| real_type opt_precision field_options { $$=$1; }
| FLOAT_SYM float_options field_options { $$=FIELD_TYPE_FLOAT; }
| BIT_SYM { Lex->length= (char*) "1";
$$=FIELD_TYPE_BIT; }
- | BIT_SYM '(' NUM ')' { Lex->length= $3.str;
- $$=FIELD_TYPE_BIT; }
+ | BIT_SYM field_length { $$=FIELD_TYPE_BIT; }
| BOOL_SYM { Lex->length=(char*) "1";
$$=FIELD_TYPE_TINY; }
| BOOLEAN_SYM { Lex->length=(char*) "1";
$$=FIELD_TYPE_TINY; }
- | char '(' NUM ')' opt_binary { Lex->length=$3.str;
- $$=FIELD_TYPE_STRING; }
+ | char field_length opt_binary { $$=FIELD_TYPE_STRING; }
| char opt_binary { Lex->length=(char*) "1";
$$=FIELD_TYPE_STRING; }
- | nchar '(' NUM ')' opt_bin_mod { Lex->length=$3.str;
- $$=FIELD_TYPE_STRING;
+ | nchar field_length opt_bin_mod { $$=FIELD_TYPE_STRING;
Lex->charset=national_charset_info; }
| nchar opt_bin_mod { Lex->length=(char*) "1";
$$=FIELD_TYPE_STRING;
Lex->charset=national_charset_info; }
- | BINARY '(' NUM ')' { Lex->length=$3.str;
- Lex->charset=&my_charset_bin;
+ | BINARY field_length { Lex->charset=&my_charset_bin;
$$=FIELD_TYPE_STRING; }
| BINARY { Lex->length= (char*) "1";
Lex->charset=&my_charset_bin;
$$=FIELD_TYPE_STRING; }
- | varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
- $$= MYSQL_TYPE_VARCHAR; }
- | nvarchar '(' NUM ')' opt_bin_mod { Lex->length=$3.str;
- $$= MYSQL_TYPE_VARCHAR;
+ | varchar field_length opt_binary { $$= MYSQL_TYPE_VARCHAR; }
+ | nvarchar field_length opt_bin_mod { $$= MYSQL_TYPE_VARCHAR;
Lex->charset=national_charset_info; }
- | VARBINARY '(' NUM ')' { Lex->length=$3.str;
- Lex->charset=&my_charset_bin;
+ | VARBINARY field_length { Lex->charset=&my_charset_bin;
$$= MYSQL_TYPE_VARCHAR; }
- | YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; }
+ | YEAR_SYM opt_field_length field_options { $$=FIELD_TYPE_YEAR; }
| DATE_SYM { $$=FIELD_TYPE_DATE; }
| TIME_SYM { $$=FIELD_TYPE_TIME; }
- | TIMESTAMP opt_len
+ | TIMESTAMP opt_field_length
{
if (YYTHD->variables.sql_mode & MODE_MAXDB)
$$=FIELD_TYPE_DATETIME;
@@ -3165,7 +3158,7 @@ type:
| DATETIME { $$=FIELD_TYPE_DATETIME; }
| TINYBLOB { Lex->charset=&my_charset_bin;
$$=FIELD_TYPE_TINY_BLOB; }
- | BLOB_SYM opt_len { Lex->charset=&my_charset_bin;
+ | BLOB_SYM opt_field_length { Lex->charset=&my_charset_bin;
$$=FIELD_TYPE_BLOB; }
| spatial_type
{
@@ -3187,7 +3180,7 @@ type:
$$=FIELD_TYPE_MEDIUM_BLOB; }
| LONG_SYM varchar opt_binary { $$=FIELD_TYPE_MEDIUM_BLOB; }
| TINYTEXT opt_binary { $$=FIELD_TYPE_TINY_BLOB; }
- | TEXT_SYM opt_len opt_binary { $$=FIELD_TYPE_BLOB; }
+ | TEXT_SYM opt_field_length opt_binary { $$=FIELD_TYPE_BLOB; }
| MEDIUMTEXT opt_binary { $$=FIELD_TYPE_MEDIUM_BLOB; }
| LONGTEXT opt_binary { $$=FIELD_TYPE_LONG_BLOB; }
| DECIMAL_SYM float_options field_options
@@ -3260,7 +3253,7 @@ real_type:
float_options:
/* empty */ { Lex->dec=Lex->length= (char*)0; }
- | '(' NUM ')' { Lex->length=$2.str; Lex->dec= (char*)0; }
+ | field_length { Lex->dec= (char*)0; }
| precision {};
precision:
@@ -3283,9 +3276,15 @@ field_option:
| UNSIGNED { Lex->type|= UNSIGNED_FLAG;}
| ZEROFILL { Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
-opt_len:
- /* empty */ { Lex->length=(char*) 0; } /* use default length */
- | '(' NUM ')' { Lex->length= $2.str; };
+opt_field_length:
+ /* empty */ { Lex->length=(char*) NULL; } /* use default length */
+ | field_length {};
+
+field_length:
+ '(' LONG_NUM ')' { Lex->length= $2.str; }
+ | '(' ULONGLONG_NUM ')' { Lex->length= $2.str; }
+ | '(' DECIMAL_NUM ')' { Lex->length= $2.str; }
+ | '(' NUM ')' { Lex->length= $2.str; };
opt_precision:
/* empty */ {}
@@ -5466,9 +5465,9 @@ in_sum_expr:
};
cast_type:
- BINARY opt_len { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
- | CHAR_SYM opt_len opt_binary { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
- | NCHAR_SYM opt_len { $$=ITEM_CAST_CHAR; Lex->charset= national_charset_info; Lex->dec=0; }
+ BINARY opt_field_length { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
+ | CHAR_SYM opt_field_length opt_binary { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
+ | NCHAR_SYM opt_field_length { $$=ITEM_CAST_CHAR; Lex->charset= national_charset_info; Lex->dec=0; }
| SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
| SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
| UNSIGNED { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }