Ejemplo n.º 1
0
        /// <summary>
        /// Produces insert from subquery
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public Query AsInsert(IEnumerable <string> columns, Query query)
        {
            Method = "insert";

            ClearComponent("insert").AddComponent("insert", new InsertQueryClause
            {
                Columns = columns.ToList(),
                Query   = query.Clone(),
            });

            return(this);
        }
Ejemplo n.º 2
0
 public override AbstractClause Clone()
 {
     return(new InQueryCondition
     {
         Engine = Engine,
         Column = Column,
         Query = Query.Clone(),
         IsOr = IsOr,
         IsNot = IsNot,
         Component = Component,
     });
 }
Ejemplo n.º 3
0
        public Query Select(Query query, string alias)
        {
            Method = "select";

            query = query.Clone();

            AddComponent("select", new QueryColumn
            {
                Query = query.As(alias),
            });

            return(this);
        }
Ejemplo n.º 4
0
        public Q From(Query query, string alias = null)
        {
            query = query.Clone();
            query.SetParent((Q)this);

            if (alias != null)
            {
                query.As(alias);
            }
            ;

            return(AddOrReplaceComponent("from", new QueryFromClause
            {
                Query = query
            }));
        }
        public Q WhereExists(Query query)
        {
            if (!query.HasComponent("from"))
            {
                throw new ArgumentException("'FromClause' cannot be empty if used inside a 'WhereExists' condition");
            }

            // remove unneeded components
            query = query.Clone().ClearComponent("select")
                    .SelectRaw("1");

            return(AddComponent("where", new ExistsCondition
            {
                Query = query,
                IsNot = GetNot(),
                IsOr = GetOr(),
            }));
        }
Ejemplo n.º 6
0
        public Query HavingExists(Query query)
        {
            if (!query.HasComponent("from"))
            {
                throw new ArgumentException("'FromClause' cannot be empty if used inside a 'HavingExists' condition");
            }

            // simplify the query as much as possible
            query = query.Clone().ClearComponent("select")
                    .SelectRaw("1")
                    .Limit(1);

            return(AddComponent("having", new ExistsCondition
            {
                Query = query,
                IsNot = GetNot(),
                IsOr = GetOr(),
            }));
        }