public override SqlStatement GetInsertIds(SqlStatement table, IList <SqlStatement> autoPKColumn, IList <SqlStatement> inputPKColumns, IList <SqlStatement> inputPKValues, IList <SqlStatement> outputColumns, IList <SqlStatement> outputParameters, IList <SqlStatement> outputExpressions)
 {
     // no parameters? no need to get them back
     if (outputParameters.Count == 0)
     {
         return("");
     }
     // otherwise we keep track of the new values
     return(SqlStatement.Format("SELECT {0} INTO {1} FROM DUAL",
                                SqlStatement.Join(", ", (from outputExpression in outputExpressions select outputExpression.Replace(".NextVal", ".CurrVal", true)).ToArray()),
                                SqlStatement.Join(", ", outputParameters.ToArray())));
 }
Exemplo n.º 2
0
        protected virtual SqlStatement BuildSelect(Expression select, QueryContext queryContext)
        {
            var sqlProvider   = queryContext.DataContext.Vendor.SqlProvider;
            var selectClauses = new List <SqlStatement>();

            foreach (var selectExpression in select.GetOperands())
            {
                var expressionString = BuildExpression(selectExpression, queryContext);
                if (selectExpression is SelectExpression)
                {
                    selectClauses.Add(sqlProvider.GetParenthesis(expressionString));
                }
                else
                {
                    selectClauses.Add(expressionString);
                }
            }
            SelectExpression selectExp = select as SelectExpression;

            if (selectExp != null)
            {
                if (selectExp.Group.Count == 1 && selectExp.Group[0].GroupedExpression == selectExp.Group[0].KeyExpression)
                {
                    // this is a select DISTINCT expression
                    // TODO: better handle selected columns on DISTINCT: I suspect this will not work in some cases
                    if (selectClauses.Count == 0)
                    {
                        selectClauses.Add(sqlProvider.GetColumns());
                    }
                    return(sqlProvider.GetSelectDistinctClause(selectClauses.ToArray()));
                }
                var noSelect = selectExp.Tables.Count == 0;
                if (noSelect)
                {
                    // maybe this is not necessary, but maybe we have to test against operand.specialtype==count
                    var countOperand = selectExp.Operands.FirstOrDefault() as SpecialExpression;
                    noSelect &= countOperand != null &&
                                countOperand.SpecialNodeType == SpecialExpressionType.Count;
                }
                if (noSelect)
                {
                    return(SqlStatement.Join(", ", selectClauses));
                }
            }
            return(sqlProvider.GetSelectClause(selectClauses.ToArray()));
        }
Exemplo n.º 3
0
        protected virtual SqlStatement BuildLimit(SelectExpression select, SqlStatement literalSelect, QueryContext queryContext)
        {
            if (select.Limit != null)
            {
                var sqlProvider  = queryContext.DataContext.Vendor.SqlProvider;
                var literalLimit = BuildExpression(select.Limit, queryContext);
                if (select.Offset != null)
                {
                    var literalOffset         = BuildExpression(select.Offset, queryContext);
                    var literalOffsetAndLimit = BuildExpression(select.OffsetAndLimit, queryContext);
                    var limitFields           = SqlStatement.Join(",", select.Operands.OfType <ColumnExpression>().Select(c => new SqlStatement(sqlProvider.GetColumn(c.Name))).ToList());

                    return(sqlProvider.GetLiteralLimit(
                               limitFields,
                               literalSelect, literalLimit,
                               literalOffset,
                               literalOffsetAndLimit));
                }
                return(sqlProvider.GetLiteralLimit(literalSelect, literalLimit));
            }
            return(literalSelect);
        }
Exemplo n.º 4
0
        public override SqlStatement GetInsertIds(SqlStatement table, IList <SqlStatement> autoPKColumn, IList <SqlStatement> inputPKColumns, IList <SqlStatement> inputPKValues, IList <SqlStatement> outputColumns, IList <SqlStatement> outputParameters, IList <SqlStatement> outputExpressions)
        {
            // No parameters? no need to get them back.

            if (outputParameters.Count == 0)
            {
                return(SqlStatement.Empty);
            }

            // Otherwise we keep track of the new values. Note that we avoid null expressions
            // that can be present in the passed list (is this a bug above us?)

            IList <SqlStatement> ids = new List <SqlStatement>();

            foreach (SqlStatement outputExpression in outputExpressions)
            {
                if (outputExpression != null)
                {
                    ids.Add(outputExpression.Replace("nextval(", "currval(", true));
                }
            }
            return(SqlStatement.Format("SELECT {0}", SqlStatement.Join(", ", ids.ToArray())));
        }
Exemplo n.º 5
0
 public SqlStatement Join(QueryContext queryContext, params SqlStatement[] clauses)
 {
     return(SqlStatement.Join(queryContext.DataContext.Vendor.SqlProvider.NewLine,
                              (from clause in clauses where clause.ToString() != string.Empty select clause).ToList()));
 }