Exemple #1
0
 public subquery(selectstatement select, string consumeralias)
     : base(new selectstatements() { })
 {
     if (select is unionstatement)
     {
         var union = select as unionstatement;
         base.All     = union.All;
         base.Selects = union.Selects;
         base.OrderBy = union.OrderBy;
     }
     else
     {
         var sel1 = new selectstatement()
         {
             Top           = select.Top,
             Distinct      = select.Distinct,
             Fields        = select.Fields,
             Tables        = select.Tables,
             Joins         = select.Joins,
             Where         = select.Where,
             GroupBy       = select.GroupBy,
             Having        = select.Having,
             OrderBy       = select.OrderBy,
             ConsumerAlias = consumeralias
         };
         base.Selects.Add(sel1);
     }
 }
Exemple #2
0
        public override ITable[] DependentUpon()
        {
            List <ITable> result = new List <ITable>();
            ITable        tab;
            /* a view might depend on various tables and other views, too */
            selectstatement  stmt = ConstituentSelectStatement;
            selectstatements sts;

            /* [dlatikay 20160913] pass-through views might have their dependencies specified in attributes */
            object[] da = Attribute.GetCustomAttributes(this.GetType(), typeof(DependencyAttribute), false);
            for (int i = 0; i < da.Length; ++i)
            {
                var attr = da[i] as DependencyAttribute;
                tab = TableobjectFromName(attr.Relation.Name);
                if (!result.Contains(tab))
                {
                    result.Add(tab);
                }
            }
            /* decompose possible unions */
            var unionStatement = stmt as unionstatement;

            if (unionStatement != null)
            {
                sts = unionStatement.Selects; /* a union might contain multiple selects (at least two) */
            }
            else
            {
                sts = new selectstatements()
                {
                    stmt
                }
            };                                         /* a singular statement */
            /* iterate all of them */
            foreach (selectstatement st in sts)
            {
                /* 1. look in the tables */
                if (st.Tables != null)
                {
                    foreach (tableexpression tex in st.Tables)
                    {
                        tab = TableobjectFromName(tex.Tablename);
                        if (!result.Contains(tab))
                        {
                            result.Add(tab);
                        }
                    }
                }
                /* 2. look in the joins */
                if (st.Joins != null)
                {
                    foreach (joinstatement join in st.Joins)
                    {
                        tab = TableobjectFromName(join.Tablename);
                        if (!result.Contains(tab))
                        {
                            result.Add(tab);
                        }
                    }
                }
                /* 3. look in the subqueries that might reside in the where clause */
                /* -!- not yet cared to implement */

                /* 4. look in the subqueries that might reside in the field list */
                /* -!- not yet cared to implement */
            }
            /* deliver */
            return(result.ToArray());
        }

        ITable TableobjectFromName(string name)
        {
            try
            {
                return((ITable)Assembly.GetAssembly(this.GetType()).CreateInstance("dal.schema." + name));
            }
            catch (Exception)
            {
                throw new ArgumentOutOfRangeException("name", String.Format("Failed to resolve the name \"{0}\" in the \"dal.schema\" namespace.", name));
            }
        }
    }
Exemple #3
0
 public subquery(selectstatement sel) : this(sel, null)
 {
 }