private IEnumerable <string> _makeSafeLikeClauses()
        {
            string SearchTerm           = _SearchTerm.Trim();
            Collection <string> Clauses = new Collection <string>();

            if (_SearchType == CswEnumSqlLikeMode.Contains)
            {
                // For Contains, we treat each word individually, unless enclosed in quotes

                // Find entries in quotes
                bool StopLoop = false;
                while (SearchTerm.Contains("\"") && false == StopLoop)
                {
                    int begin  = SearchTerm.IndexOf('"');
                    int length = SearchTerm.Substring(begin + 1).IndexOf('"');
                    if (length > 0)
                    {
                        string QueryItem = SearchTerm.Substring(begin + 1, length).Trim();
                        SearchTerm = SearchTerm.Remove(begin, length + 2).Trim();
                        if (false == string.IsNullOrEmpty(QueryItem))
                        {
                            Clauses.Add(CswTools.SafeSqlLikeClause(QueryItem.ToLower(), CswEnumSqlLikeMode.Contains, true));
                        }
                    }
                    else
                    {
                        StopLoop = true;
                    }
                } // while( SearchTerm.Contains( "\"" ) && Continue)

                // Split by spaces (case 27532)
                foreach (string TrimmedQueryItem in SearchTerm.Split(new char[] { ' ' })
                         .Select(QueryItem => QueryItem.Trim())
                         .Where(TrimmedQueryItem => false == string.IsNullOrEmpty(TrimmedQueryItem)))
                {
                    Clauses.Add(CswTools.SafeSqlLikeClause(TrimmedQueryItem.ToLower(), CswEnumSqlLikeMode.Contains, true));
                }
            } // if( _SearchType == CswEnumSqlLikeMode.Contains )
            else
            {
                Clauses.Add(CswTools.SafeSqlLikeClause(SearchTerm.ToLower(), _SearchType, true));
            }
            return(Clauses);
        } // makeSafeLikeClauses
Пример #2
0
        } // removeFilter()

        public ICswNbtTree Results()
        {
            // Filters to apply
            string WhereClause = string.Empty;

            //Collection<Int32> FilteredPropIds = new Collection<Int32>();
            foreach (CswNbtSearchFilter Filter in FiltersApplied)
            {
                if (Filter.Type == CswEnumNbtSearchFilterType.nodetype)
                {
                    // NodeType filter
                    Int32 NodeTypeFirstVersionId = Filter.FirstVersionId;
                    if (NodeTypeFirstVersionId != Int32.MinValue)
                    {
                        WhereClause += " and t.nodetypeid in (select nodetypeid from nodetypes where firstversionid = " + NodeTypeFirstVersionId.ToString() + @") ";
                    }
                }
                else if (Filter.Type == CswEnumNbtSearchFilterType.objectclass)
                {
                    // Object Class filter
                    Int32 ObjectClassId = Filter.ObjectClassId;
                    if (ObjectClassId != Int32.MinValue)
                    {
                        WhereClause += " and t.nodetypeid in (select nodetypeid from nodetypes where objectclassid = " + ObjectClassId.ToString() + @") ";
                    }
                }
                else if (Filter.Type == CswEnumNbtSearchFilterType.propertyset)
                {
                    // PropertySet filter
                    Int32 PropertySetId = Filter.PropertySetId;
                    if (PropertySetId != Int32.MinValue)
                    {
                        WhereClause += " and t.nodetypeid in (select nodetypeid from nodetypes where objectclassid in (select objectclassid from jct_propertyset_objectclass where propertysetid = " + PropertySetId.ToString() + @") )";
                    }
                }
                else if (Filter.Type == CswEnumNbtSearchFilterType.propval)
                {
                    // Property Filter
                    // Someday we may need to do this in a view instead
                    Int32  NodeTypePropFirstVersionId = Filter.FirstPropVersionId;
                    string FilterStr = Filter.FilterValue;
                    if (FilterStr == CswNbtSearchFilter.BlankValue)
                    {
                        FilterStr = " is null";
                    }
                    else
                    {
                        FilterStr = CswTools.SafeSqlLikeClause(FilterStr, CswEnumSqlLikeMode.Begins, false);
                    }

                    if (NodeTypePropFirstVersionId != Int32.MinValue)
                    {
                        WhereClause += @" and n.nodeid in (select nodeid 
                                                             from jct_nodes_props 
                                                            where nodetypepropid in (select nodetypepropid 
                                                                                       from nodetype_props 
                                                                                      where firstpropversionid = (select firstpropversionid 
                                                                                                                    from nodetype_props 
                                                                                                                   where nodetypepropid = " + NodeTypePropFirstVersionId.ToString() + @" ))
                                                              and gestaltsearch " + FilterStr + @") ";
                    }
                } // else if( Filter.Type == CswNbtSearchFilterType.propval )
            }     // foreach( CswNbtSearchFilter Filter in FiltersApplied )

            ICswNbtTree Tree = _CswNbtResources.Trees.getTreeFromSearch(SearchTerm, SearchType, WhereClause, true, false, false, IsSingleNodeType(), OnlyMergeableNodeTypes, ExcludeNodeIds: ExcludeNodeIds);

            return(Tree);
        } // Results()