Uploaded image for project: 'iBatis for .NET'
  1. iBatis for .NET
  2. IBATISNET-278

Iterator literals ($filters[].FieldName$) aren't parsed properly when used within conditional tags

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • DataMapper
    • None

    Description

      Apparently we don't fully support using iterate literals inside conditional tags. This doesn't work:

      <isPropertyAvailable property="filters">
      AND
      <iterate open="(" close=")" property="filters" conjunction=" AND ">
      <isEqual property="filters[].FilterTypeValue" compareValue="IsEqualTo">$filters[].FieldName$ = #filters[].Begin#</isEqual>
      <isEqual property="filters[].FilterTypeValue" compareValue="IsNotEqualTo">$filters[].FieldName$ <> #filters[].Begin#</isEqual>
      <isEqual property="filters[].FilterTypeValue" compareValue="IsGreaterThan">$filters[].FieldName$ > #filters[].Begin#</isEqual>
      </iterate>
      </isPropertyAvailable>

      The problem is that the filters[] tokens aren't being expanded to hold the current iterator value:

      #filters[0].Begin#
      #filters[1].Begin#
      etc...

      $filters[0].FieldName$
      $filters[0].FieldName$
      etc...

      I hacked up the code in DynamicSql.cs that handles adding SqlText fragments (around line 256):

      // DynamicSql.cs
      ParameterProperty[] parameters = sqlText.Parameters;
      if (parameters != null)
      {
      int length = parameters.Length;
      for (int i = 0; i< length; i++)
      {
      ParameterProperty parameterProperty = parameters[i];

      // HACK!
      IterateContext iterateContext = ctx.PeekIterateContext();
      if (iterateContext != null)
      {
      int currentIterateIndex = 0;
      if (ctx.PeekIterateContext().Index > 0)

      { currentIterateIndex = ctx.PeekIterateContext().Index; }

      parameterProperty.PropertyName = parameterProperty.PropertyName.Replace("[]", "[" + currentIterateIndex + "]");
      }

      ctx.AddParameterMapping(parameterProperty);
      }
      }

      as well as ConditionalTagHandler.DoEndFragment. Its not really patch worthy...I just hacked the code to make my stuff work :-/

      // ConditionalTagHandler.cs
      public override int DoEndFragment(...)
      {
      Iterate iterateTag = tag.Parent as Iterate;

      if (iterateTag != null)

      { // HACK! iterate.Index starts at -1 IterateContext iterate = ctx.PeekIterateContext(); string find = iterateTag.Property + "[]"; tring replace = iterateTag.Property + "[" + (iterate.Index + 1) + "]"; //Parameter-index-Dynamic Replace(bodyContent, find, replace); }

      return BaseTagHandler.INCLUDE_BODY;
      }

      The Java version seems to support that as well as the concept of nested iterators:

      http://issues.apache.org/jira/browse/IBATIS-131
      http://issues.apache.org/jira/browse/IBATIS-281
      http://issues.apache.org/jira/browse/IBATIS-293

      Attachments

        Activity

          People

            Unassigned Unassigned
            ron liu ron
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: