コード例 #1
0
        string GetClausesForJoinQuery(string select, bool orderby)
        {
            var leftTableAlias = tableAliasGenerator.GenerateTableAlias(ViewOrTableName);
            var sb             = new StringBuilder();

            sb.AppendFormat(select, leftTableAlias)
            .AppendLine($" FROM (SELECT * {GetClauses(false)}) {leftTableAlias}");

            foreach (var join in Joins)
            {
                var right           = join.RightQuery;
                var rightQuery      = right.SelectQuery(false);
                var rightTableAlias = tableAliasGenerator.GenerateTableAlias(right.ViewOrTableName);

                var joinClauseString = JoinClauseString(leftTableAlias, rightTableAlias, join.JoinClauses);
                var joinTypeString   = JoinTypeString(join.JoinType);

                sb.AppendLine($"{joinTypeString} ({rightQuery}) {rightTableAlias} {joinClauseString}");
            }

            if (orderby)
            {
                var orderByClause = GetOrderByClause(leftTableAlias);
                if (!string.IsNullOrEmpty(orderByClause))
                {
                    sb.AppendLine(orderByClause);
                }
            }
            return(sb.ToString().Trim());
        }
コード例 #2
0
ファイル: QueryBuilder.cs プロジェクト: renesugar/Nevermore
        public IJoinSourceQueryBuilder <TRecord> Join(IAliasedSelectSource source, JoinType joinType, CommandParameterValues parameterValues, Parameters parameters, ParameterDefaults parameterDefaults)
        {
            var clonedSelectBuilder = selectBuilder.Clone();

            clonedSelectBuilder.IgnoreDefaultOrderBy();
            var subquery = new SubquerySource(clonedSelectBuilder.GenerateSelect(), tableAliasGenerator.GenerateTableAlias());

            return(new JoinSourceQueryBuilder <TRecord>(subquery,
                                                        joinType,
                                                        source,
                                                        transaction,
                                                        tableAliasGenerator,
                                                        uniqueParameterNameGenerator,
                                                        new CommandParameterValues(ParameterValues, parameterValues),
                                                        new Parameters(Parameters, parameters),
                                                        new ParameterDefaults(ParameterDefaults, parameterDefaults)));
        }
コード例 #3
0
ファイル: SelectBuilder.cs プロジェクト: onenorth/Nevermore
        string GetAlias()
        {
            if (string.IsNullOrEmpty(customAlias))
            {
                customAlias = tableAliasGenerator.GenerateTableAlias();
            }

            return(customAlias);
        }
コード例 #4
0
        public QueryBuilderFixture()
        {
            transaction = Substitute.For <IRelationalTransaction>();

            var tableNumber = 0;

            tableAliasGenerator.GenerateTableAlias(Arg.Any <string>()).Returns(delegate
            {
                tableNumber++;
                return("t" + tableNumber);
            });
        }
コード例 #5
0
        public IJoinSourceQueryBuilder <TRecord> Join(IAliasedSelectSource source, JoinType joinType, CommandParameterValues parameterValues, Parameters parameters, ParameterDefaults parameterDefaults)
        {
            var subquery = new SubquerySource(selectBuilder.GenerateSelectWithoutDefaultOrderBy(), tableAliasGenerator.GenerateTableAlias());

            return(new JoinSourceQueryBuilder <TRecord>(subquery,
                                                        joinType,
                                                        source,
                                                        readQueryExecutor,
                                                        tableAliasGenerator,
                                                        uniqueParameterNameGenerator,
                                                        new CommandParameterValues(ParameterValues, parameterValues),
                                                        new Parameters(Parameters, parameters),
                                                        new ParameterDefaults(ParameterDefaults, parameterDefaults)));
        }