[fdo-trac] #719: Defect in filter parsing

FDO trac_fdo at osgeo.org
Wed Nov 3 08:23:38 EDT 2010


#719: Defect in filter parsing
-------------------------------+--------------------------------------------
   Reporter:  maland           |       Owner:  gregboone
       Type:  defect           |      Status:  new      
   Priority:  major            |   Milestone:  3.6.0    
  Component:  ArcSDE Provider  |     Version:  3.5.0    
   Severity:  3                |    Keywords:           
External_id:                   |  
-------------------------------+--------------------------------------------
 There is a defect in the ProcessBinaryLogicalOperator function in
 ArcSDEFilterToSql.cpp. It happens when both operands are "attribute"-style
 filters. The parenthesis matching is broken.

 If you set a filter like this:
 YROW = 0 AND ( XROW = 0 OR XROW = 1)

 Then the generated SQL will be:
 YROW = 0  AND  ( ( ( (XROW)  = (0)  ( OR  ( (XROW)  =  (1) ) ) )

 This is obviously wrong since there is 9 left parenthesis and 7 right
 parenthesis.

 FIX:
 I've not spent enough time on this to understand the point of the
 mUseNesting variable, but the following fix works good for my case.

 Original code:

 {{{
     else if ((leftOpType == ArcSDEFilterType_Attribute) && (rightOpType ==
 ArcSDEFilterType_Attribute))
     {
         // Both operands are "attribute"-style filters, process them both
 (append both to query string):

         if (!mFilterAnalyzed)
             AppendString (OPEN_PAREN);
         else
             if ((mFilterAnalyzed) && (mUseNesting))
                 AppendString (OPEN_PAREN);
         HandleFilter (FdoPtr<FdoFilter>(filter.GetLeftOperand ()));
         if (!mFilterAnalyzed)
             AppendString (OPEN_PAREN);
         else
             if ((mFilterAnalyzed) && (mUseNesting))
                 AppendString (OPEN_PAREN);
         switch (filter.GetOperation ())
         {
             case FdoBinaryLogicalOperations_And:
                 AppendString (LOGICAL_AND);
                 break;
             case FdoBinaryLogicalOperations_Or:
                 AppendString (LOGICAL_OR);
                 break;
             default:
                 throw FdoFilterException::Create
 (NlsMsgGet(ARCSDE_UNSUPPORTED_BINARY_LOGICAL_OPERATOR, "The given binary
 logical operator is not supported."));
         }
         if ((mFilterAnalyzed) && (mUseNesting))
             AppendString (OPEN_PAREN);
         HandleFilter (FdoPtr<FdoFilter>(filter.GetRightOperand ()));
         if ((mFilterAnalyzed) && (mUseNesting))
             AppendString (CLOSE_PAREN);
     }
 }}}


 Modified code:

 {{{
     else if ((leftOpType == ArcSDEFilterType_Attribute) && (rightOpType ==
 ArcSDEFilterType_Attribute))
     {
       // Both operands are "attribute"-style filters, process them both
 (append both to query string):
       AppendString (OPEN_PAREN);
       HandleFilter (FdoPtr<FdoFilter>(filter.GetLeftOperand ()));
       switch (filter.GetOperation ())
       {
       case FdoBinaryLogicalOperations_And:
         AppendString (LOGICAL_AND);
         break;
       case FdoBinaryLogicalOperations_Or:
         AppendString (LOGICAL_OR);
         break;
       default:
         throw FdoFilterException::Create
 (NlsMsgGet(ARCSDE_UNSUPPORTED_BINARY_LOGICAL_OPERATOR, "The given binary
 logical operator is not supported."));
       }
       HandleFilter (FdoPtr<FdoFilter>(filter.GetRightOperand ()));
       AppendString (CLOSE_PAREN);
     }
 }}}

-- 
Ticket URL: <http://trac.osgeo.org/fdo/ticket/719>
FDO <http://fdo.osgeo.org/>
Feature Data Objects


More information about the fdo-trac mailing list