Beispiel #1
0
        public virtual void Render(SqlWriter writer)
        {
            if(Precedence > Left.Precedence)
            {
                writer.Append("(");
                writer.Append(Left);
                writer.Append(")");
            }
            else
            {
                writer.Append(Left);
            }

            writer.Append(Operator);

            if (Precedence > Right.Precedence)
            {
                writer.Append("(");
                writer.Append(Right);
                writer.Append(")");
            }
            else
            {
                writer.Append(Right);
            }
        }
Beispiel #2
0
        public void Render(SqlWriter writer)
        {
            if (_joins.Count == 0)
                return;

            foreach (var join in _joins.Values)
            {
                writer.AppendLine();
                join.Render(writer);
            }
        }
Beispiel #3
0
        public void Render(SqlWriter writer)
        {
            for (var i = 0; i < _entityMap.Properties.Length; i++)
            {
                if (i > 0)
                    writer.Append(",");

                writer.Append(_alias + _entityMap.Properties[i].Column);
            }

            RenderRowNumber(writer);
        }
Beispiel #4
0
 public void Render(SqlWriter writer)
 {
     var type = PropertyMap.Property.PropertyType;
     if (type == typeof(bool) && !(Parent is Relational))
     {
         writer.Append(Alias + PropertyMap.Column, SqlStrings.Equal, "1");
     }
     else
     {
         writer.Append(Alias + PropertyMap.Column);
     }
 }
Beispiel #5
0
        private void RenderRowNumber(SqlWriter writer)
        {
            if (!_showRowNumber)
                return;

            writer.Append(",", SqlStrings.ROW_NUMBER + "()", SqlStrings.Over, "(");

            if (_orderBy == null)
                writer.Append(SqlStrings.OrderBy, _alias + _entityMap.Key.Column, SqlStrings.Ascending);
            else
                writer.Append(_orderBy);

            writer.Append(")", SqlStrings.As, (BracketedName)SqlStrings.ROW_NUMBER);
        }
Beispiel #6
0
 public virtual void Render(SqlWriter writer)
 {
     writer.Append(Operator);
     if(Precedence > Expr.Precedence)
     {
         writer.Append("(");
         writer.Append(Expr);
         writer.Append(")");
     }
     else
     {
         writer.Append(Expr);
     }
 }
Beispiel #7
0
        public void Render(SqlWriter writer)
        {
            for (var i = 0; i < _items.Count; i++)
            {
                var item = _items[i];

                if(i == 0)
                    writer.Append(SqlStrings.OrderBy);
                else
                    writer.Append(",");

                writer.Append(item.Alias + item.Property.Column,
                              item.Ascending ? SqlStrings.Ascending : SqlStrings.Descending);
            }
        }
Beispiel #8
0
        public QueryContext(IEnumerable<EntityMap> entityMaps, string connectionString)
        {
            if (entityMaps == null)
                throw new ArgumentNullException("entityMaps");

            if (connectionString == null)
                throw new ArgumentNullException("connectionString");

            Values = new Dictionary<string, IValueProvider>();
            EntityMaps = entityMaps;
            ConnectionString = connectionString;

            _writer = new SqlWriter();
            _alias = 0;
            _param = 0;
        }
Beispiel #9
0
        public void Render(SqlWriter writer)
        {
            var value = (string)Context.Values[Parameter.Name].Value;

            if (PartialPrefix && !value.EndsWith("%"))
                value = value + '%';

            if (PartialPostfix && !value.StartsWith("%"))
                value = '%' + value;

            Context.Values[Parameter.Name].Value = value;

            PropertyAccess.Render(writer);
            writer.Append(SqlStrings.Like);
            Parameter.Render(writer);
        }
Beispiel #10
0
        public void CanWriteFormattedText()
        {
            string expected = "<ul>\n\t<li>\n\t\t1 + 2 = 3\n\t</li>\n</ul>";

            var writer = new SqlWriter();
            writer.AppendLine("<ul>");
                writer.Indent();
                    writer.AppendLine("<li>");
                        writer.Indent();
                            writer.AppendLine("1", "+", "2", "=", "3");
                        writer.Unindent();
                    writer.AppendLine("</li>");
                writer.Unindent();
            writer.AppendLine("</ul>");

            var result = writer.GetResult();
            Assert.AreEqual(expected, result);
        }
Beispiel #11
0
        public void CanRenderSelect()
        {
            var writer = new SqlWriter();
            var convention = new DefaultConvention();
            var builder = new EntityMapBuilder<Student>(convention);

            var map = ((EntityMapBuilder<Student>) builder
                                                       .Key(_ => _.ID, "Student_id")).Build();

            var selectEntity = new Select(map, "t0");

            selectEntity.Render(writer);
            var result = writer.GetResult();

            AssertHelper.AreEqualWithNoSpaces(
            @"SELECT [t0].[Student_id], [t0].[Name]
            FROM [dbo].[Student] AS [t0] (NOLOCK)", result);
        }
Beispiel #12
0
        public void Render(SqlWriter writer)
        {
            writer.AppendLine(SqlStrings.Select);

            writer.Indent();

            writer.AppendLine(Top);

            writer.AppendLine(Columns);

            writer.Unindent();

            writer.AppendLine(From);

            writer.AppendLine(JoinGroup);

            writer.AppendLine(Where);

            writer.AppendLine(OrderBy);
        }
Beispiel #13
0
        public void Render(SqlWriter writer)
        {
            writer.AppendLine(SqlStrings.Select);

            writer.Indent();

            writer.AppendLine(Top);

            writer.AppendLine("*");

            writer.Unindent();

            writer.AppendLine(SqlStrings.From, "(");

            writer.Indent();

            writer.AppendLine(_innerSelect);

            writer.Unindent();

            writer.AppendLine(")", SqlStrings.As, _alias);

            writer.AppendLine(SqlStrings.Where, (BracketedName)SqlStrings.ROW_NUMBER, ">", _skip.ParamName);
        }
Beispiel #14
0
 public void Render(SqlWriter writer)
 {
     writer.AppendLine(SqlStrings.From, _select.EntityMap.Schema + _select.EntityMap.Table, SqlStrings.As, _select.Alias, SqlStrings.NoLock);
 }
Beispiel #15
0
 public void Render(SqlWriter writer)
 {
     writer.Append(SqlStrings.Null);
 }
Beispiel #16
0
 public void Render(SqlWriter writer)
 {
     writer.Append(Join, ReferenceMap.To.Table, SqlStrings.As, ToAlias, SqlStrings.NoLock);
     writer.Indent();
     writer.AppendLine(SqlStrings.On, FromAlias + ReferenceMap.Column, "=", ToAlias + ReferenceMap.To.Key.Column);
     writer.Unindent();
 }
Beispiel #17
0
 public void Render(SqlWriter writer)
 {
     writer.Append(Name);
 }
Beispiel #18
0
 public void Render(SqlWriter writer)
 {
     writer.AppendLine(SqlStrings.Where);
     expr.Render(writer);
 }
Beispiel #19
0
 public void Render(SqlWriter writer)
 {
     writer.Append(SqlStrings.Top + '(' + _valueProvider.ParamName + ')');
 }