List:Commits« Previous MessageNext Message »
From:marc.alff Date:May 1 2008 5:34pm
Subject:bk commit into 6.0 tree (malff:1.2638) BUG#11661 WL#2110
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of malff.  When malff does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-05-01 11:34:42-06:00, malff@stripped. +4 -0
  WL#2110 (Stored Procedures: Implement SIGNAL)
  WL#2265 (Stored Procedures: Implement RESIGNAL)
  WL#2111 (Stored Procedures: Implement GET DIAGNOSTICS)
  Bug#11661 (Raising Exceptions from within stored procedures: Support for
    SIGNAL statement)
  
  SIGNAL runtime implementation and tests, feature preview.

  mysql-test/r/signal.result@stripped, 2008-05-01 11:34:38-06:00, malff@stripped. +237 -0
    SIGNAL / RESIGNAL / GET DIAGNOSTICS

  mysql-test/t/signal.test@stripped, 2008-05-01 11:34:38-06:00, malff@stripped. +281 -0
    SIGNAL / RESIGNAL / GET DIAGNOSTICS

  sql/sql_class.h@stripped, 2008-05-01 11:34:38-06:00, malff@stripped. +1 -1
    SIGNAL / RESIGNAL / GET DIAGNOSTICS

  sql/sql_signal.cc@stripped, 2008-05-01 11:34:39-06:00, malff@stripped. +108 -23
    SIGNAL / RESIGNAL / GET DIAGNOSTICS

diff -Nrup a/mysql-test/r/signal.result b/mysql-test/r/signal.result
--- a/mysql-test/r/signal.result	2008-04-29 17:34:12 -06:00
+++ b/mysql-test/r/signal.result	2008-05-01 11:34:38 -06:00
@@ -1255,3 +1255,240 @@ end $$
 call test_signal() $$
 ERROR 40001: Unhandled user-defined exception
 drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE foo CONDITION FOR 9999;
+begin
+DECLARE foo CONDITION FOR 8888;
+end;
+SIGNAL foo; /* outer */
+end $$
+call test_signal() $$
+ERROR HY000: Unhandled user-defined exception
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE foo CONDITION FOR 9999;
+begin
+DECLARE foo CONDITION FOR 8888;
+SIGNAL foo; /* inner */
+end;
+end $$
+call test_signal() $$
+ERROR HY000: Unhandled user-defined exception
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE foo CONDITION FOR 9999;
+SIGNAL foo SET SQLCODE = 1111;
+end $$
+call test_signal() $$
+ERROR HY000: Unhandled user-defined exception
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE warn CONDITION FOR SQLSTATE "01000";
+SIGNAL warn SET SQLCODE = 1111;
+end $$
+call test_signal() $$
+Warnings:
+Warning	1111	Unhandled user-defined warning
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE not_found CONDITION FOR SQLSTATE "02000";
+SIGNAL not_found SET SQLCODE = 1111;
+end $$
+call test_signal() $$
+ERROR 02000: Unhandled user-defined not found
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE error CONDITION FOR SQLSTATE "55000";
+SIGNAL error SET SQLCODE = 1111;
+end $$
+call test_signal() $$
+ERROR 55000: Unhandled user-defined exception
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE foo CONDITION FOR 9999;
+SIGNAL foo SET MESSAGE_TEXT = "Something bad happened";
+end $$
+call test_signal() $$
+ERROR HY000: Something bad happened
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE warn CONDITION FOR SQLSTATE "01000";
+SIGNAL warn SET MESSAGE_TEXT = "Something bad happened";
+end $$
+call test_signal() $$
+Warnings:
+Warning	1	Something bad happened
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE not_found CONDITION FOR SQLSTATE "02000";
+SIGNAL not_found SET MESSAGE_TEXT = "Something bad happened";
+end $$
+call test_signal() $$
+ERROR 02000: Something bad happened
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE error CONDITION FOR SQLSTATE "55000";
+SIGNAL error SET MESSAGE_TEXT = "Something bad happened";
+end $$
+call test_signal() $$
+ERROR 55000: Something bad happened
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE error CONDITION FOR 9999;
+SIGNAL error SET
+CLASS_ORIGIN = NULL,
+SUBCLASS_ORIGIN = NULL,
+CONSTRAINT_CATALOG = NULL,
+CONSTRAINT_SCHEMA = NULL,
+CONSTRAINT_NAME = NULL,
+CATALOG_NAME = NULL,
+SCHEMA_NAME = NULL,
+TABLE_NAME = NULL,
+COLUMN_NAME = NULL,
+CURSOR_NAME = NULL,
+MESSAGE_TEXT = NULL,
+SQLCODE = NULL;
+end $$
+call test_signal() $$
+ERROR HY000: Unhandled user-defined exception
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE something CONDITION FOR 9999;
+DECLARE message_text VARCHAR(64) DEFAULT "Local string variable";
+DECLARE sqlcode INTEGER DEFAULT 1234;
+SIGNAL something SET
+MESSAGE_TEXT = message_text,
+SQLCODE = sqlcode;
+end $$
+call test_signal() $$
+ERROR HY000: Local string variable
+drop procedure test_signal $$
+create procedure test_signal(message_text VARCHAR(64), sqlcode INTEGER)
+begin
+DECLARE something CONDITION FOR SQLSTATE "12345";
+SIGNAL something SET
+MESSAGE_TEXT = message_text,
+SQLCODE = sqlcode;
+end $$
+call test_signal(NULL, NULL) $$
+ERROR 12345: Unhandled user-defined exception
+call test_signal("Parameter string", 5678) $$
+ERROR 12345: Parameter string
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE something CONDITION FOR SQLSTATE "AABBB";
+SIGNAL something SET
+MESSAGE_TEXT = @message_text,
+SQLCODE = @sqlcode;
+end $$
+call test_signal() $$
+ERROR AABBB: Unhandled user-defined exception
+set @message_text= "User variable" $$
+set @sqlcode= 12 $$
+call test_signal() $$
+ERROR AABBB: User variable
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE something CONDITION FOR SQLSTATE "12345";
+SIGNAL something SET
+MESSAGE_TEXT = concat("functions", " also works"),
+SQLCODE = 1000 + 12;
+end $$
+call test_signal() $$
+ERROR 12345: functions also works
+drop procedure test_signal $$
+create procedure test_signal(code integer)
+begin
+DECLARE something CONDITION FOR SQLSTATE "12345";
+SIGNAL something SET
+MESSAGE_TEXT = (select message_text from t1 where id=code),
+SQLCODE = (select sqlcode from t1 where id=code);
+end $$
+drop table if exists t1 $$
+call test_signal(1) $$
+ERROR 42S02: Table 'test.t1' doesn't exist
+create table t1(id integer, message_text varchar(64), sqlcode integer) $$
+call test_signal(1) $$
+ERROR 12345: Unhandled user-defined exception
+insert into t1 values ((1), ("First message"), (1001)) $$
+insert into t1 values ((2), ("Second message"), (1002)) $$
+call test_signal(1) $$
+ERROR 12345: First message
+call test_signal(2) $$
+ERROR 12345: Second message
+alter table t1 drop column message_text $$
+call test_signal(2) $$
+ERROR 42S22: Unknown column 'message_text' in 'field list'
+drop table t1 $$
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE warn CONDITION FOR SQLSTATE "01234";
+SIGNAL warn SET
+CLASS_ORIGIN = repeat("A", 64),
+SUBCLASS_ORIGIN = repeat("B", 64),
+CONSTRAINT_CATALOG = repeat("C", 64),
+CONSTRAINT_SCHEMA = repeat("D", 64),
+CONSTRAINT_NAME = repeat("E", 64),
+CATALOG_NAME =repeat("F", 64),
+SCHEMA_NAME =repeat("G", 64),
+TABLE_NAME = repeat("H", 64),
+COLUMN_NAME =repeat("I", 64),
+CURSOR_NAME = repeat("J", 64),
+MESSAGE_TEXT = repeat("K", 128),
+SQLCODE = 4294967295;
+end $$
+call test_signal() $$
+Warnings:
+Warning	4294967295	KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
+drop procedure test_signal $$
+create procedure test_signal()
+begin
+DECLARE warn CONDITION FOR SQLSTATE "01234";
+SIGNAL warn SET
+CLASS_ORIGIN = concat(repeat("A", 64), "X"),
+SUBCLASS_ORIGIN = concat(repeat("B", 64), "X"),
+CONSTRAINT_CATALOG = concat(repeat("C", 64), "X"),
+CONSTRAINT_SCHEMA = concat(repeat("D", 64), "X"),
+CONSTRAINT_NAME = concat(repeat("E", 64), "X"),
+CATALOG_NAME = concat(repeat("F", 64), "X"),
+SCHEMA_NAME = concat(repeat("G", 64), "X"),
+TABLE_NAME = concat(repeat("H", 64), "X"),
+COLUMN_NAME = concat(repeat("I", 64), "X"),
+CURSOR_NAME = concat(repeat("J", 64), "X"),
+MESSAGE_TEXT = concat(repeat("1", 100),
+repeat("2", 20),
+repeat("8", 8),
+"X"),
+SQLCODE = 999999999999999999999999999999999999999999999999999;
+end $$
+call test_signal() $$
+Warnings:
+Warning	1292	Truncated incorrect VARCHAR(64) value: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAX'
+Warning	1292	Truncated incorrect VARCHAR(64) value: 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBX'
+Warning	1292	Truncated incorrect VARCHAR(64) value: 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCX'
+Warning	1292	Truncated incorrect VARCHAR(64) value: 'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDX'
+Warning	1292	Truncated incorrect VARCHAR(64) value: 'EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEX'
+Warning	1292	Truncated incorrect VARCHAR(64) value: 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFX'
+Warning	1292	Truncated incorrect VARCHAR(64) value: 'GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGX'
+Warning	1292	Truncated incorrect VARCHAR(64) value: 'HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHX'
+Warning	1292	Truncated incorrect VARCHAR(64) value: 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIX'
+Warning	1292	Truncated incorrect VARCHAR(64) value: 'JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJX'
+Warning	1292	Truncated incorrect VARCHAR(128) value: '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222222288888888'
+Error	1292	Truncated incorrect DECIMAL value: ''
+Warning	4294967295	11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222222288888888
+drop procedure test_signal $$
diff -Nrup a/mysql-test/t/signal.test b/mysql-test/t/signal.test
--- a/mysql-test/t/signal.test	2008-04-29 17:34:12 -06:00
+++ b/mysql-test/t/signal.test	2008-05-01 11:34:38 -06:00
@@ -1509,12 +1509,293 @@ end $$
 call test_signal() $$
 drop procedure test_signal $$
 
+# Test the scope of condition
 
+create procedure test_signal()
+begin
+  DECLARE foo CONDITION FOR 9999;
+  begin
+    DECLARE foo CONDITION FOR 8888;
+  end;
+  SIGNAL foo; /* outer */
+end $$
 
+--error 9999
+call test_signal() $$
+drop procedure test_signal $$
 
+create procedure test_signal()
+begin
+  DECLARE foo CONDITION FOR 9999;
+  begin
+    DECLARE foo CONDITION FOR 8888;
+    SIGNAL foo; /* inner */
+  end;
+end $$
 
+--error 8888
+call test_signal() $$
+drop procedure test_signal $$
 
+# Test SET SQLCODE
 
+create procedure test_signal()
+begin
+  DECLARE foo CONDITION FOR 9999;
+  SIGNAL foo SET SQLCODE = 1111;
+end $$
+
+--error 1111
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE warn CONDITION FOR SQLSTATE "01000";
+  SIGNAL warn SET SQLCODE = 1111;
+end $$
+
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE not_found CONDITION FOR SQLSTATE "02000";
+  SIGNAL not_found SET SQLCODE = 1111;
+end $$
+
+--error 1111
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE error CONDITION FOR SQLSTATE "55000";
+  SIGNAL error SET SQLCODE = 1111;
+end $$
+
+--error 1111
+call test_signal() $$
+drop procedure test_signal $$
+
+# Test SET MESSAGE_TEXT
+
+create procedure test_signal()
+begin
+  DECLARE foo CONDITION FOR 9999;
+  SIGNAL foo SET MESSAGE_TEXT = "Something bad happened";
+end $$
+
+--error 9999
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE warn CONDITION FOR SQLSTATE "01000";
+  SIGNAL warn SET MESSAGE_TEXT = "Something bad happened";
+end $$
+
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE not_found CONDITION FOR SQLSTATE "02000";
+  SIGNAL not_found SET MESSAGE_TEXT = "Something bad happened";
+end $$
+
+--error 1
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE error CONDITION FOR SQLSTATE "55000";
+  SIGNAL error SET MESSAGE_TEXT = "Something bad happened";
+end $$
+
+--error 1
+call test_signal() $$
+drop procedure test_signal $$
+
+# Test SET complex expressions
+
+create procedure test_signal()
+begin
+  DECLARE error CONDITION FOR 9999;
+  SIGNAL error SET
+    CLASS_ORIGIN = NULL,
+    SUBCLASS_ORIGIN = NULL,
+    CONSTRAINT_CATALOG = NULL,
+    CONSTRAINT_SCHEMA = NULL,
+    CONSTRAINT_NAME = NULL,
+    CATALOG_NAME = NULL,
+    SCHEMA_NAME = NULL,
+    TABLE_NAME = NULL,
+    COLUMN_NAME = NULL,
+    CURSOR_NAME = NULL,
+    MESSAGE_TEXT = NULL,
+    SQLCODE = NULL;
+end $$
+
+--error 1
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE something CONDITION FOR 9999;
+  DECLARE message_text VARCHAR(64) DEFAULT "Local string variable";
+  DECLARE sqlcode INTEGER DEFAULT 1234;
+
+  SIGNAL something SET
+    MESSAGE_TEXT = message_text,
+    SQLCODE = sqlcode;
+end $$
+
+--error 1234
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal(message_text VARCHAR(64), sqlcode INTEGER)
+begin
+  DECLARE something CONDITION FOR SQLSTATE "12345";
+
+  SIGNAL something SET
+    MESSAGE_TEXT = message_text,
+    SQLCODE = sqlcode;
+end $$
+
+--error 1
+call test_signal(NULL, NULL) $$
+
+--error 5678
+call test_signal("Parameter string", 5678) $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE something CONDITION FOR SQLSTATE "AABBB";
+
+  SIGNAL something SET
+    MESSAGE_TEXT = @message_text,
+    SQLCODE = @sqlcode;
+end $$
+
+--error 1
+call test_signal() $$
+
+set @message_text= "User variable" $$
+set @sqlcode= 12 $$
+
+--error 12
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE something CONDITION FOR SQLSTATE "12345";
+
+  SIGNAL something SET
+    MESSAGE_TEXT = concat("functions", " also works"),
+    SQLCODE = 1000 + 12;
+end $$
+
+--error 1012
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal(code integer)
+begin
+  DECLARE something CONDITION FOR SQLSTATE "12345";
+
+  SIGNAL something SET
+    MESSAGE_TEXT = (select message_text from t1 where id=code),
+    SQLCODE = (select sqlcode from t1 where id=code);
+end $$
+
+--disable_warnings
+drop table if exists t1 $$
+--enable_warnings
+
+--error ER_NO_SUCH_TABLE
+call test_signal(1) $$
+
+create table t1(id integer, message_text varchar(64), sqlcode integer) $$
+
+--error 1
+call test_signal(1) $$
+
+insert into t1 values ((1), ("First message"), (1001)) $$
+insert into t1 values ((2), ("Second message"), (1002)) $$
+
+--error 1001
+call test_signal(1) $$
+
+--error 1002
+call test_signal(2) $$
+
+alter table t1 drop column message_text $$
+
+--error ER_BAD_FIELD_ERROR
+call test_signal(2) $$
+
+drop table t1 $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE warn CONDITION FOR SQLSTATE "01234";
+
+  SIGNAL warn SET
+    CLASS_ORIGIN = repeat("A", 64),
+    SUBCLASS_ORIGIN = repeat("B", 64),
+    CONSTRAINT_CATALOG = repeat("C", 64),
+    CONSTRAINT_SCHEMA = repeat("D", 64),
+    CONSTRAINT_NAME = repeat("E", 64),
+    CATALOG_NAME =repeat("F", 64),
+    SCHEMA_NAME =repeat("G", 64),
+    TABLE_NAME = repeat("H", 64),
+    COLUMN_NAME =repeat("I", 64),
+    CURSOR_NAME = repeat("J", 64),
+    MESSAGE_TEXT = repeat("K", 128),
+    SQLCODE = 4294967295;
+end $$
+
+call test_signal() $$
+drop procedure test_signal $$
+
+create procedure test_signal()
+begin
+  DECLARE warn CONDITION FOR SQLSTATE "01234";
+
+  SIGNAL warn SET
+    CLASS_ORIGIN = concat(repeat("A", 64), "X"),
+    SUBCLASS_ORIGIN = concat(repeat("B", 64), "X"),
+    CONSTRAINT_CATALOG = concat(repeat("C", 64), "X"),
+    CONSTRAINT_SCHEMA = concat(repeat("D", 64), "X"),
+    CONSTRAINT_NAME = concat(repeat("E", 64), "X"),
+    CATALOG_NAME = concat(repeat("F", 64), "X"),
+    SCHEMA_NAME = concat(repeat("G", 64), "X"),
+    TABLE_NAME = concat(repeat("H", 64), "X"),
+    COLUMN_NAME = concat(repeat("I", 64), "X"),
+    CURSOR_NAME = concat(repeat("J", 64), "X"),
+    MESSAGE_TEXT = concat(repeat("1", 100),
+                          repeat("2", 20),
+                          repeat("8", 8),
+                          "X"),
+    SQLCODE = 999999999999999999999999999999999999999999999999999;
+end $$
+
+#NOTE: the warning text for ER_TRUNCATED_WRONG_VALUE contains
+# value: '%-.128s', so the warning printed truncates the value too,
+# which affects MESSAGE_TEXT (the X is missing)
+
+#NOTE: ER_TRUNCATED_WRONG_VALUE is raised as an error for DECIMAL,
+# it's an existing bug (TODO: report it)
+call test_signal() $$
+drop procedure test_signal $$
 
 delimiter ;$$
 
diff -Nrup a/sql/sql_class.h b/sql/sql_class.h
--- a/sql/sql_class.h	2008-04-29 17:34:14 -06:00
+++ b/sql/sql_class.h	2008-05-01 11:34:38 -06:00
@@ -1135,7 +1135,7 @@ public:
            MYSQL_ERROR::enum_warning_level level, myf MyFlags);
 
   void set_utf8_message_text(const char* str);
-  void set_message_text(const String *str);
+  void set_message_text(String *str);
   const char* get_message_text() const;
 
   void set_sqlstate(const char* sqlstate);
diff -Nrup a/sql/sql_signal.cc b/sql/sql_signal.cc
--- a/sql/sql_signal.cc	2008-04-29 17:34:14 -06:00
+++ b/sql/sql_signal.cc	2008-05-01 11:34:39 -06:00
@@ -141,12 +141,33 @@ SQL_condition::set_utf8_message_text(con
 }
 
 void
-SQL_condition::set_message_text(const String *str)
+SQL_condition::set_message_text(String *str)
 {
-  m_message_text.copy(*str);
-  // FIXME: message_length
-  m_message_length= m_message_text.length();
-  m_message_octet_length= m_message_text.length();
+  if (str)
+  {
+    if (str->length() > 128)
+    {
+      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                          ER_TRUNCATED_WRONG_VALUE,
+                          ER(ER_TRUNCATED_WRONG_VALUE),
+                          "VARCHAR(128)", str->c_ptr());
+
+      m_message_text.length(0);
+      m_message_text.append(str->c_ptr(), 128);
+    }
+    else
+      m_message_text.copy(*str);
+
+    // FIXME: message_length
+    m_message_length= m_message_text.length();
+    m_message_octet_length= m_message_text.length();
+  }
+  else
+  {
+    m_message_text.length(0);
+    m_message_length= 0;
+    m_message_octet_length= 0;
+  }
 }
 
 const char*
@@ -245,80 +266,117 @@ int Abstract_signal::eval_defaults(THD *
   return 0;
 }
 
+void set_cond_64_string(String *str, String *value)
+{
+  if (value)
+  {
+    if (value->length() > 64)
+    {
+      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                          ER_TRUNCATED_WRONG_VALUE,
+                          ER(ER_TRUNCATED_WRONG_VALUE),
+                          "VARCHAR(64)", value->c_ptr());
+
+      str->length(0);
+      str->append(value->c_ptr(), 64);
+    }
+    else
+      str->copy(*value);
+  }
+  else
+    str->length(0);
+}
+
 int Abstract_signal::eval_signal_informations(THD *thd, SQL_condition *cond)
 {
   Item *set;
   String str_value;
   String *str;
+  int i;
+
+  DBUG_ENTER("Abstract_signal::eval_signal_informations");
+
+  for (i= FIRST_DIAG_SET_PROPERTY;
+       i <= LAST_DIAG_SET_PROPERTY;
+       i++)
+  {
+    set= m_set_signal_information.m_item[i];
+    if (set)
+    {
+      if (set->fix_fields(thd, & set))
+        DBUG_RETURN(1);
+      m_set_signal_information.m_item[i]= set;
+    }
+  }
 
   set= m_set_signal_information.m_item[DIAG_CLASS_ORIGIN];
   if (set != NULL)
   {
     str= set->val_str(& str_value);
-    cond->m_class_origin.copy(*str);
+    set_cond_64_string(& cond->m_class_origin, str);
   }
 
   set= m_set_signal_information.m_item[DIAG_SUBCLASS_ORIGIN];
   if (set != NULL)
   {
     str= set->val_str(& str_value);
-    cond->m_subclass_origin.copy(*str);
+    set_cond_64_string(& cond->m_subclass_origin, str);
   }
 
   set= m_set_signal_information.m_item[DIAG_CONSTRAINT_CATALOG];
   if (set != NULL)
   {
     str= set->val_str(& str_value);
-    cond->m_constraint_catalog.copy(*str);
+    set_cond_64_string(& cond->m_constraint_catalog, str);
   }
 
   set= m_set_signal_information.m_item[DIAG_CONSTRAINT_SCHEMA];
   if (set != NULL)
   {
     str= set->val_str(& str_value);
-    cond->m_constraint_schema.copy(*str);
+    set_cond_64_string(& cond->m_constraint_schema, str);
   }
 
   set= m_set_signal_information.m_item[DIAG_CONSTRAINT_NAME];
   if (set != NULL)
   {
     str= set->val_str(& str_value);
-    cond->m_constraint_name.copy(*str);
+    set_cond_64_string(& cond->m_constraint_name, str);
   }
 
   set= m_set_signal_information.m_item[DIAG_CATALOG_NAME];
   if (set != NULL)
   {
     str= set->val_str(& str_value);
-    cond->m_catalog_name.copy(*str);
+    set_cond_64_string(& cond->m_catalog_name, str);
   }
 
   set= m_set_signal_information.m_item[DIAG_SCHEMA_NAME];
   if (set != NULL)
   {
     str= set->val_str(& str_value);
-    cond->m_schema_name.copy(*str);
+    set_cond_64_string(& cond->m_schema_name, str);
   }
 
   set= m_set_signal_information.m_item[DIAG_TABLE_NAME];
   if (set != NULL)
   {
     str= set->val_str(& str_value);
-    cond->m_table_name.copy(*str);
+    set_cond_64_string(& cond->m_table_name, str);
   }
 
   set= m_set_signal_information.m_item[DIAG_COLUMN_NAME];
   if (set != NULL)
   {
     str= set->val_str(& str_value);
-    cond->m_column_name.copy(*str);
+    set_cond_64_string(& cond->m_column_name, str);
   }
 
   set= m_set_signal_information.m_item[DIAG_CURSOR_NAME];
   if (set != NULL)
   {
     str= set->val_str(& str_value);
-    cond->m_cursor_name.copy(*str);
+    set_cond_64_string(& cond->m_cursor_name, str);
   }
 
   set= m_set_signal_information.m_item[DIAG_MESSAGE_TEXT];
@@ -331,42 +389,69 @@ int Abstract_signal::eval_signal_informa
   set= m_set_signal_information.m_item[DIAG_SQLCODE];
   if (set != NULL)
   {
-    cond->m_sqlcode= set->val_int();
+    if (set->is_null())
+      cond->m_sqlcode= SIGNAL_DEFAULT_SQLCODE;
+    else
+      cond->m_sqlcode= set->val_int();
   }
 
-  return 0;
+  if (thd->is_error())
+    DBUG_RETURN(1);
+
+  DBUG_RETURN(0);
 }
 
 int SQLCOM_signal::execute(THD *thd)
 {
   int result= 1;
   SQL_condition cond;
+  TABLE_LIST *all_tables= thd->lex->query_tables;
+
+
+  DBUG_ENTER("SQLCOM_signal::execute");
+
+  thd->main_da.reset_diagnostics_area();
+  thd->row_count_func= 0;
+  mysql_reset_errors(thd, TRUE);
+
+  if (check_table_access(thd, SELECT_ACL, all_tables, FALSE, FALSE, UINT_MAX))
+    DBUG_RETURN(result);
+
+  if (open_and_lock_tables(thd, all_tables))
+    DBUG_RETURN(result);
 
   if (eval_sqlcode_sqlstate(thd, & cond))
-    return result;
+    DBUG_RETURN(result);
 
   if (eval_defaults(thd, & cond))
-    return result;
+    DBUG_RETURN(result);
 
   if (eval_signal_informations(thd, & cond))
-    return result;
+    DBUG_RETURN(result);
+
+  /* SIGNAL should not signal WARN_LEVEL_NOTE */
+  DBUG_ASSERT((cond.m_level == MYSQL_ERROR::WARN_LEVEL_WARN) ||
+              (cond.m_level == MYSQL_ERROR::WARN_LEVEL_ERROR));
 
   thd->raise_condition(& cond);
 
   if (cond.m_level == MYSQL_ERROR::WARN_LEVEL_WARN)
     result= 0;
-  return result;
+
+  DBUG_RETURN(result);
 }
 
 int SQLCOM_resignal::execute(THD *thd)
 {
+  DBUG_ENTER("SQLCOM_resignal::execute");
   my_error(ER_NOT_SUPPORTED_YET, MYF(0), "RESIGNAL");
-  return 1;
+  DBUG_RETURN(1);
 }
 
 int SQLCOM_get_diag::execute(THD *thd)
 {
+  DBUG_ENTER("SQLCOM_get_diag::execute");
   my_error(ER_NOT_SUPPORTED_YET, MYF(0), "GET DIAGNOSTICS");
-  return 1;
+  DBUG_RETURN(1);
 }
 
Thread
bk commit into 6.0 tree (malff:1.2638) BUG#11661 WL#2110marc.alff1 May