protected static bool GetCondition(DmlfCommandBase cmd, ChangeSetItem item, ChangeSetCondition cond, DatabaseInfo db) { var source = new DmlfSource { Alias = "basetbl", LinkedInfo = item.LinkedInfo, TableOrView = item.TargetTable, }; var colref = cmd.SingleFrom.GetColumnRef(source, item.TargetTable, StructuredIdentifier.Parse(cond.Column), db, DmlfJoinType.Inner); if (colref == null) return false; //var table = db.FindTable(item.TargetTable); //if (table == null) return false; //var column = table.FindColumn(cond.Column); //if (column == null) return false; var colexpr = new DmlfColumnRefExpression { Column = colref }; var column = colref.FindSourceColumn(db); cmd.AddAndCondition(FilterParser.FilterParser.ParseFilterExpression(column != null ? column.CommonType : new DbTypeString(), colexpr, cond.Expression)); return true; }
public void CompileFilter() { if (!Filters.Any()) return; var type = DetectFilterType(FilterType, DbshColumns); var entity = Entities.First(); var expr = new DmlfColumnRefExpression { Column = new DmlfColumnRef { ColumnName = entity.GetColumnName(Alias), Source = entity.QuerySource, } }; var andCondition = new DmlfAndCondition(); foreach (var filter in Filters) { var cond = FilterParser.ParseFilterExpression(type, expr, filter); andCondition.Conditions.Add(cond); } if (andCondition.Conditions.Count == 1) { FilterCondition = andCondition.Conditions[0]; } else { FilterCondition = andCondition; } }
public override DmlfExpression CreateSourceExpression(SourceJoinSqlModel sourceJoinModel, bool aggregate) { var expr = new DmlfColumnRefExpression { Column = new DmlfColumnRef { ColumnName = _col.RefName, Source = _targetSqlModel.GetRefSource(sourceJoinModel.SourceToRefsJoin, sourceJoinModel), } }; return GetExprOrAggregate(expr, aggregate); }
public static DmlfConditionBase CompileSingleFilter(SourceColumn column, string tableAlias) { var expr = new DmlfColumnRefExpression { Column = new DmlfColumnRef { ColumnName = column.Name, Source = new DmlfSource { Alias = tableAlias }, } }; var type = DetectFilterType(column.FilterType, new[] { column }); var cond = FilterParser.ParseFilterExpression(type, expr, column.Filter); return cond; }
public void AddReferenceJoins(DmlfCommandBase command) { foreach (var qitem in _queue) { var relation = new DmlfRelation { JoinType = DmlfJoinType.Inner, Reference = new DmlfSource { Alias = qitem.RefAlias, TableOrView = qitem.RefEntity.TargetTable, }, }; foreach (var col in qitem.BaseEntity.TargetColumns) { if (col.UnderlyingReference != qitem.Fk) continue; var refColumn = new DmlfColumnRefExpression { Column = new DmlfColumnRef { Source = new DmlfSource { Alias = qitem.RefAlias }, ColumnName = col.RefColumnName, } }; relation.Conditions.Add(new DmlfEqualCondition { LeftExpr = col.CreateTargetExpression(qitem.BaseAlias), RightExpr = refColumn, CollateSpec = col.UseCollate(qitem.BaseEntity.SourceJoinModel) ? "DATABASE_DEFAULT" : null, }); } command.SingleFrom.Relations.Add(relation); qitem.RefEntity.CreateLifetimeConditions(command, qitem.RefAlias); qitem.RefEntity.CreateRestrictionCondition(command, qitem.RefAlias, false); } }
private void CreateFilterConditions(DmlfCommandBase cmd) { foreach(var col in SourceJoinModel.Columns.Values) { var colFilterCondition = col.FilterCondition; // process additional condition var additional = _dbsh.AdditionalFilters.FirstOrDefault(x => x.Column == col.Alias); if (additional != null) { var type = SourceColumnSqlModel.DetectFilterType(additional.FilterType, col.DbshColumns); var entity = col.Entities.First(); var expr = new DmlfColumnRefExpression { Column = new DmlfColumnRef { ColumnName = entity.GetColumnName(col.Alias), Source = entity.QuerySource, } }; var additionalCondition = FilterParser.ParseFilterExpression(type, expr, additional.Filter); if (colFilterCondition != null) { var andCondition = new DmlfAndCondition(); andCondition.Conditions.Add(additionalCondition); andCondition.Conditions.Add(colFilterCondition); colFilterCondition = andCondition; } else { colFilterCondition = additionalCondition; } } if (colFilterCondition != null) { var orCond = new DmlfOrCondition(); if (col.Entities.Count == 1) { var entity = col.Entities.Single(); if (entity.SingleKeyColumnNameOrAlias != null) { var expr = new DmlfColumnRefExpression { Column = new DmlfColumnRef { ColumnName = entity.GetColumnName(entity.SingleKeyColumnNameOrAlias), Source = entity.QuerySource, } }; orCond.Conditions.Add(new DmlfIsNullCondition { Expr = expr, }); } } if (orCond.Conditions.Any()) { orCond.Conditions.Add(colFilterCondition); cmd.AddAndCondition(orCond); } else { cmd.AddAndCondition(colFilterCondition); } } } }