public void ReadFromSqlExprTest() { var res = new SqlJsonObjectResolver(); var expEngine = new SqlExpressionEngine(res); var expr = expEngine.BuildExpressionTree("c.CustomerId = 12 AND c.CompanyName = 'ahyu' AND c.EmailAddress = @p1 AND c.ModifiedDate = @p2"); var result = QueryExpressionHelper.ReadFromSqlExpr(expr); Assert.Equal("ModifiedDate", result.Right.Left.QueryField.Field.FieldName); Assert.Equal("=", result.Right.Operator); Assert.Equal("@p2", result.Right.Right.Param); }
public void ExpressionParseToStringAndPriorityMappedTest() { var res = new SqlJsonObjectResolver(); var expEngine = new SqlExpressionEngine(res); var expr = expEngine.BuildExpressionTree("p.project_id = @p1 AND a.allocation_id = @p2 OR p.project_id = 0"); var result = QueryExpressionHelper.ReadFromSqlExpr(expr); var text = QueryExpressionHelper.QueryExprToString(result, QueryExpressionHelper.CSharpOperatorsMap); Assert.Equal("((p.project_id == @p1) && (a.allocation_id == @p2)) || (p.project_id == 0)", text); }
public void ExpressionParseToStringOrPriorityParensTest() { var res = new SqlJsonObjectResolver(); var expEngine = new SqlExpressionEngine(res); var expr = expEngine.BuildExpressionTree("p.project_id = @p1 AND (a.allocation_id = @p2 OR p.project_id = 0)"); var result = QueryExpressionHelper.ReadFromSqlExpr(expr); var text = QueryExpressionHelper.QueryExprToString(result); Assert.Equal("(p.project_id = @p1) AND ((a.allocation_id = @p2) OR (p.project_id = 0))", text); }
public void ExpressionParseToStringTest() { var res = new SqlJsonObjectResolver(); var expEngine = new SqlExpressionEngine(res); var expr = expEngine.BuildExpressionTree( "((p.project_id = @p1) AND a.allocation_id = @p2) OR ((p.project_id = 0 AND a.allocation_id = 0) OR u.last_name = 'admin')"); var result = QueryExpressionHelper.ReadFromSqlExpr(expr); var text = QueryExpressionHelper.QueryExprToString(result); Assert.Equal("((p.project_id = @p1) AND (a.allocation_id = @p2)) OR (((p.project_id = 0) AND (a.allocation_id = 0)) OR (u.last_name = 'admin'))", text); }
private void CheckWhereClause() { try { var result = _expressions.BuildExpressionTree(SelectedQuery.WhereClause); QueryExpressionHelper.ReadFromSqlExpr(result); } catch (Exception exc) { ValidationResults.Add(new RuleValidationResult { Type = ValidationResultTypes.Error, Message = $"Where Clause error: {exc.Message}" }); //Errors += "\r\n" + exc.Message; } }
public StoreQuery GenerateQuery(IQueryModel qc) { try { var result = new StoreQuery() { DataService = qc.StoreParameters.DataService, Name = qc.StoreParameters.QueryName, Namespace = qc.StoreParameters.Namespace, ReturnTypeName = qc.StoreParameters.QueryReturnType, SchemaName = qc.Schema.Name, SchemaFile = qc.StoreParameters.SchemaFileName, SchemaVersion = qc.Schema.Version }; result.Query = new StoreQueryDefinition(); result.Query.Fields = qc.SelectionProperties.ToDictionary( p => p.OutputName, p => new StoreQueryField { FieldAlias = p.OutputName, IsOutput = p.IsOutput, GroupByFunction = p.GroupByFunction, Field = new StoreFieldReference { FieldName = p.StoreProperty.Name, ObjectAlias = p.FromTable.Alias } }); result.Query.Tables = qc.FromTables.ToDictionary( t => t.Alias, t => new StoreTableReference { ObjectAlias = t.Alias, TableName = t.StoreDefinition.Name } ); // ToDo: composite foreign keys not supported currently List <StoreObjectJoin> joins = qc.FromTableJoins.Where(f => !f.IsDeleted) .Select(f => { f.Source.JoinType = f.JoinType; return(f.Source); }).ToList(); result.Query.Joins = joins.ToArray(); var expr = _expressions.BuildExpressionTree(qc.WhereClause); var storeExpr = QueryExpressionHelper.ReadFromSqlExpr(expr); result.Query.Where = new StoreQueryCondition { Expression = storeExpr }; var paramsDict = QueryExpressionHelper.GetParamsFromSqlExpr(expr); result.Query.Parameters = paramsDict.ToDictionary(d => d.Key, d => new StoreQueryParameter { Name = d.Key, Type = FindStoreProperty(qc, d.Value)?.Type }); return(result); } catch (Exception exc) { qc.Errors += "\r\n" + exc.Message; return(null); } }