コード例 #1
0
        public void testSimpleOrFilter()
        {
            Authentication auth = BuildAuthentication();
            Query          q    = new Query(InfrastructureDTD.AUTHENTICATION, GroupOperator.Or);

            q.AddCondition(InfrastructureDTD.AUTHENTICATIONINFO_DISTINGUISHEDNAME, ComparisonOperators.EQ, "foo");
            q.AddCondition(InfrastructureDTD.AUTHENTICATION_REFID, ComparisonOperators.EQ, REFID_GUID);
            Assert.IsTrue(q.Evaluate(auth));
        }
コード例 #2
0
        public void TestQueryCompare()
        {
            Query query = new Query(StudentDTD.STUDENTSCHOOLENROLLMENT, GroupOperator.Or);

            query.AddCondition(StudentDTD.STUDENTSCHOOLENROLLMENT_TIMEFRAME, ComparisonOperators.EQ, TimeFrame.CURRENT.Value);
            query.AddCondition(StudentDTD.STUDENTSCHOOLENROLLMENT_TIMEFRAME, ComparisonOperators.EQ, TimeFrame.FUTURE.Value);

            StudentSchoolEnrollment studentSchoolEnrollment = new StudentSchoolEnrollment();

            studentSchoolEnrollment.TimeFrame = TimeFrame.HISTORICAL.Value;
            Assert.IsFalse(query.Evaluate(studentSchoolEnrollment));
        }
コード例 #3
0
        private Query testResolveBySQP(IElementDef objectDef, String sqp,
                                       SifVersion version, IElementDef resolvedNestedElement)
        {
            Adk.SifVersion = version;

            Query q = new Query(objectDef);

            q.AddCondition(sqp, ComparisonOperators.EQ, "foo");
            String sifQueryXML = q.ToXml();

            Console.WriteLine(sifQueryXML);

            String searchFor = "<SIF_Element>" + sqp + "</SIF_Element>";

            // The .Net ADK doesn't encode apostrophes when they are in
            // element content, so the following line is different than
            // the java test
            //searchFor = searchFor.Replace( "'", "&apos;" );
            Assert.IsTrue(sifQueryXML.Contains(searchFor), "SQP in XML");

            SifParser   parser = SifParser.NewInstance();
            SIF_Request sifR   = (SIF_Request)parser.Parse("<SIF_Request>"
                                                           + sifQueryXML + "</SIF_Request>", null);

            Query newQuery = new Query(sifR.SIF_Query);

            Condition cond = newQuery.HasCondition(sqp);

            Assert.IsNotNull(cond, "hasCondition");
            Assert.AreEqual(sqp, cond.GetXPath(), "SQP");
            Assert.AreEqual(sqp, cond.GetXPath(newQuery,
                                               version), "Version-Specific SQP");

            return(newQuery);
        }
コード例 #4
0
        /**
         * Test SIF Query Pattern support in the ADK
         *
         * @param objectDef
         *            The IElementDef representing the root SIF Object
         * @param def
         *            The IElementDef representing the field being queried (e.g.
         *            CommonDTD.NAME_FIRSTNAME)
         * @param sqp
         *            The expected SIF Query Pattern (e.g. "Name/FirstName") for the
         *            above field def
         * @param version
         *            The version of SIF to test
         */

        private Query testSQP(IElementDef objectDef, IElementDef def, String sqp,
                              SifVersion version)
        {
            Adk.SifVersion = version;
            IElementDef lookedUp = Adk.Dtd.LookupElementDefBySQP(objectDef, sqp);

            Assert.AreEqual(def.Name, lookedUp.Name, "IElementDef");
            testResolveBySQP(objectDef, sqp, version, def);

            Query q = new Query(objectDef);

            q.AddCondition(def, ComparisonOperators.EQ, "foo");

            String sifQueryXML = q.ToXml();

            Console.WriteLine(sifQueryXML);

            String searchFor = "<SIF_Element>" + sqp + "</SIF_Element>";

            Assert.IsTrue(sifQueryXML.Contains(searchFor), "SQP in XML");

            SifParser   parser = SifParser.NewInstance();
            SIF_Request sifR   = (SIF_Request)parser.Parse("<SIF_Request>"
                                                           + sifQueryXML + "</SIF_Request>", null);

            Query newQuery = new Query(sifR.SIF_Query);

            Condition cond = newQuery.HasCondition(sqp);

            Assert.IsNotNull(cond, "hasCondition");
            Assert.AreEqual(sqp, cond.GetXPath(), "SQP");
            Assert.AreEqual(def, cond.Field, "IElementDef");

            return(newQuery);
        }
コード例 #5
0
        /// <summary>
        /// This method will check the cache for dependent objects that have yet to be received and make a SIF
        /// Request them.
        /// </summary>
        /// <param name="zones">Zones that the SIF Request need to be made on.</param>
        private void RequestDependentObjects(IZone[] zones)
        {
            foreach (IZone zone in zones)
            {
                ICollection <DependentObject> dependentObjects = cacheService.RetrieveNotYetRequested(SifObjectType.Name, ApplicationId, zone.ZoneId);
                if (log.IsDebugEnabled)
                {
                    log.Debug(this.GetType().Name + " found " + dependentObjects.Count + " " + SifObjectType.Name + " dependent objects for application " + ApplicationId + " in zone " + zone.ZoneId + ".");
                }

                foreach (DependentObject dependentObject in dependentObjects)
                {
                    // Create a Query for the SIF Data Object type.
                    Query query = new Query(SifObjectType);
                    // Without this, an error occurs.
                    query.SifVersions = new SifVersion[] { AgentConfiguration.Version };
                    ICollection <SifRefIdMetadata> metadataValues = SifDataObjectMetadata <T> .ParseSifUniqueId(dependentObject.ObjectKeyValue);

                    foreach (SifRefIdMetadata metadataValue in metadataValues)
                    {
                        query.AddCondition(metadataValue.XPath, ComparisonOperators.EQ, metadataValue.Value);
                    }

                    zone.Query(query);
                    cacheService.MarkAsRequested(dependentObject, AgentConfiguration.SourceId, zone.ZoneId);
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Made a request for " + SifObjectType.Name + " with SIF RefId credentials of " + dependentObject.ObjectKeyValue + ".");
                    }
                }
            }
        }
コード例 #6
0
        public void testSimpleRefidFilterFail()
        {
            Authentication auth = BuildAuthentication();
            Query          q    = new Query(InfrastructureDTD.AUTHENTICATION);

            q.AddCondition(InfrastructureDTD.AUTHENTICATION_REFID, ComparisonOperators.EQ, "FAIL");
            Assert.IsFalse(q.Evaluate(auth));
        }
コード例 #7
0
 /// <summary>
 /// Filter the SIF Request to a student whose SIF RefId is 7C834EA9EDA12090347F83297E1C290C.
 /// </summary>
 /// <param name="query">SIF Query that contains the filter condition.</param>
 /// <param name="zone">Zone to make the SIF Request on.</param>
 protected override void AddToBroadcastRequestQuery(Query query, IZone zone)
 {
     if (log.IsDebugEnabled)
     {
         log.Debug("Added a condition to the request query for StudentPersonal SIF RefId of 7C834EA9EDA12090347F83297E1C290C.");
     }
     query.AddCondition(StudentDTD.STUDENTPERSONAL_REFID, ComparisonOperators.EQ, "7C834EA9EDA12090347F83297E1C290C");
 }
コード例 #8
0
        public void testConditionWithNullValue()
        {
            StudentPersonal sp = new StudentPersonal(Adk.MakeGuid(), new Name(NameType.BIRTH, "E", "Sally"));

            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            q.AddCondition(CommonDTD.NAME_LASTNAME, ComparisonOperators.GT, null);
            Assert.IsFalse(q.Evaluate(sp));
        }
コード例 #9
0
        public void testSimpleLTFilter()
        {
            StudentPersonal sp = new StudentPersonal(Adk.MakeGuid(), new Name(NameType.BIRTH, "E", "Sally"));

            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            q.AddCondition(CommonDTD.NAME_LASTNAME, ComparisonOperators.LT, "G");
            Assert.IsTrue(q.Evaluate(sp));

            q = new Query(StudentDTD.STUDENTPERSONAL);
            q.AddCondition(CommonDTD.NAME_LASTNAME, ComparisonOperators.LT, "E");
            Assert.IsFalse(q.Evaluate(sp));
        }
コード例 #10
0
        public void testQuery010()
        {
            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            q.AddCondition("Demographics/Ethnicity", ComparisonOperators.EQ, "W");
            Console.WriteLine(q.ToXml());

            q = SaveToXMLAndReparse(q, SifVersion.SIF15r1);

            Condition c = q.HasCondition("Demographics/Ethnicity");

            Assert.IsNotNull(c, "Condition didn't resolve");
        }
コード例 #11
0
        public void testSQLQueryFormatter030()
        {
            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            q.AddCondition(CommonDTD.NAME_FIRSTNAME, ComparisonOperators.EQ, "Johnny");

            IDictionary fields = new Hashtable();

            SQLQueryFormatter formatter = new SQLQueryFormatter();
            String            sql       = formatter.Format(q, fields, false);

            Assert.AreEqual("( 1=1 )", sql, "Query format");
        }
コード例 #12
0
        public void testSQP060()
        {
            // TT 217 Presumptive Query Syntax support
            Query q = new Query(ReportingDTD.STUDENTLOCATOR);

            q.AddCondition("RequestingAgencyId/@Type", ComparisonOperators.EQ,
                           "LEA");
            q.AddCondition("RequestingAgencyId", ComparisonOperators.EQ, "0001");

            q = SaveToXMLAndReparse(q, SifVersion.LATEST);

            Condition c = q.HasCondition(ReportingDTD.REQUESTINGAGENCYID_TYPE);

            Assert.IsNotNull(c);
            String xPath = c.GetXPath(q, SifVersion.LATEST);

            Assert.AreEqual("RequestingAgencyId/@Type", xPath, "RequestingAgencyID/@Type XPath");

            c = q.HasCondition(ReportingDTD.REQUESTINGAGENCYID);
            Assert.IsNotNull(c);
            xPath = c.GetXPath(q, SifVersion.LATEST);
            Assert.AreEqual("RequestingAgencyId", xPath, "RequestingAgencyIDe XPath");
        }
コード例 #13
0
        public void testSQLQueryFormatter010()
        {
            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            q.AddCondition(CommonDTD.NAME_FIRSTNAME, ComparisonOperators.EQ, "Johnny");

            IDictionary fields = new Hashtable();

            fields[CommonDTD.NAME_FIRSTNAME] = new SQLField("vchFirstName", DbType.String);

            SQLQueryFormatter formatter = new SQLQueryFormatter();
            String            sql       = formatter.Format(q, fields);

            Assert.AreEqual("( vchFirstName = 'Johnny' )", sql, "Query format");
        }
コード例 #14
0
        public void testSQP050()
        {
            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            q.AddCondition("OtherIdList/OtherId[@Type='ZZ']",
                           ComparisonOperators.EQ, "SCHOOL:997");

            Condition c = q.HasCondition(CommonDTD.OTHERID);

            Assert.IsNotNull(c);
            String xPath = c.GetXPath(q, SifVersion.SIF15r1);

            Assert.AreEqual(xPath, "OtherId[@Type='ZZ']", "SIF 1.5 XPath");

            xPath = c.GetXPath(q, SifVersion.SIF20);
            Assert.AreEqual("OtherIdList/OtherId[@Type='ZZ']", xPath, "SIF 2.0 XPath");
        }
コード例 #15
0
 public static Query Eq(this Query query, string columnName, object value, bool doNotGenerateForNullValue = false, ConditionEquality conditionEquality = ConditionEquality.Equality)
 {
     //if (!IsNullOrEmpty(value) || !doNotGenerateForNullValue)
     if (AddCondition(value, doNotGenerateForNullValue))
     {
         var item = new SearchItem
         {
             ColumnName          = columnName,
             ConditionEquality   = conditionEquality,
             ConditionStringType = ConditionStringType.Equal,
             ConditionType       = ConditionType.And,
             ValueInSearch       = value,
         };
         query.AddCondition(item);
     }
     return(query);
 }
コード例 #16
0
        public void testSQP040()
        {
            Query q = new Query(StudentDTD.STUDENTSCHOOLENROLLMENT);

            q.AddCondition(StudentDTD.STUDENTSCHOOLENROLLMENT_SCHOOLYEAR,
                           ComparisonOperators.EQ, "2001");

            Condition c = q
                          .HasCondition(StudentDTD.STUDENTSCHOOLENROLLMENT_SCHOOLYEAR);

            Assert.IsNotNull(c);
            String xPath = c.GetXPath(q, SifVersion.SIF15r1);

            Assert.AreEqual("SchoolYear", xPath, "SIF 1.5 XPath");

            xPath = c.GetXPath(q, SifVersion.SIF20);
            Assert.AreEqual("@SchoolYear", xPath, "SIF 2.0 XPath");
        }
コード例 #17
0
        public void testSQLQueryFormatter100()
        {
            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            q.AddCondition("Name/FirstName", ComparisonOperators.LE, "Sally");

            // Convert the query to XML and back
            Query reparsed = QueryTests.SaveToXMLAndReparse(q, SifVersion.LATEST);

            IDictionary fields = new Hashtable();

            fields["Name/FirstName"] =
                new SQLField("Users.FName", DbType.String);

            SQLQueryFormatter formatter = new SQLQueryFormatter();
            String            sql       = formatter.Format(reparsed, fields);

            Assert.AreEqual("( Users.FName <= 'Sally' )", sql, "Query format");
        }
コード例 #18
0
        public void testSQLQueryFormatter050()
        {
            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            q.AddCondition("Demographics/RaceList/Race/Code", ComparisonOperators.EQ, "1002");

            // Convert the query to XML and back
            Query reparsed = QueryTests.SaveToXMLAndReparse(q, SifVersion.LATEST);

            IDictionary fields = new Hashtable();

            fields["Demographics/RaceList/Race/Code"] =
                new SQLField("Users.vchFirstName{0998=I;0999=A;1000=B;1001=H;1002=W}",
                             DbType.String);

            SQLQueryFormatter formatter = new SQLQueryFormatter();
            String            sql       = formatter.Format(reparsed, fields);

            Assert.AreEqual("( Users.vchFirstName = 'W' )", sql, "Query format");
        }
コード例 #19
0
        public void testSQLQueryFormatter020()
        {
            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            q.AddCondition(CommonDTD.NAME_FIRSTNAME, ComparisonOperators.EQ, "Johnny");

            IDictionary fields = new Hashtable();

            SQLQueryFormatter formatter = new SQLQueryFormatter();

            try
            {
                String sql = formatter.Format(q, fields);
            }
            catch (QueryFormatterException)
            {
                // Expected because the map doesn't have an entry for the query condition
                return;
            }

            Assert.Fail("QueryFormatterException should have been thrown");
        }
コード例 #20
0
        private void _processSIF_ZoneStatus(SIF_ZoneStatus zoneStatus, IZone zone)
        {
            if (zoneStatus == null)
            {
                return;
            }

            bool      sync       = getChameleonProperty(zone, "sync", false);
            bool      events     = getChameleonProperty(zone, "logEvents", true);
            bool      logEntry   = getChameleonProperty(zone, "sifLogEntrySupport", false);
            ArrayList objectDefs = new ArrayList();

            SIF_Providers providers = zoneStatus.SIF_Providers;

            if (providers != null)
            {
                foreach (SIF_Provider p in providers)
                {
                    foreach (SIF_Object obj in p.SIF_ObjectList)
                    {
                        // Lookup the topic for each provided object in the zone
                        IElementDef def = Adk.Dtd.LookupElementDef(obj.ObjectName);
                        if (def != null)
                        {
                            objectDefs.Add(def);
                            ITopic topic = TopicFactory.GetInstance(def);
                            if (topic.GetSubscriber() == null)
                            {
                                if (events)
                                {
                                    topic.SetSubscriber(fLogger, new SubscriptionOptions());
                                }
                                if (sync)
                                {
                                    topic.SetQueryResults(fLogger);
                                }
                            }
                        }
                    }
                }
            }

            if (logEntry)
            {
                ITopic sifLogEntryTopic = TopicFactory.GetInstance(InfraDTD.SIF_LOGENTRY);
                sifLogEntryTopic.SetSubscriber(fLogger, new SubscriptionOptions());
            }

            foreach (ITopic topic in TopicFactory.GetAllTopics(SifContext.DEFAULT))
            {
                try
                {
                    // Join the topic to each zone ( causes the agent to subscribe to the joined objects )
                    // TODO: Add an "isJoinedTo()" API to topic so that it doesn't throw an exception
                    if (topic.ObjectType != InfraDTD.SIF_ZONESTATUS.Name)
                    {
                        topic.Join(zone);
                    }
                }
                catch (Exception ex)
                {
                    zone.Log.Error(ex.Message, ex);
                }
            }

            if (sync)
            {
                if (objectDefs.Count == 0)
                {
                    zone.ServerLog.Log
                        (LogLevel.WARNING, "No objects are being provided in this zone", null,
                        "1001");
                }
                string syncObjects = zone.Properties.GetProperty("chameleon.syncObjects");
                foreach (IElementDef def in objectDefs)
                {
                    if (def.IsSupported(Adk.SifVersion))
                    {
                        if (syncObjects == null ||
                            (syncObjects.Length > 0 && syncObjects.IndexOf(def.Name) > -1))
                        {
                            Query q = new Query(def);

                            // Query by specific parameters
                            string condition =
                                zone.Properties.GetProperty
                                    ("chameleon.syncConditions." + def.Name);
                            if (condition != null && condition.Length > 0)
                            {
                                // The condition should be in the format "path=value" e.g "@RefId=123412341...1234|@Name=asdfasdf"
                                String[] queryConditions = condition.Split('|');
                                foreach (String cond in queryConditions)
                                {
                                    string[] conds = cond.Split('=');
                                    if (conds.Length == 2)
                                    {
                                        q.AddCondition(conds[0], "EQ", conds[1]);
                                    }
                                }
                            }

                            if (logEntry)
                            {
                                zone.ServerLog.Log
                                    (LogLevel.INFO,
                                    "Requesting " + q.ObjectType.Name + " from the zone",
                                    q.ToXml(Adk.SifVersion), "1002");
                            }

                            zone.Query(q);
                        }
                    }
                    else
                    {
                        String debug = "Will not request " + def.Name +
                                       " because it is not supported in " +
                                       Adk.SifVersion.ToString();
                        Console.WriteLine(debug);
                        zone.ServerLog.Log(LogLevel.WARNING, debug, null, "1001");
                    }
                }
            }
        }
コード例 #21
0
        public override void WriteEndElement()
        {
            var elem  = _meta.Count < 1 ? null : _meta.Pop();
            var value = _buffer.ToString() ?? "";

            _buffer.Length = 0;

            if (elem is string name)
            {
                if (_meta.Peek() is QueryItem item)
                {
                    switch (elem)
                    {
                    case "alias":
                        item.Alias = value;
                        break;

                    case "item_type":
                        if (_attrBuffer.TryGetValue("keyed_name", out var keyedName))
                        {
                            item.Type = keyedName;
                        }
                        else if (_attrBuffer.TryGetValue("name", out var type))
                        {
                            item.Type = type;
                        }
                        else
                        {
                            item.Attributes["typeId"] = value;
                        }
                        break;

                    case "ref_id":
                        item.Attributes["ref_id"] = value;
                        break;

                    case "filter_xml":
                        item.Attributes["filter_xml"] = value;
                        break;

                    case "offset_fetch_xml":
                        var offsetXml = XElement.Parse(value);
                        item.Offset = (int?)offsetXml.Element("option")?.Element("offset");
                        item.Fetch  = (int?)offsetXml.Element("option")?.Element("fetch");
                        break;
                    }
                }
                else if (_meta.Peek() is SelectExpression select)
                {
                    if (name == "property_name")
                    {
                        item = _meta.OfType <QueryItem>().Last();
                        select.Expression = new PropertyReference(value, item);
                    }
                }
                else if (_meta.Peek() is SortedOrderBy orderBy)
                {
                    switch (name)
                    {
                    case "property_name":
                        item = _meta.OfType <QueryItem>().Last();
                        orderBy.Expression = new PropertyReference(value, item);
                        break;

                    case "sort_order":
                        orderBy.SortOrder = int.Parse(value);
                        break;

                    case "sort_order_direction":
                        orderBy.Ascending = value != "desc";
                        break;
                    }
                }
                else if (_meta.Peek() is ParameterReference param)
                {
                    switch (name)
                    {
                    case "name":
                        param.Name = value;
                        break;

                    case "value":
                        param.DefaultValue = value;
                        break;
                    }
                }
                else if (_meta.Peek() is QueryReference queryRef)
                {
                    switch (name)
                    {
                    case "child_ref_id":
                        queryRef.ChildRefId = value;
                        break;

                    case "filter_xml":
                        queryRef.FilterXml = value;
                        break;

                    case "parent_ref_id":
                        queryRef.ParentRefId = value;
                        break;

                    case "ref_id":
                        queryRef.RefId = value;
                        break;

                    case "start_query_reference_path":
                        queryRef.StartQueryReferencePath = value;
                        break;
                    }
                }
                else if (name == "qry_QueryDefinition")
                {
                    var settings = new FilterSettings()
                    {
                        Items = _items
                                .Where(i => i.Attributes.ContainsKey("ref_id"))
                                .ToDictionary(i => i.Attributes["ref_id"]),
                    };

                    foreach (var reference in _refs.Where(r => !string.IsNullOrEmpty(r.ParentRefId)))
                    {
                        var parent = settings.Items[reference.ParentRefId];
                        var child  = settings.Items[reference.ChildRefId];
                        settings.ItemCallback = x =>
                        {
                            if (string.Equals(x, "parent::Item", StringComparison.OrdinalIgnoreCase))
                            {
                                return(parent);
                            }
                            return(child);
                        };
                        var join = new Join()
                        {
                            Condition = ProcessFilter(XElement.Parse(reference.FilterXml), settings, null),
                            Left      = parent,
                            Right     = child,
                            Type      = JoinType.LeftOuter
                        };
                        parent.Joins.Add(join);
                        settings.Joins[reference.RefId] = join;
                    }

                    foreach (var i in _items)
                    {
                        if (i.Attributes.TryGetValue("filter_xml", out var filter))
                        {
                            settings.ItemCallback = x =>
                            {
                                if (string.Equals(x, "child::Item", StringComparison.OrdinalIgnoreCase))
                                {
                                    return(i.Joins[0].Right);
                                }
                                return(i);
                            };
                            i.Attributes.Remove(filter);
                            i.Where = ProcessFilter(XElement.Parse(filter), settings, null);
                        }
                    }

                    var rootRef = _refs.First(r => string.IsNullOrEmpty(r.ParentRefId));

                    Query = settings.Items[rootRef.ChildRefId];
                    if (!string.IsNullOrEmpty(rootRef.FilterXml))
                    {
                        settings.ItemCallback = x =>
                        {
                            if (string.Equals(x, "child::Item", StringComparison.OrdinalIgnoreCase))
                            {
                                return(Query.Joins[0].Right);
                            }
                            return(Query);
                        };
                        Query.AddCondition(ProcessFilter(XElement.Parse(rootRef.FilterXml), settings, null));
                    }
                    Query.RebalanceCriteria();
                }
            }
        }
コード例 #22
0
        private bool AddConditions(Query q, String whereClause)
        {
            InitializeComparisonList();
            bool added = true;

            whereClause = whereClause.Trim();
            if (whereClause.Length == 0)
            {
                return(added);
            }

            string[]            whereConditions = Regex.Split(whereClause, "[aA][nN][dD]");
            ComparisonOperators cmpOperator     = ComparisonOperators.EQ;

            string[] fields = null;

            if (whereConditions.Length > 0)
            {
                foreach (String condition in whereConditions)
                {
                    fields = null;
                    foreach (KeyValuePair <string, ComparisonOperators> kvp in supportedComparisons)
                    {
                        string cmpString = kvp.Key;
                        cmpOperator = kvp.Value;
                        if (cmpOperator == ComparisonOperators.EQ)
                        {
                            int index = condition.LastIndexOf(cmpString);
                            fields = new string[2];
                            if (index > 0)
                            {
                                fields[0] = condition.Substring(0, index);
                                fields[1] = condition.Substring((index + 1));
                            }
                            else
                            {
                                fields[0] = condition;
                            }
                        }//end if

                        if (fields == null)
                        {
                            fields = Regex.Split(condition, cmpString);
                        }

                        if (fields[0] == condition)
                        {
                            //Means no match found using that current comparison operator
                            //so skip this condition
                            fields = null;
                            continue;
                        }

                        if (fields.Length != 2)
                        {
                            Console.WriteLine("ERROR: Unsupported where clause: " + whereClause);
                            PrintSQLHelp();
                            added = false;
                            break;
                        }

                        string      fieldExpr = fields[0].Trim();
                        IElementDef def       = Adk.Dtd.LookupElementDefBySQP(q.ObjectType, fieldExpr);
                        if (def == null)
                        {
                            Console.WriteLine("ERROR: Unrecognized field in where clause: " + fieldExpr);
                            PrintSQLHelp();
                            added = false;
                            break;
                        }
                        else
                        {
                            if (fieldExpr.IndexOf('[') > 0)
                            {
                                // If there is a square bracket in the field syntax, use the raw XPath,
                                // rather then the ElementDef because using ElementDef restrictions
                                // does not work for XPath expressions that contain predicates
                                // Note that using raw XPath expressions works fine, but the ADK is no longer
                                // going to be able to use version-independent rendering of the query
                                q.AddCondition(fieldExpr, cmpOperator, fields[1].Trim());
                            }
                            else
                            {
                                q.AddCondition(def, cmpOperator, fields[1].Trim());
                            }
                            //our condition has been found, no need to check the other comparison
                            //operators for a match so move to the next condition
                            break;
                        }
                    }//end foreach
                }        //end foreach
            }

            return(added);
        }