Esempio n. 1
0
 protected sqlcompiler(Iddl _db, Istatement _stmt)
 {
     if (_db != null)
     {
         db = _db;
     }
     if (_stmt != null)
     {
         stmt      = _stmt;
         local_sql = stmt.ToString();
     }
     local_parameters  = new List <DbParameter>();
     rowsource_aliases = new Dictionary <string, Irowsource>();
     /* [rzamponi 20100112] FxCop CA1805:DoNotInitializeUnnecessarily */
     //_indent = 0;
 }
Esempio n. 2
0
        public virtual bool Compile(Isqlcompiler _parent)
        {
            parent = _parent;

            /* 1. special case with toplevel select statement: if there is an ordering defined in the field list,
             * then we append those ordering hints to the order by clause even if there is none */
            if (stmt is selectstatement && (!(stmt is unionstatement)))
            {
                selectstatement s = stmt as selectstatement;
                foreach (selectfield f in s.Fields)
                {
                    if (f.definesOrder)
                    {
                        if (parent != null && parent.TypeOfCommand.Equals(typeof(insertstatement)) == false)
                        {
                            throw new ArgumentException("subquery may not define a sort order");
                        }
                        if (s.OrderBy == null)
                        {
                            s.OrderBy = new orderbystatement();
                        }
                        s.OrderBy.fields.Add(f);
                    }
                }
#if DEBUG
                if (s.Where != null && s.Where.expressions.Count <= 0)
                {
                    throw new ArgumentException("cannot have empty 'where' clause");
                }
                if (s.Having != null && s.Having.expressions.Count <= 0)
                {
                    throw new ArgumentException("cannot have empty 'having' clause");
                }
                if (s.GroupBy != null && s.GroupBy.fields.Count <= 0)
                {
                    throw new ArgumentException("cannot have empty 'group by' clause");
                }
                if (s.OrderBy != null && s.OrderBy.fields.Count <= 0)
                {
                    throw new ArgumentException("cannot have empty 'order by' clause");
                }
#endif
            }
            /* some tasks are only performed during debug mode */
#if DEBUG
            /* 1. debug task: propagation of toplevel statements to other manifold members required? */
            if (_parent == null)
            {
                string sproc;
                if (type_of_procedure == null)
                {
                    sproc = stmt.GetType().Name;
                }
                else
                {
                    sproc = type_of_procedure.Name;
                }
                Tracing.InfoDAL("{0} Compiled \"{1}\", a {2} command for {3}", DateTime.Now.Ticks.ToString().PadLeft(20, '0'), sproc, stmt.ToString(), db.GetProvider.ToString());
                //Tracing.VerboseDAL("at {0}", Environment.StackTrace);
                PropagateStatementCompilation(stmt);
            }
            /* 2. debug task: identify missing or inconsistent fields because some providers don't tell line numbers of wrong field names */
            /* -!- */
#endif
            return(true);
        }