Inheritance: SqlFragment
        protected InputFragment VisitInputExpression(DbExpression e, string name, TypeUsage type)
        {
            SqlFragment f = e.Accept(this);

            Debug.Assert(f is InputFragment);

            InputFragment inputFragment = f as InputFragment;

            inputFragment.Name = name;

            if (inputFragment is TableFragment && type != null)
            {
                (inputFragment as TableFragment).Type = type;
            }

            SelectStatement select = inputFragment as SelectStatement;

            if (name != null)
            {
                if (select != null && !select.IsWrapped)
                {
                    scope.Add(name, select.From);
                }
                else
                {
                    scope.Add(name, inputFragment);
                }
            }

            return(inputFragment);
        }
Example #2
0
        void AddDefaultColumns(Scope scope)
        {
            if (columnHash == null)
            {
                columnHash = new Dictionary <string, ColumnFragment>();
            }

            List <ColumnFragment> columns = GetDefaultColumnsForFragment(From);

            foreach (ColumnFragment column in columns)
            {
                // first we need to set the input for this column
                InputFragment input = scope.FindInputFromProperties(column.PropertyFragment);
                column.TableName = input.Name;

                // then we rename the column if necessary
                if (columnHash.ContainsKey(column.ColumnName))
                {
                    column.ColumnAlias = MakeColumnNameUnique(column.ColumnName);
                    columnHash.Add(column.ColumnAlias, column);
                }
                else
                {
                    columnHash.Add(column.ColumnName, column);
                }
                Columns.Add(column);
            }
        }
        List <ColumnFragment> GetDefaultColumnsForFragment(InputFragment input)
        {
            List <ColumnFragment> columns = new List <ColumnFragment>();

            if (input is TableFragment)
            {
                return(GetDefaultColumnsForTable(input as TableFragment));
            }
            else if (input is JoinFragment || input is UnionFragment)
            {
                Debug.Assert(input.Left != null);
                columns = GetDefaultColumnsForFragment(input.Left);
                if (input is JoinFragment && input.Right != null)
                {
                    List <ColumnFragment> right = GetDefaultColumnsForFragment(input.Right);
                    columns.AddRange(right);
                }
            }
            else if (input is SelectStatement)
            {
                SelectStatement select = input as SelectStatement;
                foreach (ColumnFragment cf in select.Columns)
                {
                    ColumnFragment newColumn = new ColumnFragment(cf.TableName,
                                                                  string.IsNullOrEmpty(cf.ColumnAlias) ? cf.ActualColumnName : cf.ColumnAlias
                                                                  );
                    newColumn.PushInput(cf.ActualColumnName);
                    if (cf.TableName != null && cf.ColumnAlias == null)
                    {
                        newColumn.PushInput(cf.TableName);
                    }
                    if (select.Name != null)
                    {
                        newColumn.PushInput(select.Name); // add the scope
                    }
                    columns.Add(newColumn);
                }
                return(columns);
            }
            else
            {
                throw new NotImplementedException();
            }
            if (!String.IsNullOrEmpty(input.Name) && input.Name != From.Name)
            {
                foreach (ColumnFragment c in columns)
                {
                    c.PushInput(input.Name);
                }
            }
            return(columns);
        }
Example #4
0
 void AddDefaultColumnsForFragment(InputFragment input)
 {
     if (input is TableFragment)
     {
         AddDefaultColumnsForTable(input as TableFragment);
     }
     else if (input is JoinFragment)
     {
         JoinFragment j = input as JoinFragment;
         AddDefaultColumnsForFragment(j.Left);
         AddDefaultColumnsForFragment(j.Right);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Example #5
0
        public void Remove(InputFragment fragment)
        {
            if (fragment == null) return;
            if (fragment.Name != null)
                scopeTable.Remove(fragment.Name);

            if (fragment is SelectStatement)
                Remove((fragment as SelectStatement).From);
            else if (fragment is JoinFragment)
            {
                JoinFragment j = fragment as JoinFragment;
                Remove(j.Left);
                Remove(j.Right);
            }
            else if (fragment is UnionFragment)
            {
                UnionFragment u = fragment as UnionFragment;
                Remove(u.Left);
                Remove(u.Right);
            }
        }
 private void WrapJoinInputIfNecessary(InputFragment fragment, bool isRightPart)
 {
     if (fragment is SelectStatement ||
         fragment is UnionFragment)
         fragment.Wrap(scope);
     else if (fragment is JoinFragment && isRightPart)
         fragment.Wrap(null);
 }
    List<ColumnFragment> GetDefaultColumnsForFragment(InputFragment input)
    {
      List<ColumnFragment> columns = new List<ColumnFragment>();

      if (input is TableFragment)
      {
        return GetDefaultColumnsForTable(input as TableFragment);
      }
      else if (input is JoinFragment || input is UnionFragment)
      {
        Debug.Assert(input.Left != null);
        columns = GetDefaultColumnsForFragment(input.Left);
        if (input is JoinFragment && input.Right != null)
        {
          List<ColumnFragment> right = GetDefaultColumnsForFragment(input.Right);
          columns.AddRange(right);
        }
      }
      else if (input is SelectStatement)
      {
        SelectStatement select = input as SelectStatement;
        foreach (ColumnFragment cf in select.Columns)
        {
          ColumnFragment newColumn = new ColumnFragment(cf.TableName,
              string.IsNullOrEmpty(cf.ColumnAlias) ? cf.ActualColumnName : cf.ColumnAlias
              );
          newColumn.PushInput(cf.ActualColumnName);
          if (cf.TableName != null && cf.ColumnAlias == null)
            newColumn.PushInput(cf.TableName);
          if (select.Name != null)
          {
            newColumn.PushInput(select.Name);      // add the scope 
          }
          columns.Add(newColumn);
        }
        return columns;
      }
      else
        throw new NotImplementedException();
      if (!String.IsNullOrEmpty(input.Name) && input.Name != From.Name)
        foreach (ColumnFragment c in columns)
        {
            c.PushInput(input.Name);
        }
      return columns;
    }
 private InputFragment WrapJoinInputIfNecessary(InputFragment fragment, bool isRightPart)
 {
   if (fragment is SelectStatement || fragment is UnionFragment)
   {
     fragment.Wrap(scope);
     fragment.Scoped = true;
   }
   else if (fragment is JoinFragment && isRightPart)
   {
     SelectStatement select = new SelectStatement();
     select.From = fragment;
     select.Name = fragment.Name;
     select.Wrap(scope);
     return select;
   }
   return fragment;
 }
 void AddDefaultColumnsForFragment(InputFragment input)
 {
     if (input is TableFragment)
     {
         AddDefaultColumnsForTable(input as TableFragment);
     }
     else if (input is JoinFragment)
     {
         JoinFragment j = input as JoinFragment;
         AddDefaultColumnsForFragment(j.Left);
         AddDefaultColumnsForFragment(j.Right);
     }
     else
         throw new NotImplementedException();
 }
Example #10
0
 public void Add(string name, InputFragment fragment)
 {
     scopeTable.Add(name, fragment);
 }
Example #11
0
 public void Remove(InputFragment fragment)
 {
   if( fragment == null ) return;
   Remove(fragment.Name, fragment);
 }