예제 #1
0
 public PrintLogSearchForm(UrlHelper url) : base(url)
 {
     SetApiUrl("PrintAPI", "PrintLog", url);
     AddSortField(new SortField("PrintId", "Id", true, true));
     Selects.Add("PrintId");
     //Rest is inherited
 }
예제 #2
0
        public SqlFromQuery ToOutQuery(params SqlSelectItem[] selectItem)
        {
            if (selectItem == null || selectItem.Length <= 0)
            {
                throw new ArgumentException("must select some one");
            }

            foreach (var item in selectItem)
            {
                if (item.Target.Expression.Type == ExpressionType.SelectItemExpression)
                {
                    SqlSelectItemExpression si = (SqlSelectItemExpression)item.Target.Expression;
                    if (si.Owner == this)
                    {
                        SqlSelectItemExpression tar = new SqlSelectItemExpression(si.Expression, item.Target.AliasName);
                        tar.Owner = this;
                        Selects.Add(item.Target.AliasName, tar);
                    }
                    else
                    {
                        Selects.Add(item.Target.AliasName, item.Target);
                    }
                }
                else
                {
                    Selects.Add(item.Target.AliasName, item.Target);
                }
            }

            return(new SqlFromQuery(this));
        }
예제 #3
0
        void CheckedChange(string path, bool isChecked)
        {
            if (IsSelectMany == false)
            {
                Selects.Clear();
                if (isChecked)
                {
                    Selects.Add(path);
                }
                return;
            }

            if (isChecked)
            {
                if (Selects.Contains(path))
                {
                    return;
                }
                Selects.Add(path);
            }
            else
            {
                if (Selects.Contains(path) == false)
                {
                    return;
                }
                Selects.Remove(path);
            }
        }
 public void AdicionarResultadoAgregado(Agregadores agregador, string campo)
 {
     if (agregador == Agregadores.Count)
     {
         Selects.Add(" " + agregador + ((campo == null)
                                 ? "(*)"
                                 : "(distinct [" + campo + "])as[" + campo + "]"));
     }
     else
     {
         Selects.Add(" " + agregador + "([" + campo + "])as[" + campo + "]");
     }
 }
 private void ConstruirSelectPadrao(Dicionario dicionario)
 {
     if (dicionario == null)
     {
         Selects.Add("[" + _tabela + "].*");
     }
     else
     {
         foreach (var item in dicionario.Itens)
         {
             Selects.Add("[" + item.Nome + "]" + ConsultarAliasDoCampo(item));
         }
     }
 }
 private void ConstruirSelectPadrao(Dicionario dicionario)
 {
     if (dicionario == null)
     {
         Selects.Add(string.Concat("[", _tabela, "].*"));
     }
     else
     {
         foreach (var item in dicionario.Itens)
         {
             Selects.Add(string.Concat("[", item.Nome, "]", ConsultarAliasDoCampo(item)));
         }
     }
 }
        public void AdicionarResultadoAgregado(Agregadores agregador, string campo)
        {
            string conteudo;

            if (agregador == Agregadores.Count)
            {
                conteudo = (campo == null)
                                        ? "(*)"
                                        : string.Concat("(distinct [", campo, "])as[", campo, "]");
            }
            else
            {
                conteudo = string.Concat("([", campo, "])as[", campo, "]");
            }
            Selects.Add(string.Concat(" ", agregador, conteudo));
        }
예제 #8
0
        private void InitializeItems()
        {
            var databasePath = Properties.Settings.Default.CurrentDatabase;

            using (var databaseHandler = new TableHandler(databasePath))
            {
                var columns = databaseHandler.GetColumns(tableName);

                foreach (var column in columns)
                {
                    Selects.Add(new SelectItem
                    {
                        ColumnName = column.Name,
                        IsSelected = true
                    });
                }
            }
        }
예제 #9
0
        public string BuildSqlString(bool canUseOperators)
        {
            if (MainFrom == null)
            {
                throw new ApplicationException("From !?");
            }

            foreach (var qs in Simplifications)
            {
                if (qs.CanSimplify(this))
                {
                    return(qs.Simplify(this));
                }
            }

            var sb = new StringBuilder();

            sb.Append("SELECT ");

            var groupOperator = ResultOperators.FirstOrDefault(it => it is GroupResultOperator) as GroupResultOperator;

            if (groupOperator != null)
            {
                if (Selects.Count != 1)
                {
                    throw new FrameworkException("Select count can only be two when grouping!");
                }
                //TODO fix later... collect
                sb.AppendFormat(
                    "{0} AS \"Key\", ARRAY_AGG(\"{1}\") AS \"Values\"",
                    GetSqlExpression(groupOperator.KeySelector),
                    Selects[0].QuerySource.ItemName);
            }
            else
            {
                if (canUseOperators)
                {
                    var countOperator = ResultOperators.FirstOrDefault(it => it is CountResultOperator || it is LongCountResultOperator);
                    if (countOperator != null)
                    {
                        return(BuildCountQuery(countOperator));
                    }
                    if (ResultOperators.Any(it => it is AnyResultOperator))
                    {
                        return(BuildAnyQuery());
                    }
                    var sumOperator = ResultOperators.FirstOrDefault(it => it is SumResultOperator);
                    if (sumOperator != null)
                    {
                        if (Selects.Count > 1)
                        {
                            //TOOD hack to fix problem with select
                            Selects.Clear();
                            Selects.Add(new SelectSource {
                                Sql = GetSqlExpression(Selector), ItemType = Selector.Type
                            });
                        }
                        sb.AppendFormat("COALESCE(SUM({0}), 0)", Selects[0].Sql);
                        //TODO use actual type
                        if (Selects[0].ItemType == typeof(int) || Selects[0].ItemType == typeof(int?))
                        {
                            sb.Append("::int");
                        }
                        if (Selects[0].Name != null)
                        {
                            sb.AppendFormat(" AS \"{0}\"", Selects[0].Name);
                        }
                        sb.AppendLine();
                        sb.Append(GetFromPart());
                        sb.Append(GetWherePart());
                        return(sb.ToString());
                    }
                    var containsOperator = ResultOperators.FirstOrDefault(it => it is ContainsResultOperator);
                    if (containsOperator != null)
                    {
                        if (Selects.Count > 1)
                        {
                            //TOOD hack to fix problem with select
                            Selects.Clear();
                            Selects.Add(new SelectSource {
                                Sql = GetSqlExpression(Selector)
                            });
                        }
                    }
                }
                sb.Append(string.Join(@", ", Selects.Where(it => it.Sql != null).Select(it => it.Sql)));
            }

            sb.AppendLine();
            sb.Append(GetFromPart());
            sb.Append(GetWherePart());
            sb.Append(GetOrderPart());

            ProcessResultOperators(sb);

            return(sb.ToString());
        }
예제 #10
0
파일: Union.cs 프로젝트: jonkeda/SqlQueries
 public Union(Select select1, Select select2)
 {
     Selects.Add(select1);
     Selects.Add(select2);
 }
예제 #11
0
 public SelectQueryType <T> Select(string column)
 {
     Selects.Add(column);
     return(this);
 }
예제 #12
0
 public void Select(string field)
 {
     Selects.Add(field);
 }
예제 #13
0
 public void AdicionarResultadoPersonalizado(string resultado)
 {
     Selects.Add(resultado);
 }
예제 #14
0
 public void AdicionarResultado(string campo)
 {
     Selects.Add("[" + campo + "]");
 }
예제 #15
0
 public void AddSelectItem(SqlSelectItemExpression item)
 {
     item.Owner = this;
     Selects.Add(item.AliasName, item);
 }
예제 #16
0
 public QueryExpression Select(params object[] propertys)
 {
     Selects.Add(propertys);
     return(this);
 }