Browse Source

Merge pull request #4083 from ghalliday/issue8939

HPCC-8939 Fix problems with <ebcdic-string1> IN ('a','b')

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 12 years ago
parent
commit
eb4be8d732
2 changed files with 30 additions and 5 deletions
  1. 11 5
      ecl/hqlcpp/hqlcppcase.cpp
  2. 19 0
      ecl/regress/issue8939.ecl

+ 11 - 5
ecl/hqlcpp/hqlcppcase.cpp

@@ -641,10 +641,11 @@ void HqlCppCaseInfo::buildSwitchCondition(BuildCtx & ctx, CHqlBoundExpr & bound)
 void HqlCppCaseInfo::buildSwitchMap(BuildCtx & ctx, const CHqlBoundTarget * target, IHqlExpression * test)
 {
     bool isCharCompare = (test->queryType()->getTypeCode() == type_string);
+    Owned<ITypeInfo> unsigned1Type = makeIntType(1, false);
     
     LinkedHqlExpr cond = test;
     if (isCharCompare)
-        cond.setown(createValue(no_index, makeCharType(), LINK(test), getZero()));
+        cond.setown(createValue(no_implicitcast, LINK(unsigned1Type), createValue(no_index, makeCharType(), LINK(test), getZero())));
     
     BuildCtx subctx(ctx);
     IHqlStmt * stmt = subctx.addSwitch(cond);
@@ -659,10 +660,15 @@ void HqlCppCaseInfo::buildSwitchMap(BuildCtx & ctx, const CHqlBoundTarget * targ
 
         if (isCharCompare)
         {
-            OwnedITypeInfo charType = makeCharType();
-            IValue * cur = compare->queryValue();
-            IValue * next = cur->castTo(charType);
-            compare.setown(createConstant(next));
+            //Coded this way to avoid problems with ascii v ebcdic strings
+            const byte * data = reinterpret_cast<const byte *>((char *)compare->queryValue()->queryValue());
+            byte value = data[0];
+            Owned<IValue> cast;
+            if (value < 127)
+                cast.setown(createCharValue(value, true));
+            else
+                cast.setown(createIntValue(data[0], LINK(unsigned1Type)));
+            compare.setown(createConstant(cast.getClear()));
         }
         
         bool same = false;

+ 19 - 0
ecl/regress/issue8939.ecl

@@ -0,0 +1,19 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2013 HPCC Systems.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+############################################################################## */
+
+ds := DATASET('x', { ebcdic string1 x }, THOR);
+output(ds(x IN ['A', 'B', 'Z']));