internal ColumnAlias(DbmsRelationTree table, DbmsColumn column) { _Table = table; _Column = column; _IsUniqueName = false; _Alias = null; }
private string BuildJoinClause(DbmsRelationTree startTable) { StringBuilder joinClause = new StringBuilder(); joinClause.AppendFormat(startTable.QualifiedName); joinClause.Append(" "); joinClause.AppendLine(startTable.LinkProperty.Alias); foreach (DbmsForeignKey fk in startTable.ForeignKeys) // INNER JOIN first { if (!fk.IsNullable) // ForeignKeyColumns is not null { AppendJoinSource(joinClause, fk); } } foreach (DbmsForeignKey fk in startTable.ForeignKeys) // Then LEFT JOIN { if (fk.IsNullable) // ForeignKeyColumns is nullable { AppendJoinSource(joinClause, fk); } } return(joinClause.ToString()); }
public DbmsForeignKey(string constraintName, DbmsRelationTree foreignKeyBaseTable, string primaryUniqueKeyBaseTableName) { _ConstraintName = constraintName; _ForeignKeyBaseTable = foreignKeyBaseTable; _PrimaryUniqueKeyBaseTable = new DbmsRelationTree(primaryUniqueKeyBaseTableName, this); _ForeignKeyColumns = new List <DbmsColumn>(); _PrimaryUniqueKeyColumns = new List <DbmsColumn>(); }
private void TraverseRelationTree(DbmsRelationTree nodeTable, string parentAlias, byte position) { nodeTable.LinkProperty = new TableLink(this, parentAlias, position); foreach (DbmsColumn col in nodeTable.DisplayColumns) { _ColumnAliases.Add(new ColumnAlias(nodeTable, col)); } for (byte pos = 0; pos < nodeTable.ForeignKeys.Count; pos++) { TraverseRelationTree(nodeTable.ForeignKeys[pos].PrimaryUniqueKeyBaseTable, nodeTable.LinkProperty.Alias, pos); } }
public bool DetectLoopback() // Call after the node has been added into the tree { DbmsForeignKey parentForeignKey; for (DbmsRelationTree baseTable = this.ForeignKeyBaseTable; ; baseTable = parentForeignKey.ForeignKeyBaseTable) { parentForeignKey = baseTable.ParentForeignKey; if (parentForeignKey == null) { break; } if (_ConstraintName.Equals(parentForeignKey.ConstraintName, System.StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }
internal JoinedTable(DbmsRelationTree rootTable) { _RootTable = rootTable; _ColumnAliases = new List <ColumnAlias>(); TraverseRelationTree(rootTable, string.Empty, 0); }