Exemplo n.º 1
0
        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);

            var condItem = FilterParserTool.ParseFilterExpression(column != null ? column.CommonType : new DbTypeString(), colexpr, cond.UsedExpression);

            if (condItem == null)
            {
                throw new Exception("DBSH-00000 Error creating condition");
            }
            cmd.AddAndCondition(condItem);
            return(true);
        }
Exemplo n.º 2
0
 protected static List <ChangeSetCondition> GetPrefixedConditions(List <ChangeSetCondition> conditions, string prefix)
 {
     return((from cond in conditions
             let col = StructuredIdentifier.Parse(cond.Column)
                       let newcol = prefix / col
                                    select new ChangeSetCondition
     {
         Column = newcol.ToString(),
         Expression = cond.Expression,
         ValueToBeEqual = cond.ValueToBeEqual,
     }).ToList());
 }
Exemplo n.º 3
0
        public DmlfColumnRef GetColumnRef(DmlfSource baseSource, NameWithSchema baseTable, StructuredIdentifier columnId, DatabaseInfo db, DmlfJoinType joinType)
        {
            var    relationId = columnId.WithoutLast;
            string column     = columnId.Last;
            var    source     = AddOrFindRelation(baseSource, baseTable, relationId, db, joinType);

            if (source == null)
            {
                return(null);
            }
            return(new DmlfColumnRef
            {
                ColumnName = column,
                Source = source,
            });
        }
Exemplo n.º 4
0
        private DmlfSource DoAddOrFindRelation(DmlfSource baseSource, NameWithSchema baseTable, StructuredIdentifier relationJoined, StructuredIdentifier relationToJoin, DatabaseInfo db, DmlfJoinType joinType)
        {
            if (relationToJoin.IsEmpty)
            {
                return(baseSource);
            }
            string relName = relationToJoin.First;
            string alias   = String.Format("_REF{0}_{1}", relationJoined.NameItems.Select(x => "_" + x).CreateDelimitedText(""), relName);
            var    source  = FindSourceByAlias(alias);

            if (source == null)
            {
                var baseTableInfo = db.FindTable(baseTable);
                var fk            = baseTableInfo.ForeignKeys.FirstOrDefault(x => System.String.Compare(x.ConstraintName, relName, StringComparison.OrdinalIgnoreCase) == 0);
                if (fk == null)
                {
                    var column = baseTableInfo.FindColumn(relName);
                    if (column != null)
                    {
                        fk = column.GetForeignKeys().FirstOrDefault(x => x.Columns.Count == 1);
                    }
                }
                if (fk == null)
                {
                    return(null);
                }

                source = new DmlfSource
                {
                    TableOrView = fk.RefTableFullName,
                    Alias       = alias,
                };
                var relation = new DmlfRelation
                {
                    Reference = source,
                    JoinType  = joinType,
                };
                for (int i = 0; i < fk.Columns.Count; i++)
                {
                    relation.Conditions.Add(new DmlfEqualCondition
                    {
                        LeftExpr = new DmlfColumnRefExpression
                        {
                            Column = new DmlfColumnRef
                            {
                                ColumnName = fk.Columns[0].RefColumnName,
                                Source     = baseSource,
                            }
                        },
                        RightExpr = new DmlfColumnRefExpression
                        {
                            Column = new DmlfColumnRef
                            {
                                ColumnName = fk.RefColumns[0].RefColumnName,
                                Source     = source,
                            }
                        },
                    });
                    Relations.Add(relation);
                }
            }
            if (relationToJoin.IsEmpty)
            {
                return(source);
            }
            return(DoAddOrFindRelation(source, source.TableOrView, relationJoined / relationToJoin.First, relationToJoin.WithoutFirst, db, joinType));
        }
Exemplo n.º 5
0
 public DmlfSource AddOrFindRelation(DmlfSource baseSource, NameWithSchema baseTable, StructuredIdentifier relationId, DatabaseInfo db, DmlfJoinType joinType)
 {
     return(DoAddOrFindRelation(baseSource, baseTable, new StructuredIdentifier(), relationId, db, joinType));
 }