コード例 #1
0
ファイル: WhereClauseParserTests.cs プロジェクト: Epitomy/CMS
 public void Test2()
 {
     DataRuleContext context = new DataRuleContext(null, null) { ValueProvider = new NameValueCollectionValueProvider(new NameValueCollection()) };
     WhereClause[] clauses = new WhereClause[] {
         new WhereClause(){ FieldName="title", Operator = Operator.Contains, Value1= "title1",Logical = Logical.Or },
         new WhereClause(){ FieldName="title", Operator = Operator.Contains,Value1="title1",Logical = Logical.And },
         new WhereClause(){ FieldName="body", Operator = Operator.Contains,Value1="body1",Logical = Logical.Or },
         new WhereClause(){ FieldName="body", Operator = Operator.Contains,Value1="body2",Logical = Logical.Or },
         new WhereClause(){ FieldName="userkey", Operator = Operator.Contains,Value1="userkey1",Logical = Logical.Or }
     };
     var expression = WhereClauseToContentQueryHelper.Parse(clauses, context);
     var query = new TranslatedQueryMock();
     StringVisitor visitor = new StringVisitor(query);
     visitor.Visite(expression);
     Assert.AreEqual("((((((((title Conatins title1) OR (title Conatins title1))) AND (body Conatins body1))) OR (body Conatins body2))) OR (userkey Conatins userkey1))", query.ClauseText);
 }
コード例 #2
0
ファイル: WhereClause.cs プロジェクト: Epitomy/CMS
 private static IWhereExpression GetExpression(IWhereExpression inner, WhereClause clause, Schema schema, IValueProvider valueProvider)
 {
     var value = ParameterizedFieldValue.GetFieldValue(clause.Value1, valueProvider);
     var fieldValue = Kooboo.CMS.Content.Models.Binder.TextContentBinder.DefaultBinder.ConvertToColumnType(schema, clause.FieldName, value);
     if (clause.Logical == Logical.Or && string.IsNullOrEmpty(value))
     {
         return null;
     }
     switch (clause.Operator)
     {
         case Operator.Equals:
             return new WhereEqualsExpression(inner, clause.FieldName, fieldValue);
         case Operator.NotEquals:
             return new WhereNotEqualsExpression(inner, clause.FieldName, fieldValue);
         case Operator.GreaterThan:
             return new WhereGreaterThanExpression(inner, clause.FieldName, fieldValue);
         case Operator.LessThan:
             return new WhereLessThanExpression(inner, clause.FieldName, fieldValue);
         case Operator.Contains:
             return new WhereContainsExpression(inner, clause.FieldName, fieldValue);
         case Operator.StartsWith:
             return new WhereStartsWithExpression(inner, clause.FieldName, fieldValue);
         case Operator.EndsWith:
             return new WhereEndsWithExpression(inner, clause.FieldName, fieldValue);
         case Operator.Between:
             var value2 = ParameterizedFieldValue.GetFieldValue(clause.Value2, valueProvider);
             var fieldValue2 = Kooboo.CMS.Content.Models.Binder.TextContentBinder.DefaultBinder.ConvertToColumnType(schema, clause.Value2, value2);
             return new WhereBetweenExpression(inner, clause.FieldName, fieldValue, fieldValue2);
         default:
             return null;
     }
 }
コード例 #3
0
ファイル: WhereClause.cs プロジェクト: Godoy/CMS
 private static IWhereExpression GetExpression(IWhereExpression inner, WhereClause clause, Schema schema, IValueProvider valueProvider)
 {
     var binder = EngineContext.Current.Resolve<ITextContentBinder>();
     var value = ParameterizedFieldValue.GetFieldValue(clause.Value1, valueProvider);
     var fieldValue = binder.ConvertToColumnType(schema, clause.FieldName, value);
     if (clause.Logical == Logical.Or && string.IsNullOrEmpty(value))
     {
         return null;
     }
     switch (clause.Operator)
     {
         case Operator.Equals:
             return new WhereEqualsExpression(inner, clause.FieldName, fieldValue);
         case Operator.NotEquals:
             return new WhereNotEqualsExpression(inner, clause.FieldName, fieldValue);
         case Operator.GreaterThan:
             return new WhereGreaterThanExpression(inner, clause.FieldName, fieldValue);
         case Operator.LessThan:
             return new WhereLessThanExpression(inner, clause.FieldName, fieldValue);
         case Operator.Contains:
             return new WhereContainsExpression(inner, clause.FieldName, fieldValue);
         case Operator.StartsWith:
             return new WhereStartsWithExpression(inner, clause.FieldName, fieldValue);
         case Operator.EndsWith:
             return new WhereEndsWithExpression(inner, clause.FieldName, fieldValue);
         case Operator.Between:
             var value2 = ParameterizedFieldValue.GetFieldValue(clause.Value2, valueProvider);
             var fieldValue2 = binder.ConvertToColumnType(schema, clause.Value2, value2);
             return new WhereBetweenExpression(inner, clause.FieldName, fieldValue, fieldValue2);
         case Operator.NotNull:
             return new AndAlsoExpression(new WhereNotEqualsExpression(inner, clause.FieldName, null), new WhereNotEqualsExpression(inner, clause.FieldName, ""));
         case Operator.IsNull:
             return new OrElseExpression(new WhereEqualsExpression(inner, clause.FieldName, null), new WhereEqualsExpression(inner, clause.FieldName, ""));
         default:
             return null;
     }
 }