Join() public method

Sets a join between the last added table and the one that preceeds it.
public Join ( JoinType joinType, SqlExpression onExpression ) : void
joinType JoinType The type of join to apply to the two tables.
onExpression SqlExpression The condition for the two tables to join.
return void
示例#1
0
        private void SetFromTableInClause(FromClause clause, IFromSourceNode source, JoinNode join)
        {
            AddSourceToClause(clause, source);

            if (join != null) {
                var joinType = JoinType.Inner;
                if (!String.IsNullOrEmpty(join.JoinType))
                    joinType = GetJoinType(join.JoinType);

                SqlExpression onExpression = null;
                if (join.OnExpression != null)
                    onExpression = Build(join.OnExpression);

                clause.Join(joinType, onExpression);

                SetFromTableInClause(clause, join.Source, join.NextJoin);
            }
        }
示例#2
0
            public static FromClause Build(PlSqlParser.FromClauseContext context)
            {
                if (context == null)
                    return null;

                var clause = new FromClause();

                var list = context.tableRefList();
                if (list.IsEmpty)
                    throw new ParseCanceledException("No source set in FROM clause");

                var tableRefs = list.tableRef().Select(FormTableRef);

                bool joinSeen = false;
                bool first = true;

                foreach (var tableRef in tableRefs) {
                    if (joinSeen)
                        throw new ParseCanceledException("Invalid join clause");

                    var source = tableRef.Source;
                    if (source.SubQuery != null) {
                        clause.AddSubQuery(source.Alias, source.SubQuery);
                    } else if (source.TableName != null) {
                        clause.AddTable(source.Alias, source.TableName);
                    }

                    foreach (var joinNode in tableRef.Join) {
                        var joinSource = joinNode.Source;

                        if (joinSource.SubQuery != null) {
                            clause.AddSubQuery(joinSource.Alias, joinSource.SubQuery);
                        } else if (joinSource.TableName != null) {
                            clause.AddTable(joinSource.Alias, joinSource.TableName);
                        }

                        clause.Join(joinNode.JoinType, joinNode.OnExpression);
                        joinSeen = true;
                    }

                    if (!first && !joinSeen) {
                        clause.Join(JoinType.Inner, null);
                    }

                    first = false;
                }

                return clause;
            }