summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <antony@ltantony.rdg.cyberkinetica.homeunix.net>2003-12-11 00:28:25 +0000
committerunknown <antony@ltantony.rdg.cyberkinetica.homeunix.net>2003-12-11 00:28:25 +0000
commit8086aa3542394a747aa39c29a061a93a8c1a5d65 (patch)
treeb4960a072927a63e9ad304fd4c7cb7501a92bf2e
parent4de973336f4fed6786da07f9c1a053330d2d1254 (diff)
downloadmariadb-git-8086aa3542394a747aa39c29a061a93a8c1a5d65.tar.gz
Fix for Bug #2075 - negative default values not accepted for integer columns
Allow numeric literals have a sign sql/sql_yacc.yy: Bug#2075 - Numeric literals need to handle sign. mysql-test/r/create.result: New test for Bug #2075 mysql-test/t/create.test: New test for Bug #2075
-rw-r--r--mysql-test/r/create.result11
-rw-r--r--mysql-test/t/create.test10
-rw-r--r--sql/sql_yacc.yy19
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
@@ -331,6 +331,16 @@ 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 <item_list>
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.
**********************************************************************/