Exemplo n.º 1
0
 public GroupConcat(bool distinct, string tableName, string columnName, string separator, OrderByList orderBy)
 {
     this.Distinct = distinct;
     this.Value = new ValueWrapper(tableName, columnName);
     this.Separator = separator;
     this.OrderBy = orderBy;
 }
Exemplo n.º 2
0
 public GroupConcat(bool distinct, ValueWrapper value, string separator, OrderByList orderBy)
 {
     this.Distinct = distinct;
     this.Value = value;
     this.Separator = separator;
     this.OrderBy = orderBy;
 }
Exemplo n.º 3
0
        public void OrderByDESCSimple2()
        {
            OrderByList o = new OrderByList(global::SqlBuilder.Format.MsSQL);

            o.Descending("a", "b", "c");
            string result = o.GetSql();
            string sql    = "[a] DESC, [b] DESC, [c] DESC";

            Assert.AreEqual(sql, result);
        }
Exemplo n.º 4
0
        public void OrderByASCSimple1()
        {
            OrderByList o = new OrderByList(global::SqlBuilder.Format.MsSQL);

            o.Ascending("a");
            string result = o.GetSql();
            string sql    = "[a] ASC";

            Assert.AreEqual(sql, result);
        }
Exemplo n.º 5
0
 public Select(IFormatter parameters, string tableAlias = "")
 {
     Query      = SqlQuery.Select;
     Formatter  = parameters;
     TableAlias = tableAlias;
     Columns    = new ColumnsListAggregation(Formatter);
     Join       = new JoinList(Formatter);
     Where      = new WhereList(Formatter);
     OrderBy    = new OrderByList(Formatter);
     GroupBy    = new GroupByList(Formatter, Columns);
 }
Exemplo n.º 6
0
        public void OrderByASCAndDESC2()
        {
            OrderByList o = new OrderByList(global::SqlBuilder.Format.MsSQL);

            o.Ascending("a", "b", "c");
            o.Descending("d", "e", "f");
            string result = o.GetSql();
            string sql    = "[a] ASC, [b] ASC, [c] ASC, [d] DESC, [e] DESC, [f] DESC";

            Assert.AreEqual(sql, result);
        }
        public void OrderBy(string tableName, string fieldName, bool desc = false)
        {
            var order = Adapter.Field(tableName, fieldName);

            if (desc)
            {
                order += " DESC";
            }

            OrderByList.Add(order);
        }
Exemplo n.º 8
0
        public void OrderByRaw2()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(SqlBuilder.DefaultFormatter);

            o.Raw("[c] ASC").Raw("[d] DESC");
            string result = o.GetSql("t");
            string sql    = "[c] ASC, [d] DESC";

            Assert.AreEqual(sql, result);
        }
Exemplo n.º 9
0
        public void OrderByASCSimple1()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(SqlBuilder.DefaultFormatter);

            o.Ascending("a");
            string result = o.GetSql();
            string sql    = "[a] ASC";

            Assert.AreEqual(sql, result);
        }
Exemplo n.º 10
0
        public void OrderByDESCSimple2()
        {
            NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter);

            o.Descending("a", "b", "c");
            string result = o.GetSql();
            string sql    = "[a] DESC, [b] DESC, [c] DESC";

            Assert.Equal(sql, result);
        }
Exemplo n.º 11
0
 public Select(Format parameters, string tableName, string tableAlias = "")
 {
     this.Query      = Enums.SqlQuery.Select;
     this.Format     = parameters;
     this.TableName  = tableName;
     this.TableAlias = tableAlias;
     this.Columns    = new ColumnsListAggregation(this.Format);
     this.Join       = new JoinList(this.Format);
     this.Where      = new WhereList(this.Format);
     this.OrderBy    = new OrderByList(this.Format);
     this.GroupBy    = new GroupByList(this.Format, this.Columns);
 }
Exemplo n.º 12
0
        public void OrderByRaw2()
        {
            NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter);

            o.Raw("[c] ASC").Raw("[d] DESC");
            string result = o.GetSql("t");
            string sql    = "[c] ASC, [d] DESC";

            Assert.Equal(sql, result);
        }
Exemplo n.º 13
0
        public void OrderByDESCSimple2()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(SqlBuilder.DefaultFormatter);

            o.Descending("a", "b", "c");
            string result = o.GetSql();
            string sql    = "[a] DESC, [b] DESC, [c] DESC";

            Assert.AreEqual(sql, result);
        }
Exemplo n.º 14
0
        public void OrderByASCAndDESC2()
        {
            NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter);

            o.Ascending("a", "b", "c");
            o.Descending("d", "e", "f");
            string result = o.GetSql();
            string sql    = "[a] ASC, [b] ASC, [c] ASC, [d] DESC, [e] DESC, [f] DESC";

            Assert.Equal(sql, result);
        }
Exemplo n.º 15
0
        public void OrderByASCAndDESC2()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(SqlBuilder.DefaultFormatter);

            o.Ascending("a", "b", "c");
            o.Descending("d", "e", "f");
            string result = o.GetSql();
            string sql    = "[a] ASC, [b] ASC, [c] ASC, [d] DESC, [e] DESC, [f] DESC";

            Assert.AreEqual(sql, result);
        }
Exemplo n.º 16
0
        public void OrderByASCAndDESCAlias()
        {
            OrderByList o = new OrderByList(global::SqlBuilder.Format.MsSQL);

            o.Ascending("a");
            o.Descending("b");
            o.Ascending("c");
            o.Descending("d");
            string result = o.GetSql("t");
            string sql    = "[t].[a] ASC, [t].[b] DESC, [t].[c] ASC, [t].[d] DESC";

            Assert.AreEqual(sql, result);
        }
Exemplo n.º 17
0
        public void OrderByASCAndDESCAlias()
        {
            NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter);

            o.Ascending("a");
            o.Descending("b");
            o.Ascending("c");
            o.Descending("d");
            string result = o.GetSql("t");
            string sql    = "[t].[a] ASC, [t].[b] DESC, [t].[c] ASC, [t].[d] DESC";

            Assert.Equal(sql, result);
        }
Exemplo n.º 18
0
        public void OrderByASCAndDESCAlias()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(SqlBuilder.DefaultFormatter);

            o.Ascending("a");
            o.Descending("b");
            o.Ascending("c");
            o.Descending("d");
            string result = o.GetSql("t");
            string sql    = "[t].[a] ASC, [t].[b] DESC, [t].[c] ASC, [t].[d] DESC";

            Assert.AreEqual(sql, result);
        }
Exemplo n.º 19
0
        public string BuildSQL(string condition, string having, params string[] sorts)
        {
            string sqlstr = SelectClause + " " + FromClause;

            if (condition != null && condition.Trim().Length > 0)
            {
                if (WhereClause == null || WhereClause.Trim().Length <= 0)
                {
                    sqlstr += " where " + condition;
                }
                else
                {
                    sqlstr += " where ( " + condition + " ) and ( " + WhereClause + " )";
                }
            }
            else if (WhereClause != null && WhereClause.Trim().Length > 0)
            {
                sqlstr += " where " + WhereClause;
            }
            if (GroupByList != null && GroupByList.Trim().Length > 0)
            {
                sqlstr += " group by " + GroupByList;
                if (having != null && having.Trim().Length > 0)
                {                //用户指定了条件并且有分组,则用户指定条件合并到HAVING子句中
                    if (HavingClause == null || HavingClause.Trim().Length <= 0)
                    {
                        sqlstr += " having " + having;
                    }
                    else
                    {
                        sqlstr += " having ( " + having + " ) and ( " + HavingClause + " )";
                    }
                }
                else if (HavingClause != null && HavingClause.Trim().Length > 0)
                {
                    sqlstr += " having " + HavingClause;
                }
            }
            if (sorts.Length > 0)
            {
                sqlstr += " " + string.Join(",", sorts);
            }
            else if (OrderByList != null && OrderByList.Trim().Length > 0)
            {
                sqlstr += " order by " + OrderByList;
            }
            return(sqlstr);
        }
Exemplo n.º 20
0
        public void OrderByTableAlias2()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(SqlBuilder.DefaultFormatter);

            o.Raw("[a] ASC");
            o.Ascending("as1");
            o.Descending("ds2");
            o.SetTableAlias("ttt");
            o.Ascending("at1");
            o.SetTableAlias("ddd");
            o.Descending("at2");
            o.SetTableAlias();
            o.Descending("b");

            string result = o.GetSql();
            string sql    = "[a] ASC, [as1] ASC, [ds2] DESC, [ttt].[at1] ASC, [ddd].[at2] DESC, [b] DESC";

            Assert.AreEqual(sql, result);
        }
Exemplo n.º 21
0
        public void OrderByTableAlias2()
        {
            NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter = FormatterLibrary.MsSql;

            OrderByList o = new OrderByList(NKnife.Storages.SQL.Common.SuperSql.DefaultFormatter);

            o.Raw("[a] ASC");
            o.Ascending("as1");
            o.Descending("ds2");
            o.SetTableAlias("ttt");
            o.Ascending("at1");
            o.SetTableAlias("ddd");
            o.Descending("at2");
            o.SetTableAlias();
            o.Descending("b");

            string result = o.GetSql();
            string sql    = "[a] ASC, [as1] ASC, [ds2] DESC, [ttt].[at1] ASC, [ddd].[at2] DESC, [b] DESC";

            Assert.Equal(sql, result);
        }
Exemplo n.º 22
0
 public GroupConcat(ValueWrapper value, OrderByList orderBy)
 {
     this.Value = value;
     this.OrderBy = orderBy;
 }
Exemplo n.º 23
0
 public GroupConcat(ValueWrapper value, string separator, OrderByList orderBy)
 {
     this.Value = value;
     this.Separator = separator;
     this.OrderBy = orderBy;
 }
Exemplo n.º 24
0
 public static GroupConcat GroupConcat(ValueWrapper value, OrderByList orderBy)
 {
     return new GroupConcat(value, orderBy);
 }
Exemplo n.º 25
0
 public static GroupConcat GroupConcat(ValueWrapper value, string separator, OrderByList orderBy)
 {
     return new GroupConcat(value, separator, orderBy);
 }
Exemplo n.º 26
0
 public static GroupConcat GroupConcat(string tableName, string columnName, OrderByList orderBy)
 {
     return new GroupConcat(tableName, columnName, orderBy);
 }
Exemplo n.º 27
0
 public static GroupConcat GroupConcat(bool distinct, ValueWrapper value, OrderByList orderBy)
 {
     return new GroupConcat(distinct, value, orderBy);
 }
Exemplo n.º 28
0
 public static GroupConcat GroupConcat(bool distinct, string tableName, string columnName, OrderByList orderBy)
 {
     return new GroupConcat(distinct, tableName, columnName, orderBy);
 }
Exemplo n.º 29
0
 public Query OrderBy(string ColumnName, SortDirection SortDirection, bool ColumnNameIsLiteral)
 {
     if (_ListOrderBy == null) _ListOrderBy = new OrderByList();
     _ListOrderBy.Add(new OrderBy(ColumnName, SortDirection, ColumnNameIsLiteral));
     return this;
 }
Exemplo n.º 30
0
 public GroupConcat(bool distinct, ValueWrapper value, OrderByList orderBy)
 {
     this.Distinct = distinct;
     this.Value = value;
     this.OrderBy = orderBy;
 }
Exemplo n.º 31
0
        public override void WriteToStream(IndentStream stream)
        {
            stream.Write("SELECT");

            if (TopCount != null)
            {
                stream.Write(" ");
                TopCount.WriteToStream(stream);
            }

            stream.Write(" ");
            foreach (var column in Columns.Select((value, idx) => new { value, idx }))
            {
                if (column.idx != 0)
                {
                    stream.Write(", ");
                }

                column.value.WriteToStream(stream);
            }

            if (IntoTable != null)
            {
                stream.WriteLine();
                stream.Write("INTO ");
                IntoTable.WriteToStream(stream);
            }

            if (FromSourceList.Count > 0)
            {
                stream.WriteLine();
                stream.Write("FROM ");
                stream.Indent++;
                for (int i = 0; i < FromSourceList.Count; i++)
                {
                    if (i != 0)
                    {
                        stream.WriteLine(", ");
                    }

                    var fromSource = FromSourceList[i];
                    fromSource.WriteToStream(stream);
                }

                stream.Indent--;
            }

            if (ForXmlExpr != null)
            {
                stream.WriteLine();
                ForXmlExpr.WriteToStream(stream);
            }

            if (PivotExpr != null)
            {
                stream.WriteLine();
                PivotExpr.WriteToStream(stream);
            }

            if (WhereExpr != null)
            {
                stream.WriteLine();
                stream.Write("WHERE ");
                WhereExpr.WriteToStream(stream);
            }

            if (GroupByList.Count > 0)
            {
                stream.WriteLine();
                stream.Write("GROUP BY ");
                GroupByList.WriteToStreamWithComma(stream);
            }

            if (Having != null)
            {
                stream.WriteLine();
                Having.WriteToStream(stream);
            }

            if (OrderByList.Count > 0)
            {
                stream.WriteLine();
                stream.Write("ORDER BY ");
                OrderByList.WriteToStreamWithComma(stream);
            }

            if (OptionExpr != null)
            {
                stream.WriteLine();
                OptionExpr.WriteToStream(stream);
            }

            if (UnionSelectList != null && UnionSelectList.Count > 0)
            {
                stream.WriteLine();
                UnionSelectList.WriteToStream(stream);
            }

            if (IsSemicolon)
            {
                stream.Write(" ;");
            }
        }
Exemplo n.º 32
0
 public Query OrderBy(string columnName, SortDirection sortDirection)
 {
     if (_ListOrderBy == null) _ListOrderBy = new OrderByList();
     _ListOrderBy.Add(new OrderBy(columnName, sortDirection));
     return this;
 }
Exemplo n.º 33
0
 public Query OrderBy(string TableName, string ColumnName, SortDirection SortDirection)
 {
     if (_ListOrderBy == null) _ListOrderBy = new OrderByList();
     _ListOrderBy.Add(new OrderBy(TableName, ColumnName, SortDirection));
     return this;
 }
Exemplo n.º 34
0
 internal OrderByList ProcessOrderBy()
 {
     var list = new OrderByList();
     if (!string.IsNullOrWhiteSpace(orderByClause))
     {
         var orderByItems = orderByClause.Split(new [] { "," }, StringSplitOptions.RemoveEmptyEntries);
         foreach (var item in orderByItems)
         {
             var parts = item.Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries);
             if (parts.Length == 1)
                 list.Add(new OrderByNode(parts[0], Direction.Asc));
             if (parts.Length == 2)
             {
                 var direction = string.Equals(parts[1], "desc", StringComparison.OrdinalIgnoreCase) ? Direction.Desc : Direction.Asc;
                 list.Add(new OrderByNode(parts[0], direction));
             }
         }
     }
     return list;
 }
Exemplo n.º 35
0
 public GroupConcat(string tableName, string columnName, OrderByList orderBy)
 {
     this.Value = new ValueWrapper(tableName, columnName);
     this.OrderBy = orderBy;
 }
Exemplo n.º 36
0
 private Query OrderBy(OrderBy OrderBy)
 {
     if (_ListOrderBy == null) _ListOrderBy = new OrderByList();
     _ListOrderBy.Add(OrderBy);
     return this;
 }