From 86039a34e5114447229b59e4e3abf111d1d72e48 Mon Sep 17 00:00:00 2001
From: "pem@mysql.comhem.se" <>
Date: Fri, 21 Nov 2003 14:00:40 +0100
Subject: [PATCH] Made Item_splocal printable.

---
 sql/item.h       | 10 ++++++++--
 sql/sp_head.cc   | 21 ++++++++++++++++++---
 sql/sql_class.cc |  2 +-
 sql/sql_yacc.yy  |  9 +++++++--
 4 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/sql/item.h b/sql/item.h
index 413fcb1ca26..13b729095d8 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -230,11 +230,12 @@ class Item_splocal : public Item
 private:
   
   uint m_offset;
+  LEX_STRING m_name;
 
 public:
 
-  Item_splocal(uint offset)
-    : m_offset(offset)
+  Item_splocal(LEX_STRING name, uint offset)
+    : m_offset(offset), m_name(name)
   {
     Item::maybe_null= TRUE;
   }
@@ -305,6 +306,11 @@ class Item_splocal : public Item
   {
     return this_item()->save_in_field(field, no_conversions);
   }
+
+  inline void print(String *str)
+  {
+    str->append(m_name.str, m_name.length);
+  }
 };
 
 
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 41db1f6dd70..70810265926 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -70,22 +70,32 @@ sp_eval_func_item(THD *thd, Item *it, enum enum_field_types type)
       {
 	longlong i= it->val_int();
 
-	DBUG_PRINT("info", ("INT_RESULT: %d", i));
 	if (it->null_value)
+	{
+	  DBUG_PRINT("info", ("INT_RESULT: null"));
 	  it= new Item_null();
+	}
 	else
+	{
+	  DBUG_PRINT("info", ("INT_RESULT: %d", i));
 	  it= new Item_int(it->val_int());
+	}
 	break;
       }
     case REAL_RESULT:
       {
 	double d= it->val();
 
-	DBUG_PRINT("info", ("REAL_RESULT: %g", d));
 	if (it->null_value)
+	{
+	  DBUG_PRINT("info", ("REAL_RESULT: null"));
 	  it= new Item_null();
+	}
 	else
+	{
+	  DBUG_PRINT("info", ("REAL_RESULT: %g", d));
 	  it= new Item_real(it->val());
+	}
 	break;
       }
     default:
@@ -94,12 +104,17 @@ sp_eval_func_item(THD *thd, Item *it, enum enum_field_types type)
 	String tmp(buffer, sizeof(buffer), it->collation.collation);
 	String *s= it->val_str(&tmp);
 
-	DBUG_PRINT("info",("default result: %*s",s->length(),s->c_ptr_quick()));
 	if (it->null_value)
+	{
+	  DBUG_PRINT("info", ("default result: null"));
 	  it= new Item_null();
+	}
 	else
+	{
+	  DBUG_PRINT("info",("default result: %*s",s->length(),s->c_ptr_quick()));
 	  it= new Item_string(thd->strmake(s->c_ptr_quick(), s->length()),
 			      s->length(), it->collation.collation);
+	}
 	break;
       }
     }
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 919cf8b969b..1c0d3168f53 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -1205,7 +1205,7 @@ int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
   {
     my_var *mv= gl++;
     if (mv->local)
-      (void)local_vars.push_back(new Item_splocal(mv->offset));
+      (void)local_vars.push_back(new Item_splocal(mv->s, mv->offset));
     else
     {
       Item_func_set_user_var *xx = new Item_func_set_user_var(mv->s, item);
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index b2cdeb1221c..8d61b910234 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1775,7 +1775,12 @@ sp_case:
 	      i= new sp_instr_jump_if_not(ip, $1);
 	    else
 	    { /* Simple case: <caseval> = <whenval> */
-	      Item *var= (Item*) new Item_splocal(ctx->current_framesize()-1);
+	      LEX_STRING ivar;
+
+	      ivar.str= "_tmp_";
+	      ivar.length= 5;
+	      Item *var= (Item*) new Item_splocal(ivar, 
+						  ctx->current_framesize()-1);
 	      Item *expr= new Item_func_eq(var, $1);
 
 	      i= new sp_instr_jump_if_not(ip, expr);
@@ -5507,7 +5512,7 @@ simple_ident:
 	      YYABORT;
 	    }
 	    else
-	      $$ = (Item*) new Item_splocal(spv->offset);
+	      $$ = (Item*) new Item_splocal($1, spv->offset);
 	  }
 	  else
 	  {
-- 
2.30.9