From 7f83c1763750acf93b1f137e02606393f6d68281 Mon Sep 17 00:00:00 2001 From: "antony@ltantony.rdg.cyberkinetica.homeunix.net" <> Date: Thu, 11 Dec 2003 00:28:25 +0000 Subject: [PATCH] Fix for Bug #2075 - negative default values not accepted for integer columns Allow numeric literals have a sign --- mysql-test/r/create.result | 11 +++++++++++ mysql-test/t/create.test | 10 ++++++++++ sql/sql_yacc.yy | 19 ++++++++++++++----- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 5df29fee298..40569388456 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -423,6 +423,17 @@ strnull varchar(10) YES NULL intg int(11) YES NULL rel double YES NULL drop table t1, t2; +create table t1(name varchar(10), age smallint default -1); +describe t1; +Field Type Null Key Default Extra +name varchar(10) YES NULL +age smallint(6) YES -1 +create table t2(name varchar(10), age smallint default - 1); +describe t2; +Field Type Null Key Default Extra +name varchar(10) YES NULL +age smallint(6) YES -1 +drop table t1, t2; create database test_$1; use test_$1; select database(); diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 32565c0e20b..e50d5f41af3 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -330,6 +330,16 @@ create table t2 select default(str) as str, default(strnull) as strnull, default describe t2; drop table t1, t2; +# +# Bug #2075 +# + +create table t1(name varchar(10), age smallint default -1); +describe t1; +create table t2(name varchar(10), age smallint default - 1); +describe t2; +drop table t1, t2; + # # Bug #1209 # diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 0aa7e4c2738..e1262561ea8 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -627,6 +627,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); using_list expr_or_default set_expr_or_default interval_expr param_marker singlerow_subselect singlerow_subselect_init exists_subselect exists_subselect_init + NUM_literal %type expr_list udf_expr_list when_list ident_list ident_list_arg @@ -4409,11 +4410,8 @@ param_marker: literal: text_literal { $$ = $1; } - | NUM { $$ = new Item_int($1.str, (longlong) strtol($1.str, NULL, 10),$1.length); } - | LONG_NUM { $$ = new Item_int($1.str, (longlong) strtoll($1.str,NULL,10), $1.length); } - | ULONGLONG_NUM { $$ = new Item_uint($1.str, $1.length); } - | REAL_NUM { $$ = new Item_real($1.str, $1.length); } - | FLOAT_NUM { $$ = new Item_float($1.str, $1.length); } + | opt_plus NUM_literal { $$ = $2; } + | '-' NUM_literal { $$ = new Item_func_neg($2); } | NULL_SYM { $$ = new Item_null(); Lex->next_state=MY_LEX_OPERATOR_OR_IDENT;} | HEX_NUM { $$ = new Item_varbinary($1.str,$1.length);} @@ -4429,6 +4427,17 @@ literal: | TIME_SYM text_literal { $$ = $2; } | TIMESTAMP text_literal { $$ = $2; }; +opt_plus: + | '+' ; + +NUM_literal: + NUM { $$ = new Item_int($1.str, (longlong) strtol($1.str, NULL, 10),$1.length); } + | LONG_NUM { $$ = new Item_int($1.str, (longlong) strtoll($1.str,NULL,10), $1.length); } + | ULONGLONG_NUM { $$ = new Item_uint($1.str, $1.length); } + | REAL_NUM { $$ = new Item_real($1.str, $1.length); } + | FLOAT_NUM { $$ = new Item_float($1.str, $1.length); } + ; + /********************************************************************** ** Createing different items. **********************************************************************/