List:Commits« Previous MessageNext Message »
From:Bjorn Munch Date:August 3 2010 2:11pm
Subject:bzr commit into mysql-5.1-mtr branch (bjorn.bunch:2921) Bug#55582
View as plain text  
#At file:///home/bm136801/my/noroot-51/ based on revid:bjorn.bunch@stripped

 2921 Bjorn Munch	2010-08-03
      Bug #55582 mtr root detection (and if-expression execution) broken
      if() treated any non-numeric string as false
      Fixed to treat those as true instead
      Added some test cases
      Fixed missing $ in variable name in include/mix2.inc

    modified:
      client/mysqltest.cc
      mysql-test/include/mix2.inc
      mysql-test/r/mysqltest.result
      mysql-test/t/mysqltest.test
=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2010-06-15 09:29:24 +0000
+++ b/client/mysqltest.cc	2010-08-03 14:11:23 +0000
@@ -2383,6 +2383,9 @@ void eval_expr(VAR *v, const char *p, co
     if ((vp= var_get(p, p_end, 0, 0)))
       var_copy(v, vp);
 
+    /* Apparently it is not safe to assume null-terminated string */
+    v->str_val[v->str_val_len]= 0;
+
     /* Make sure there was just a $variable and nothing else */
     const char* end= *p_end + 1;
     if (end < expected_end)
@@ -5391,8 +5394,20 @@ void do_block(enum block_cmd cmd, struct
   /* Define inner block */
   cur_block++;
   cur_block->cmd= cmd;
-  cur_block->ok= (v.int_val ? TRUE : FALSE);
+  if (v.int_val)
+  {
+    cur_block->ok= TRUE;
+  } else
+  /* Any non-empty string which does not begin with 0 is also TRUE */
+  {
+    p= v.str_val;
+    /* First skip any leading white space or unary -+ */
+    while (*p && ((my_isspace(charset_info, *p) || *p == '-' || *p == '+')))
+      p++;
 
+    cur_block->ok= (*p && *p != '0') ? TRUE : FALSE;
+  }
+  
   if (not_expr)
     cur_block->ok = !cur_block->ok;
 

=== modified file 'mysql-test/include/mix2.inc'
--- a/mysql-test/include/mix2.inc	2007-06-06 17:57:07 +0000
+++ b/mysql-test/include/mix2.inc	2010-08-03 14:11:23 +0000
@@ -1910,7 +1910,7 @@ select hex(s1) from t4;
 drop table t1,t2,t3,t4;
 }
 
-if (test_foreign_keys)
+if ($test_foreign_keys)
 {
 eval create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=$engine_type;
 eval create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=$engine_type;
@@ -2405,7 +2405,7 @@ drop table t1, t2, t3, t5, t6, t8, t9;
 }
 # End transactional tests
 
-if (test_foreign_keys)
+if ($test_foreign_keys)
 {
 # bug 18934, "InnoDB crashes when table uses column names like DB_ROW_ID"
 --error 1005

=== modified file 'mysql-test/r/mysqltest.result'
--- a/mysql-test/r/mysqltest.result	2010-03-22 10:28:57 +0000
+++ b/mysql-test/r/mysqltest.result	2010-08-03 14:11:23 +0000
@@ -393,6 +393,8 @@ true-inner again
 true-outer
 Counter is greater than 0, (counter=10)
 Counter is not 0, (counter=0)
+Counter is true, (counter=alpha)
+Beta is true
 1
 Testing while with not
 mysqltest: In included file "MYSQLTEST_VARDIR/tmp/mysqltest_while.inc": At line 64: Nesting too deeply

=== modified file 'mysql-test/t/mysqltest.test'
--- a/mysql-test/t/mysqltest.test	2010-03-22 10:28:57 +0000
+++ b/mysql-test/t/mysqltest.test	2010-08-03 14:11:23 +0000
@@ -1106,6 +1106,25 @@ if (!$counter)
 }
 
 # ----------------------------------------------------------------------------
+# Test if with some non-numerics
+# ----------------------------------------------------------------------------
+
+let $counter=alpha;
+if ($counter)
+{
+  echo Counter is true, (counter=alpha);
+}
+let $counter=   ;
+if ($counter)
+{
+  echo oops, space is true;
+}
+if (beta)
+{
+  echo Beta is true;
+}
+
+# ----------------------------------------------------------------------------
 # Test while, { and }
 # ----------------------------------------------------------------------------
 


Attachment: [text/bzr-bundle] bzr/bjorn.bunch@oracle.com-20100803141123-topqm9i6w1wvsimk.bundle
Thread
bzr commit into mysql-5.1-mtr branch (bjorn.bunch:2921) Bug#55582Bjorn Munch3 Aug