internal override void WriteSql(StringBuilder sqlText)
 {
     if (_variable != null)
     {
         _variable.WriteSql(sqlText);
         sqlText.Append(".");
     }
     sqlText.Append(SqlBaseGenerator.QuoteIdentifier(_property.Name));
     base.WriteSql(sqlText);
 }
Exemplo n.º 2
0
        internal override void WriteSql(StringBuilder sqlText)
        {
            _column.WriteSql(sqlText);

            ColumnReferenceExpression column = _column as ColumnReferenceExpression;

            if (column == null || column.Name != _columnName)
            {
                sqlText.Append(" AS ");
                sqlText.Append(SqlBaseGenerator.QuoteIdentifier(_columnName));
            }

            base.WriteSql(sqlText);
        }
 internal override void WriteSql(StringBuilder sqlText)
 {
     sqlText.Append("SELECT ");
     if (Distinct)
     {
         sqlText.Append("DISTINCT ");
     }
     if (Projection != null)
     {
         Projection.WriteSql(sqlText);
     }
     else
     {
         if (ColumnsToProject.Count == 0)
         {
             sqlText.Append("1");                              // Could be arbitrary, let's pick 1
         }
         else
         {
             var first = true;
             foreach (var column in ColumnsToProject)
             {
                 if (!first)
                 {
                     sqlText.Append(", ");
                 }
                 else
                 {
                     first = false;
                 }
                 sqlText.Append(SqlBaseGenerator.QuoteIdentifier(column.Key.Item1));
                 sqlText.Append(".");
                 sqlText.Append(SqlBaseGenerator.QuoteIdentifier(column.Key.Item2));
                 if (column.Key.Item2 != column.Value)
                 {
                     sqlText.Append(" AS ");
                     sqlText.Append(SqlBaseGenerator.QuoteIdentifier(column.Value));
                 }
             }
         }
     }
     sqlText.Append(" FROM ");
     From.WriteSql(sqlText);
     Where?.WriteSql(sqlText);
     GroupBy?.WriteSql(sqlText);
     OrderBy?.WriteSql(sqlText);
     Skip?.WriteSql(sqlText);
     Limit?.WriteSql(sqlText);
     base.WriteSql(sqlText);
 }
Exemplo n.º 4
0
        internal void AppendReturning(DbNewInstanceExpression expression)
        {
            Append(" RETURNING ");//Don't put () around columns it will probably have unwanted effect
            bool first = true;

            foreach (var returingProperty in expression.Arguments)
            {
                if (!first)
                {
                    Append(",");
                }
                Append(SqlBaseGenerator.QuoteIdentifier((returingProperty as DbPropertyExpression).Property.Name));
                first = false;
            }
        }
        internal override void WriteSql(StringBuilder sqlText)
        {
            bool wrap = !(_from is LiteralExpression || _from is ScanExpression);

            if (wrap)
            {
                sqlText.Append("(");
            }
            _from.WriteSql(sqlText);
            if (wrap)
            {
                sqlText.Append(")");
            }
            sqlText.Append(" AS ");
            sqlText.Append(SqlBaseGenerator.QuoteIdentifier(_name));
            base.WriteSql(sqlText);
        }
        internal override void WriteSql(StringBuilder sqlText)
        {
            var from = _from as InputExpression;

            if (from != null)
            {
                var input = from;
                if (!ForceSubquery && input.Projection == null && input.Where == null && input.Distinct == false && input.OrderBy == null &&
                    input.Skip == null && input.Limit == null)
                {
                    // There is no point of writing
                    // (SELECT ? FROM <from> AS <name>) AS <name>
                    // so just write <from> AS <name>
                    // <name> is always the same for both nodes
                    // However, PostgreSQL needs a subquery in case we are in the right hand side of an Apply expression
                    if (((FromExpression)input.From).Name != Name)
                    {
                        throw new ArgumentException();
                    }
                    input.From.WriteSql(sqlText);
                }
                else
                {
                    sqlText.Append("(");
                    input.WriteSql(sqlText);
                    sqlText.Append(") AS ");
                    sqlText.Append(SqlBaseGenerator.QuoteIdentifier(Name));
                }
            }
            else
            {
                var wrap = !(_from is LiteralExpression || _from is ScanExpression || _from is FunctionExpression);
                if (wrap)
                {
                    sqlText.Append("(");
                }
                _from.WriteSql(sqlText);
                if (wrap)
                {
                    sqlText.Append(")");
                }
                sqlText.Append(" AS ");
                sqlText.Append(SqlBaseGenerator.QuoteIdentifier(Name));
            }
            base.WriteSql(sqlText);
        }
 internal override void WriteSql(StringBuilder sqlText)
 {
     if (_variableSubstitution.ContainsKey(_name))
     {
         sqlText.Append(SqlBaseGenerator.QuoteIdentifier(_variableSubstitution[_name]));
     }
     else
     {
         // TODO: come up with a better solution
         // need some way of removing extra levels of dots
         if (_name.Contains("."))
         {
             sqlText.Append(SqlBaseGenerator.QuoteIdentifier(_name.Substring(_name.LastIndexOf('.') + 1)));
         }
         else
         {
             sqlText.Append(SqlBaseGenerator.QuoteIdentifier(_name));
         }
     }
     base.WriteSql(sqlText);
 }
        internal override IEnumerable <ColumnExpression> GetProjectedColumns()
        {
            Dictionary <string, string> emptySubstitution = new Dictionary <string, string>();

            if (_from is ScanExpression)
            {
                ScanExpression scan = (ScanExpression)_from;
                foreach (var property in scan.Target.ElementType.Members.OfType <EdmProperty>())
                {
                    yield return(new ColumnExpression(new PropertyExpression(new VariableReferenceExpression(Name, emptySubstitution), property), property.Name, property.TypeUsage));
                }
            }
            else
            {
                foreach (var column in _from.GetProjectedColumns())
                {
                    string columnRef = string.Format("{0}.{1}", SqlBaseGenerator.QuoteIdentifier(Name), column.Name);
                    yield return(new ColumnExpression(new LiteralExpression(columnRef), column.Name, column.ColumnType));
                }
            }
        }
 internal override void WriteSql(StringBuilder sqlText)
 {
     _column.WriteSql(sqlText);
     sqlText.Append(" AS " + SqlBaseGenerator.QuoteIdentifier(_columnName));
     base.WriteSql(sqlText);
 }
Exemplo n.º 10
0
 internal override void WriteSql(StringBuilder sqlText)
 {
     sqlText.Append(SqlBaseGenerator.QuoteIdentifier(_property.Name));
     base.WriteSql(sqlText);
 }