public void TestSelectStarExpressionEquals()
        {
            SelectStarExpression first = new SelectStarExpression()
            {
                Alias = "test"
            };

            SelectStarExpression firstClone = new SelectStarExpression()
            {
                Alias = "test"
            };

            SelectStarExpression second = new SelectStarExpression()
            {
                Alias = "test2"
            };

            //Equals
            Assert.IsTrue(Equals(first, firstClone));
            Assert.IsFalse(Equals(first, null));
            Assert.IsFalse(Equals(first, second));
            Assert.IsFalse(Equals(first, "other type"));

            //Hash code
            Assert.AreEqual(first.GetHashCode(), firstClone.GetHashCode());
            Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode());
        }
Beispiel #2
0
        public void TestSelectStarExpressionAccept()
        {
            Mock <KoraliumSqlVisitor> mock = new Mock <KoraliumSqlVisitor>();
            SelectStarExpression      selectStarExpression = new SelectStarExpression();

            selectStarExpression.Accept(mock.Object);
            mock.Verify(x => x.VisitSelectStarExpression(selectStarExpression));
        }
Beispiel #3
0
        public override void Visit(SelectStarExpression node)
        {
            if (expressionCounter > 0)
            {
                expressionCounter--;
                return;
            }

            errorCallback(RULE_NAME, RULE_TEXT, node.StartLine, node.StartColumn);
        }
Beispiel #4
0
 protected override object InternalVisit(SelectStarExpression node)
 {
     return(new Func <Environment, object>(env =>
     {
         return new Func <IResultTable, Selector[]>(table =>
         {
             return table.Columns.Select(col => col.GetDefaultSelector).ToArray();
         });
     }));
 }
        public void TestVisitSelectStarExpression()
        {
            SelectStarExpression selectStarExpression = new SelectStarExpression();
            KoraliumSqlVisitor   koraliumSqlVisitor   = new KoraliumSqlVisitor();

            koraliumSqlVisitor.Visit(selectStarExpression);

            //Nothing to verify yet, only that no exceptions are thrown
            Assert.Pass();
        }
Beispiel #6
0
        public QsiColumnNode VisitSelectStarExpression(SelectStarExpression selectStarExpression)
        {
            return(TreeHelper.Create <QsiAllColumnNode>(n =>
            {
                if (selectStarExpression.Qualifier != null)
                {
                    n.Path = IdentifierVisitor.CreateQualifiedIdentifier(selectStarExpression.Qualifier);
                }

                SqlServerTree.PutFragmentSpan(n, selectStarExpression);
            }));
        }
Beispiel #7
0
        public void TestCloneSelectStarExpression()
        {
            SelectStarExpression selectStarExpression = new SelectStarExpression()
            {
                Alias = "test"
            };

            var clone = selectStarExpression.Clone() as SelectStarExpression;

            Assert.AreEqual(selectStarExpression, clone);
            Assert.IsFalse(ReferenceEquals(selectStarExpression, clone));
        }
Beispiel #8
0
        public Column GetColumnFromStarReference(SelectStarExpression expression, IEnumerable <Table> containers, IEnumerable <Table> parentContainers, IEnumerable <Cte> ctes)
        {
            if (expression == null)
            {
                return(null);
            }

            var identifiers = expression.Qualifier?.Identifiers != null?expression.Qualifier?.Identifiers.ToArray() : new Identifier[0];

            var names = identifiers.Select(i => i.Value).Concat(new[] { "*" }).ToArray();

            return(GetColumnFromIdentifiers(names, null, containers, parentContainers, ctes));
        }
Beispiel #9
0
        public override void VisitSelectStarExpression(SelectStarExpression selectStarExpression)
        {
            if (expressionStack.Count == 0)
            {
                foreach (var property in _previousStage.TypeInfo.GetProperties())
                {
                    if (property.Value.GetCustomAttribute <KoraliumIgnoreAttribute>() != null)
                    {
                        continue;
                    }

                    //Set property as used
                    AddUsedProperty(property.Value);

                    var memberExpression = Expression.MakeMemberAccess(_previousStage.ParameterExpression, property.Value);
                    selectExpressions.Add(new SelectExpression(memberExpression, property.Key));
                }
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Beispiel #10
0
 public override void Visit(SelectStarExpression node) { this.action(node); }
Beispiel #11
0
 public override void Visit(SelectStarExpression node)
 {
     SelectStarExpressionCount++;
 }
 public override void ExplicitVisit(SelectStarExpression fragment)
 {
     _fragments.Add(fragment);
 }
Beispiel #13
0
        public override void ExplicitVisit(SelectStarExpression node)
        {
            string query = String.Join(string.Empty, node.ScriptTokenStream.Select(sts => sts.Text).ToArray());

            string tableNameOrAlias = string.Empty;
            bool   hasIdentifier    = false;

            if (node.Qualifier != null)
            {
                tableNameOrAlias = node.Qualifier.Identifiers[0].Value;
                hasIdentifier    = true;
            }
            else
            {
                int pos = node.ScriptTokenStream.Select((v, i) => new { token = v, index = i }).First(sts => sts.token.TokenType == TSqlTokenType.From).index;
                tableNameOrAlias = node.ScriptTokenStream[pos + 2].Text;

                if ((node.ScriptTokenStream.Count >
                     (pos + 2 + 2)) &&
                    (node.ScriptTokenStream[pos + 4].TokenType == TSqlTokenType.Identifier))
                {
                    //e.g. 'select * from Author a' getting 'a'
                    tableNameOrAlias = node.ScriptTokenStream[pos + 4].Text;
                }
            }

            bool      isAlias = false;
            RbacTable table   = Context.User.Role.CrudPermissions.Find(tableNameOrAlias, ref isAlias);

            if (table != null)
            {
                foreach (RbacColumn col in table.Columns)
                {
                    RbacSelectColumn column = new RbacSelectColumn();
                    if (isAlias)
                    {
                        column.Table.Alias = tableNameOrAlias;
                        column.Table.Name  = table.Name;
                    }
                    else
                    {
                        column.Table.Name = tableNameOrAlias;
                    }

                    column.Table = table;
                    column.Name  = col.Name;
                    Columns.Add(column);
                }

                if ((isAlias) && (hasIdentifier))
                {
                    ParsedQuery = query.Replace(tableNameOrAlias + ".*", table.Columns.ToCommaSeparatedString(tableNameOrAlias));
                }
                else
                {
                    ParsedQuery = query.Replace("*", table.Columns.ToCommaSeparatedString(tableNameOrAlias));
                }
            }
            else
            {
                RbacException.Raise(string.Format("The referred table {0} was not found in meta data!", tableNameOrAlias),
                                    RbacExceptionCategories.Parser);
            }
        }
 public override void ExplicitVisit(SelectStarExpression node)
 {
     IsSuspected = true;
     base.ExplicitVisit(node);
 }
Beispiel #15
0
 public override void ExplicitVisit(SelectStarExpression node)
 {
     this.SelectStarExpressions.Add(node);
 }
 public gsColumnParserSelectStar(SelectElement element)
     : base(element)
 {
     _Expression = element as SelectStarExpression;
 }
Beispiel #17
0
 public override void ExplicitVisit(SelectStarExpression node)
 {
     Console.WriteLine($"Visiting SelectStarExpression: {node}");
 }
Beispiel #18
0
 public override void ExplicitVisit(SelectStarExpression node)
 {
     base.ExplicitVisit(node);
     Console.WriteLine("* ");
 }
 public override void Visit(SelectStarExpression node)
 {
     ReturnValues.Add(new SelectElementWrapper(node, _queryExpressionId, string.Empty, false));
     base.Visit(node);
 }
Beispiel #20
0
 public virtual void VisitSelectStarExpression(SelectStarExpression selectStarExpression)
 {
     //NOP
 }