Exemplo n.º 1
0
        public override SqlFragment Visit(DbVariableReferenceExpression expression)
        {
            PropertyFragment fragment = new PropertyFragment();

            fragment.Properties.Add(expression.VariableName);
            return(fragment);
        }
Exemplo n.º 2
0
 public ColumnFragment GetColumnFromProperties(PropertyFragment properties)
 {
     ColumnFragment col = Left.GetColumnFromProperties(properties);
     if (col == null)
         col = Right.GetColumnFromProperties(properties);
     return col;
 }
Exemplo n.º 3
0
        public InputFragment FindInputFromProperties(PropertyFragment fragment)
        {
            Debug.Assert(fragment != null);
            PropertyFragment propertyFragment = fragment as PropertyFragment;

            Debug.Assert(propertyFragment != null);

            if (propertyFragment.Properties.Count >= 2)
            {
                for (int x = propertyFragment.Properties.Count - 2; x >= 0; x--)
                {
                    string reference = propertyFragment.Properties[x];
                    if (reference == null)
                    {
                        continue;
                    }
                    InputFragment input = GetFragment(reference);
                    if (input == null)
                    {
                        continue;
                    }
                    if (input.Scoped)
                    {
                        return(input);
                    }
                    if (input is SelectStatement)
                    {
                        return((input as SelectStatement).From);
                    }
                    continue;
                }
            }
            Debug.Fail("Should have found an input");
            return(null);
        }
Exemplo n.º 4
0
        public override bool Equals(object obj)
        {
            if (!(obj is PropertyFragment))
            {
                return(false);
            }
            PropertyFragment prop = obj as PropertyFragment;

            Debug.Assert(Properties != null && prop.Properties != null);
            int aIndex = Properties.Count - 1;
            int bIndex = prop.Properties.Count - 1;
            int cnt    = 0;

            while (aIndex >= 0 && bIndex >= 0)
            {
                if (String.Compare(Properties[aIndex--], prop.Properties[bIndex--], true) != 0)
                {
                    return(false);
                }
                if (++cnt == 2)
                {
                    break;
                }
            }
            return(true);
        }
Exemplo n.º 5
0
        public override SqlFragment Visit(DbPropertyExpression expression)
        {
            propertyLevel++;
            PropertyFragment fragment = expression.Instance.Accept(this) as PropertyFragment;

            fragment.Properties.Add(expression.Property.Name);
            propertyLevel--;

            // if we are not at the top level property then just return
            if (propertyLevel > 0)
            {
                return(fragment);
            }

            // we are at the top level property so now we can do our work
            ColumnFragment column = GetColumnFromPropertyTree(fragment);

            for (int i = fragment.Properties.Count - 1; i >= 0; --i)
            {
                InputFragment inputFragment = scope.GetFragment(fragment.Properties[i]);
                if (inputFragment != null)
                {
                    column.TableAlias = inputFragment.Name;
                    break;
                }
            }
            return(column);
        }
Exemplo n.º 6
0
        ColumnFragment GetColumnFromPropertyTree(PropertyFragment fragment)
        {
            int         lastIndex       = fragment.Properties.Count - 1;
            SqlFragment currentFragment = scope.GetFragment(fragment.Properties[0]);

            if (currentFragment != null)
            {
                for (int i = 1; i < fragment.Properties.Count; i++)
                {
                    SqlFragment f = (currentFragment as InputFragment).GetProperty(fragment.Properties[i]);
                    if (f == null)
                    {
                        break;
                    }
                    currentFragment = f;
                }
                if (currentFragment is ColumnFragment)
                {
                    return(currentFragment as ColumnFragment);
                }
            }
            ColumnFragment col = new ColumnFragment(null, fragment.Properties[lastIndex]);

            return(col);
        }
 public void PushInput(string inputName)
 {
     if (PropertyFragment == null)
     {
         PropertyFragment = new PropertyFragment();
     }
     PropertyFragment.PushProperty(inputName);
 }
        public PropertyFragment Clone()
        {
            PropertyFragment newPF = new PropertyFragment();

            foreach (string prop in Properties)
            {
                newPF.Properties.Add(prop);
            }
            return(newPF);
        }
Exemplo n.º 9
0
        public ColumnFragment GetColumnFromProperties(PropertyFragment properties)
        {
            ColumnFragment col = Left.GetColumnFromProperties(properties);

            if (col == null)
            {
                col = Right.GetColumnFromProperties(properties);
            }
            return(col);
        }
Exemplo n.º 10
0
        public override SqlFragment Visit(DbPropertyExpression expression)
        {
            propertyLevel++;
            PropertyFragment fragment = expression.Instance.Accept(this) as PropertyFragment;

            fragment.Properties.Add(expression.Property.Name);
            propertyLevel--;

            // if we are not at the top level property then just return
            if (propertyLevel > 0)
            {
                return(fragment);
            }

            ColumnFragment column = new ColumnFragment(null, fragment.LastProperty);

            column.PropertyFragment = fragment;
            InputFragment input = scope.FindInputFromProperties(fragment);

            if (input != null)
            {
                column.TableName = input.Name;
            }

            // now we need to check if our column name was possibly renamed
            if (input is TableFragment)
            {
                return(column);
            }

            SelectStatement select = input as SelectStatement;
            UnionFragment   union  = input as UnionFragment;

            if (select != null)
            {
                select.HasDifferentNameForColumn(column);
            }
            else if (union != null)
            {
                union.HasDifferentNameForColumn(column);
            }

            // input is a table, selectstatement, or unionstatement
            return(column);
        }
Exemplo n.º 11
0
        public InputFragment FindInputFromProperties(PropertyFragment fragment)
        {
            Debug.Assert(fragment != null);
            PropertyFragment propertyFragment = fragment as PropertyFragment;
            Debug.Assert(propertyFragment != null);

            if (propertyFragment.Properties.Count >= 2)
            {
                for (int x = propertyFragment.Properties.Count - 2; x >= 0; x--)
                {
                    string reference = propertyFragment.Properties[x];
                    InputFragment input = GetFragment(reference);
                    if (input == null) continue;
                    if (input.Scoped) return input;
                    if (input is SelectStatement)
                        return (input as SelectStatement).From;
                    continue;
                }
            }
            Debug.Fail("Should have found an input");
            return null;
        }
Exemplo n.º 12
0
 public PropertyFragment Clone()
 {
     PropertyFragment newPF = new PropertyFragment();
       foreach (string prop in Properties)
     newPF.Properties.Add(prop);
       return newPF;
 }
Exemplo n.º 13
0
 public void PushInput(string inputName)
 {
     if (PropertyFragment == null)
     PropertyFragment = new PropertyFragment();
       PropertyFragment.PushProperty(inputName);
 }
Exemplo n.º 14
0
        public override SqlFragment Visit(DbPropertyExpression expression)
        {
            propertyLevel++;
            PropertyFragment fragment = expression.Instance.Accept(this) as PropertyFragment;

            fragment.Properties.Add(expression.Property.Name);
            propertyLevel--;

            // if we are not at the top level property then just return
            if (propertyLevel > 0)
            {
                return(fragment);
            }

            ColumnFragment column = new ColumnFragment(null, fragment.LastProperty);

            column.PropertyFragment = fragment;
            InputFragment input = scope.FindInputFromProperties(fragment);

            if (input != null)
            {
                column.TableName = input.Name;
            }

            // now we need to check if our column name was possibly renamed
            if (input is TableFragment)
            {
                if (!string.IsNullOrEmpty(input.Name))
                {
                    SelectStatement sf = scope.GetFragment(input.Name) as SelectStatement;
                    if (sf != null)
                    {
                        // Special case: undo alias in case of query fusing
                        for (int i = 0; i < sf.Columns.Count; i++)
                        {
                            ColumnFragment cf = sf.Columns[i];
                            if (column.ColumnName == cf.ColumnAlias)
                            {
                                column.ColumnName  = cf.ColumnName;
                                column.ColumnAlias = cf.ColumnAlias;
                                column.TableName   = input.Name;
                                return(column);
                            }
                        }
                    }
                }
                return(column);
            }

            SelectStatement select = input as SelectStatement;
            UnionFragment   union  = input as UnionFragment;

            if (select != null)
            {
                select.HasDifferentNameForColumn(column);
            }
            else if (union != null)
            {
                union.HasDifferentNameForColumn(column);
            }

            // input is a table, selectstatement, or unionstatement
            return(column);
        }