From bddf61cfb34e9aca2e19ea8bf746ad97ada0f3b8 Mon Sep 17 00:00:00 2001
From: unknown <acurtis@xiphis.org>
Date: Sat, 27 Aug 2005 07:26:14 +0100
Subject: [PATCH] Bug#9048   "Creating a function with char binary IN parameter
 fails"   Parse BINARY as part of type declaration, not as   a column
 attribute.

mysql-test/r/sp.result:
  test for bug 9048
mysql-test/t/sp.test:
  test for bug 9048
sql/sql_yacc.yy:
  fix bug 9048
  parse BINARY as part of type declaration and not as column modifier.
---
 mysql-test/r/sp.result |  7 +++++++
 mysql-test/t/sp.test   | 13 +++++++++++++
 sql/sql_yacc.yy        | 28 +++++++++++++++++++++++-----
 3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index 0ae4fc0402..7fcb797867 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -3186,4 +3186,11 @@ end|
 call bug11333(10)|
 drop procedure bug11333|
 drop table t3|
+drop function if exists bug9048|
+create function bug9048(f1 char binary) returns char binary
+begin
+set f1= concat( 'hello', f1 );
+return f1;
+end|
+drop function bug9048|
 drop table t1,t2;
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 0e3cbff897..f1662a57c1 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -4030,6 +4030,19 @@ call bug11333(10)|
 drop procedure bug11333|
 drop table t3|
 
+#
+# BUG#9048: Creating a function with char binary IN parameter fails
+#
+--disable_warnings
+drop function if exists bug9048|
+--enable_warnings
+create function bug9048(f1 char binary) returns char binary
+begin
+  set f1= concat( 'hello', f1 );
+  return f1;
+end|
+drop function bug9048|
+
 #
 # BUG#NNNN: New bug synopsis
 #
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 53fce78703..ae45df8134 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -2874,10 +2874,10 @@ type:
 					  $$=FIELD_TYPE_STRING; }
 	| char opt_binary		{ Lex->length=(char*) "1";
 					  $$=FIELD_TYPE_STRING; }
-	| nchar '(' NUM ')'		{ Lex->length=$3.str;
+	| nchar '(' NUM ')' opt_bin_mod	{ Lex->length=$3.str;
 					  $$=FIELD_TYPE_STRING;
 					  Lex->charset=national_charset_info; }
-	| nchar				{ Lex->length=(char*) "1";
+	| nchar opt_bin_mod		{ Lex->length=(char*) "1";
 					  $$=FIELD_TYPE_STRING;
 					  Lex->charset=national_charset_info; }
 	| BINARY '(' NUM ')'		{ Lex->length=$3.str;
@@ -2888,7 +2888,7 @@ type:
 					  $$=FIELD_TYPE_STRING; }
 	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
 					  $$= MYSQL_TYPE_VARCHAR; }
-	| nvarchar '(' NUM ')'		{ Lex->length=$3.str;
+	| nvarchar '(' NUM ')' opt_bin_mod { Lex->length=$3.str;
 					  $$= MYSQL_TYPE_VARCHAR;
 					  Lex->charset=national_charset_info; }
 	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
@@ -3077,7 +3077,6 @@ attribute:
 	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
 	  }
 	| COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
-	| BINARY { Lex->type|= BINCMP_FLAG; }
 	| COLLATE_SYM collation_name
 	  {
 	    if (Lex->charset && !my_charset_same(Lex->charset,$2))
@@ -3162,8 +3161,27 @@ opt_default:
 
 opt_binary:
 	/* empty */			{ Lex->charset=NULL; }
-	| ASCII_SYM			{ Lex->charset=&my_charset_latin1; }
+	| ASCII_SYM opt_bin_mod		{ Lex->charset=&my_charset_latin1; }
 	| BYTE_SYM			{ Lex->charset=&my_charset_bin; }
+	| UNICODE_SYM opt_bin_mod
+	{
+	  if (!(Lex->charset=get_charset_by_csname("ucs2",
+                                                   MY_CS_PRIMARY,MYF(0))))
+	  {
+	    my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
+	    YYABORT;
+	  }
+	}
+	| charset charset_name opt_bin_mod	{ Lex->charset=$2; }
+        | BINARY opt_bin_charset { Lex->type|= BINCMP_FLAG; };
+
+opt_bin_mod:
+	/* empty */ { }
+	| BINARY { Lex->type|= BINCMP_FLAG; };
+
+opt_bin_charset:
+	/* empty */ { }
+	| ASCII_SYM	{ Lex->charset=&my_charset_latin1; }
 	| UNICODE_SYM
 	{
 	  if (!(Lex->charset=get_charset_by_csname("ucs2",
-- 
2.30.9