public override void ExplicitVisit(BooleanIsNullExpression node)
        {
            var function = node.Expression as FunctionCall;

            checkIsSuspected(function);
            base.ExplicitVisit(node);
        }
Ejemplo n.º 2
0
        private void BuildEqualsSameLiteral(BooleanExpression search, ScalarExpression firstParam, Literal literal)
        {
            var newExpression = new BooleanParenthesisExpression();
            var expression    = new BooleanBinaryExpression();

            newExpression.Expression = expression;

            expression.BinaryExpressionType = BooleanBinaryExpressionType.Or;
            var isnull = new BooleanIsNullExpression();

            isnull.Expression          = firstParam;
            expression.FirstExpression = isnull;

            var second = new BooleanComparisonExpression();

            second.FirstExpression      = firstParam;
            second.SecondExpression     = literal;
            expression.SecondExpression = second;

            var sql = ScriptDom.GenerateTSql(newExpression);

            _replacementsToMake.Add(new Replacements
            {
                Original         = _script.Substring(search.StartOffset, search.FragmentLength),
                OriginalLength   = search.FragmentLength,
                OriginalOffset   = search.StartOffset,
                Replacement      = sql,
                OriginalFragment = _currentFragment
            });
        }
Ejemplo n.º 3
0
        //The isNulls are used in the search condition to find out if any of the columns are different and therefore need an update
        private List <BooleanIsNullExpression> BuildNullIfStatements()
        {
            var isNulls = new List <BooleanIsNullExpression>();

            foreach (var descriptor in _merge.Table.Columns)
            {
                var nullExpression = new NullIfExpression();

                //var first =
                //    (nullExpression.FirstExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression;
                //first.MultiPartIdentifier =  MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.SourceName, descriptor.Name.GetName());

                //var second =
                //    (nullExpression.SecondExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression;
                //second.MultiPartIdentifier = MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.TargetName, descriptor.Name.GetName());

                nullExpression.FirstExpression  = GetColumnOrCastColumn(descriptor, MergeIdentifierStrings.SourceName);
                nullExpression.SecondExpression = GetColumnOrCastColumn(descriptor, MergeIdentifierStrings.TargetName);

                var isNullExpresson = new BooleanIsNullExpression();
                isNullExpresson.Expression = nullExpression;
                isNullExpresson.IsNot      = true;
                isNulls.Add(isNullExpresson);
            }

            return(isNulls);
        }
        private BooleanIsNullExpression GetIsNotNull()
        {
            var isNull = new BooleanIsNullExpression();
            isNull.IsNot = true;
            var query = (isNull.Expression = new ScalarSubquery()) as ScalarSubquery;
            var spec = (query.QueryExpression = new QuerySpecification()) as QuerySpecification;
            spec.SelectElements.Add(new SelectStarExpression());
            var fromTable = new QueryDerivedTable();
            spec.FromClause = new FromClause();
            spec.FromClause.TableReferences.Add(fromTable);
            var subQuerySpec = new QuerySpecification();
            var version = new GlobalVariableExpression();
            version.Name = "@@version";

            var columnName = new IdentifierOrValueExpression();
            //var v = (columnName.ValueExpression = new StringLiteral()) as StringLiteral;
            //v.Value = "v";
            columnName.Identifier = new Identifier();
            columnName.Identifier.Value = "v";

            subQuerySpec.SelectElements.Add(new SelectScalarExpression {Expression = version, ColumnName = columnName});
            fromTable.QueryExpression = subQuerySpec;
            fromTable.Alias = new Identifier {Value = "edition"};

            spec.WhereClause = new WhereClause();
            var likePredicate = (spec.WhereClause.SearchCondition = new LikePredicate()) as LikePredicate;
            var col = (likePredicate.FirstExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression;
            col.ColumnType = ColumnType.Regular;
            col.MultiPartIdentifier = new MultiPartIdentifier();
            col.MultiPartIdentifier.Identifiers.Add(new Identifier {Value = "v"});
            var ver = (likePredicate.SecondExpression = new StringLiteral()) as StringLiteral;
            ver.Value = "%Enterprise%";

            return isNull;
        }
Ejemplo n.º 5
0
        public override void VisitBooleanIsNullExpression(BooleanIsNullExpression booleanIsNullExpression)
        {
            booleanIsNullExpression.ScalarExpression.Accept(this);

            var expression = PopStack();


            if (booleanIsNullExpression.IsNot)
            {
                if (expression.Type.IsPrimitive)
                {
                    AddExpressionToStack(Expression.Constant(true));
                }
                else
                {
                    AddExpressionToStack(Expression.NotEqual(expression, Expression.Constant(null)));
                }
            }
            else
            {
                if (expression.Type.IsPrimitive)
                {
                    AddExpressionToStack(Expression.Constant(false));
                }
                else
                {
                    AddExpressionToStack(Expression.Equal(expression, Expression.Constant(null)));
                }
            }
        }
Ejemplo n.º 6
0
        public void TestBooleanIsNullExpressionAccept()
        {
            Mock <KoraliumSqlVisitor> mock = new Mock <KoraliumSqlVisitor>();
            BooleanIsNullExpression   booleanIsNullExpression = new BooleanIsNullExpression();

            booleanIsNullExpression.Accept(mock.Object);
            mock.Verify(x => x.VisitBooleanIsNullExpression(booleanIsNullExpression));
        }
Ejemplo n.º 7
0
        internal gsWhereTermBase GetWhereTerm(BooleanIsNullExpression booleanIsNullExpression)
        {
            gsWhereTermIsNullOrNotNull whereTerm = new gsWhereTermIsNullOrNotNull();

            whereTerm.NullType   = booleanIsNullExpression.IsNot ? gsNullOrNotNull.NotNull : gsNullOrNotNull.Null;
            whereTerm.Expression = gsScalarExpressionParserFactory.CreateParser(booleanIsNullExpression.Expression, null).Parse();

            return(whereTerm);
        }
Ejemplo n.º 8
0
        public QsiBinaryExpressionNode VisitBooleanIsNullExpression(BooleanIsNullExpression booleanIsNullExpression)
        {
            return(TreeHelper.Create <QsiBinaryExpressionNode>(n =>
            {
                n.Left.SetValue(VisitScalarExpression(booleanIsNullExpression.Expression));
                n.Right.SetValue(TreeHelper.CreateNullLiteral());

                n.Operator = booleanIsNullExpression.IsNot ? SqlServerKnownOperator.NotEqualToExclamation : SqlServerKnownOperator.Equals;
            }));
        }
Ejemplo n.º 9
0
 public override void ExplicitVisit(BooleanIsNullExpression node)
 {
     node.Expression.Accept(this);
     if (node.IsNot)
     {
         _buffer.Append(" is not null");
     }
     else
     {
         _buffer.Append(" is null");
     }
 }
Ejemplo n.º 10
0
        public void TestVisitBooleanIsNullExpression()
        {
            Mock <ScalarExpression> mock = new Mock <ScalarExpression>();
            BooleanIsNullExpression booleanIsNullExpression = new BooleanIsNullExpression()
            {
                ScalarExpression = mock.Object
            };

            KoraliumSqlVisitor koraliumSqlVisitor = new KoraliumSqlVisitor();

            koraliumSqlVisitor.Visit(booleanIsNullExpression);

            mock.Verify(x => x.Accept(koraliumSqlVisitor));
        }
        private BooleanIsNullExpression GetIsNotNull()
        {
            var isNull = new BooleanIsNullExpression();

            isNull.IsNot = true;
            var query = (isNull.Expression = new ScalarSubquery()) as ScalarSubquery;
            var spec  = (query.QueryExpression = new QuerySpecification()) as QuerySpecification;

            spec.SelectElements.Add(new SelectStarExpression());
            var fromTable = new QueryDerivedTable();

            spec.FromClause = new FromClause();
            spec.FromClause.TableReferences.Add(fromTable);
            var subQuerySpec = new QuerySpecification();
            var version      = new GlobalVariableExpression();

            version.Name = "@@version";

            var columnName = new IdentifierOrValueExpression();

            //var v = (columnName.ValueExpression = new StringLiteral()) as StringLiteral;
            //v.Value = "v";
            columnName.Identifier       = new Identifier();
            columnName.Identifier.Value = "v";


            subQuerySpec.SelectElements.Add(new SelectScalarExpression {
                Expression = version, ColumnName = columnName
            });
            fromTable.QueryExpression = subQuerySpec;
            fromTable.Alias           = new Identifier {
                Value = "edition"
            };

            spec.WhereClause = new WhereClause();
            var likePredicate = (spec.WhereClause.SearchCondition = new LikePredicate()) as LikePredicate;
            var col           = (likePredicate.FirstExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression;

            col.ColumnType          = ColumnType.Regular;
            col.MultiPartIdentifier = new MultiPartIdentifier();
            col.MultiPartIdentifier.Identifiers.Add(new Identifier {
                Value = "v"
            });
            var ver = (likePredicate.SecondExpression = new StringLiteral()) as StringLiteral;

            ver.Value = "%Enterprise%";

            return(isNull);
        }
Ejemplo n.º 12
0
        public void TestBooleanIsNull()
        {
            var actual = new BooleanIsNullExpression()
            {
                ScalarExpression = new ColumnReference()
                {
                    Identifiers = new List <string> {
                        "c1"
                    }
                }
            }.Print();
            var expected = "c1 IS NULL";

            actual.Should().Be(expected);
        }
        public override void ExplicitVisit(BooleanIsNullExpression node)
        {
            cs.CodeBinaryOperatorExpression binary = new cs.CodeBinaryOperatorExpression();
            binary.Operator = node.IsNot
                ? cs.CodeBinaryOperatorType.IdentityInequality
                : cs.CodeBinaryOperatorType.ValueEquality;
            binary.Left  = TryBuildFromNode(node.Expression, ref lastHasError, ref lastError);
            binary.Right = new cs.CodePrimitiveExpression(null);

            if (lastHasError)
            {
            }
            else
            {
                this.lastExpression = binary;
            }
        }
Ejemplo n.º 14
0
        public void TestCloneBooleanIsNullExpression()
        {
            BooleanIsNullExpression booleanIsNullExpression = new BooleanIsNullExpression()
            {
                IsNot            = false,
                ScalarExpression = new ColumnReference()
                {
                    Identifiers = new List <string>()
                    {
                        "c1"
                    }
                }
            };

            var clone = booleanIsNullExpression.Clone() as BooleanIsNullExpression;

            Assert.AreEqual(booleanIsNullExpression, clone);
            Assert.IsFalse(ReferenceEquals(booleanIsNullExpression, clone));
            Assert.IsFalse(ReferenceEquals(booleanIsNullExpression.ScalarExpression, clone.ScalarExpression));
        }
Ejemplo n.º 15
0
        //The isNulls are used in the search condition to find out if any of the columns are different and therefore need an update
        private List <BooleanIsNullExpression> BuildNullIfStatements()
        {
            var isNulls = new List <BooleanIsNullExpression>();

            foreach (var descriptor in _columnDescriptors)
            {
                var nullExpression = new NullIfExpression();

                var first =
                    (nullExpression.FirstExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression;
                first.MultiPartIdentifier = new MultiPartIdentifier().Create(MergeIdentifierStrings.SourceName, descriptor.Name);

                var second =
                    (nullExpression.SecondExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression;
                second.MultiPartIdentifier = new MultiPartIdentifier().Create(MergeIdentifierStrings.TargetName, descriptor.Name);

                var isNullExpresson = new BooleanIsNullExpression();
                isNullExpresson.Expression = nullExpression;
                isNullExpresson.IsNot      = true;
                isNulls.Add(isNullExpresson);
            }

            return(isNulls);
        }
Ejemplo n.º 16
0
        //The isNulls are used in the search condition to find out if any of the columns are different and therefore need an update
        private List<BooleanIsNullExpression> BuildNullIfStatements()
        {
            var isNulls = new List<BooleanIsNullExpression>();

            foreach (var descriptor in _columnDescriptors)
            {
                var nullExpression = new NullIfExpression();

                var first =
                    (nullExpression.FirstExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression;
                first.MultiPartIdentifier = new MultiPartIdentifier().Create(MergeIdentifierStrings.SourceName, descriptor.Name);

                var second =
                    (nullExpression.SecondExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression;
                second.MultiPartIdentifier = new MultiPartIdentifier().Create(MergeIdentifierStrings.TargetName, descriptor.Name);

                var isNullExpresson = new BooleanIsNullExpression();
                isNullExpresson.Expression = nullExpression;
                isNullExpresson.IsNot = true;
                isNulls.Add(isNullExpresson);
            }

            return isNulls;
        }
Ejemplo n.º 17
0
        private void BuildEqualsSameLiteral(BooleanExpression search, ScalarExpression firstParam, Literal literal)
        {
            var newExpression = new BooleanParenthesisExpression();
            var expression = new BooleanBinaryExpression();
            newExpression.Expression = expression;

            expression.BinaryExpressionType = BooleanBinaryExpressionType.Or;
            var isnull = new BooleanIsNullExpression();
            isnull.Expression = firstParam;
            expression.FirstExpression = isnull;

            var second = new BooleanComparisonExpression();
            second.FirstExpression = firstParam;
            second.SecondExpression = literal;
            expression.SecondExpression = second;

            var sql = ScriptDom.GenerateTSql(newExpression);

            _replacementsToMake.Add(new Replacements
            {
                Original = _script.Substring(search.StartOffset, search.FragmentLength),
                OriginalLength = search.FragmentLength,
                OriginalOffset = search.StartOffset,
                Replacement = sql,
                OriginalFragment = _currentFragment
            });
        }
Ejemplo n.º 18
0
 public virtual void VisitBooleanIsNullExpression(BooleanIsNullExpression booleanIsNullExpression)
 {
     Visit(booleanIsNullExpression.ScalarExpression);
     //DONE
 }
 public override void ExplicitVisit(BooleanIsNullExpression node)
 {
     var function = node.Expression as FunctionCall;
     checkIsSuspected(function);
     base.ExplicitVisit(node);
 }
Ejemplo n.º 20
0
 public override void Visit(BooleanIsNullExpression node) { this.action(node); }
Ejemplo n.º 21
0
        public void TestBooleanIsNullExpressionEquals()
        {
            BooleanIsNullExpression first = new BooleanIsNullExpression()
            {
                IsNot            = false,
                ScalarExpression = new ColumnReference()
                {
                    Identifiers = new List <string>()
                    {
                        "c1"
                    }
                }
            };

            BooleanIsNullExpression firstClone = new BooleanIsNullExpression()
            {
                IsNot            = false,
                ScalarExpression = new ColumnReference()
                {
                    Identifiers = new List <string>()
                    {
                        "c1"
                    }
                }
            };

            BooleanIsNullExpression second = new BooleanIsNullExpression()
            {
                IsNot            = true,
                ScalarExpression = new ColumnReference()
                {
                    Identifiers = new List <string>()
                    {
                        "c1"
                    }
                }
            };

            BooleanIsNullExpression third = new BooleanIsNullExpression()
            {
                IsNot            = false,
                ScalarExpression = new ColumnReference()
                {
                    Identifiers = new List <string>()
                    {
                        "c2"
                    }
                }
            };

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

            //Hash code
            Assert.AreEqual(first.GetHashCode(), firstClone.GetHashCode());
            Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode());
            Assert.AreNotEqual(first.GetHashCode(), third.GetHashCode());
        }
 public override void ExplicitVisit(BooleanIsNullExpression fragment)
 {
     _fragments.Add(fragment);
 }
Ejemplo n.º 23
0
 public override void ExplicitVisit(BooleanIsNullExpression node)
 {
     base.ExplicitVisit(node);
     ReplaceExpression(node, n => n.Expression);
 }
Ejemplo n.º 24
0
        //The isNulls are used in the search condition to find out if any of the columns are different and therefore need an update
        private List<BooleanIsNullExpression> BuildNullIfStatements()
        {
            var isNulls = new List<BooleanIsNullExpression>();

            foreach (var descriptor in _merge.Table.Columns)
            {
                var nullExpression = new NullIfExpression();

                //var first =
                //    (nullExpression.FirstExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression;
                //first.MultiPartIdentifier =  MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.SourceName, descriptor.Name.GetName());

                //var second =
                //    (nullExpression.SecondExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression;
                //second.MultiPartIdentifier = MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.TargetName, descriptor.Name.GetName());

                nullExpression.FirstExpression = GetColumnOrCastColumn(descriptor, MergeIdentifierStrings.SourceName);
                nullExpression.SecondExpression = GetColumnOrCastColumn(descriptor, MergeIdentifierStrings.TargetName);

                var isNullExpresson = new BooleanIsNullExpression();
                isNullExpresson.Expression = nullExpression;
                isNullExpresson.IsNot = true;
                isNulls.Add(isNullExpresson);
            }

            return isNulls;
        }