public override void VisitSetVariableStatement(SetVariableStatement setVariableStatement) { //Parameters from other sources go before inline parameters if (!_visitorMetadata.Parameters.Contains(setVariableStatement.VariableReference.Name)) { if (setVariableStatement.ScalarExpression is StringLiteral stringLiteral) { _visitorMetadata.Parameters.Add(SqlParameter.Create(setVariableStatement.VariableReference.Name, stringLiteral.Value)); } else if (setVariableStatement.ScalarExpression is IntegerLiteral integerLiteral) { _visitorMetadata.Parameters.Add(SqlParameter.Create(setVariableStatement.VariableReference.Name, integerLiteral.Value)); } else if (setVariableStatement.ScalarExpression is NumericLiteral numericLiteral) { _visitorMetadata.Parameters.Add(SqlParameter.Create(setVariableStatement.VariableReference.Name, numericLiteral.Value)); } else if (setVariableStatement.ScalarExpression is Base64Literal base64Literal) { var decodedString = Encoding.UTF8.GetString(Convert.FromBase64String(base64Literal.Value)); _visitorMetadata.Parameters.Add(SqlParameter.Create(setVariableStatement.VariableReference.Name, decodedString)); } else if (setVariableStatement.ScalarExpression is BooleanLiteral booleanLiteral) { _visitorMetadata.Parameters.Add(SqlParameter.Create(setVariableStatement.VariableReference.Name, booleanLiteral.Value)); } else { throw new NotImplementedException($"The parameter type: {setVariableStatement.ScalarExpression.GetType().Name} is not implemented"); } } }
public static EngineResult Evaluate(SetVariableStatement set, Scope scope) { scope.Env.Vars[set.Variable.Name] = Evaluate( set.AssignmentKind, scope.Env.Vars[set.Variable.Name], Evaluate(set.Expression, NullArgument.It, scope)); return(null); }
public void TestSetVariableStatementAccept() { Mock <KoraliumSqlVisitor> mock = new Mock <KoraliumSqlVisitor>(); SetVariableStatement setVariableStatement = new SetVariableStatement(); setVariableStatement.Accept(mock.Object); mock.Verify(x => x.VisitSetVariableStatement(setVariableStatement)); }
public static ValidateLogic FirstTestLogic() { ValidateLogic VL = new ValidateLogic(); DeclareVariableStatement dvs = new DeclareVariableStatement("Times", typeof(INumber)); SetVariableStatement svs = new SetVariableStatement(new LongVar("Times"), new LongConst(0)); Execute initialEx = new Execute(); initialEx.Statements.Add(dvs); initialEx.Statements.Add(svs); SetVariableStatement svs2 = new SetVariableStatement(new LongVar("Times"), new ArithmeticExpression(new LongVar("Times"), null, Operator.PlusOne)); Execute ex2 = new Execute(svs2); CompareExpression AtLeast2 = new CompareExpression(new LongVar("Times"), new LongConst(2), Operator.GreaterThanOrEqualTo); Area ar1 = new Area(null, null, VL); VL.Areas.Add(ar1); AreaStart ap1 = new AreaStart(ar1); VL.StartNode = initialEx; initialEx.NextNode = ap1; CharsToIntegerPart stip = new CharsToIntegerPart(); ar1.StartNode = stip; UnitSet us1 = new UnitSet(CharUnits.Comma); us1.Units.Add(CharUnits.WhiteSpace); stip.NextNode = us1; CharsToIntegerPart stip2 = new CharsToIntegerPart(); us1.NextNode = stip2; UnitSet us2 = new UnitSet(CharUnits.WhiteSpace); stip2.NextNode = us2; CharsToIntegerPart stip3 = new CharsToIntegerPart(); us2.NextNode = stip3; stip3.NextNode = EndNode.Instance; UnitSet us3 = " CH".ToUnitSet(); us3.Units.Add(CharUnits.AtoZ); Status st = new Status(); ap1.NextNode = us3; UnitSet CRLF = "\r\n".ToUnitSet(); st.Choices.Add(new Choice(CRLF)); st.Choices.Add(new Choice(EndNode.Instance, AtLeast2)); us3.NextNode = st; CRLF.NextNode = ex2; ex2.NextNode = ap1; //12, 56 70 CHA //08, 32 45 CHR //98, -3 45 CHD return(VL); }
public override void Visit(SetVariableStatement node) { if (node.Expression is StringLiteral strLiteral) { VariableValues[node.Variable.Name] = strLiteral.Value; } else if (node.Expression is IntegerLiteral intLiteral) { VariableValues[node.Variable.Name] = intLiteral.Value; } else if (node.Expression is BinaryExpression binaryExpression) { HandleBinaryExpression(node.Variable.Name, binaryExpression); } }
private void TestCloneSetVariableStatement_internal(SetVariableStatement setVariableStatement) { var clone = setVariableStatement.Clone() as SetVariableStatement; Assert.AreEqual(setVariableStatement, clone); Assert.IsFalse(ReferenceEquals(setVariableStatement, clone)); if (setVariableStatement.ScalarExpression != null && clone.ScalarExpression != null) { Assert.IsFalse(ReferenceEquals(setVariableStatement.ScalarExpression, clone.ScalarExpression)); } if (setVariableStatement.VariableReference != null && clone.VariableReference != null) { Assert.IsFalse(ReferenceEquals(setVariableStatement.VariableReference, clone.VariableReference)); } }
public void TestVisitSetVariableStatement() { Mock <ScalarExpression> scalarMock = new Mock <ScalarExpression>(); Mock <VariableReference> variableMock = new Mock <VariableReference>(); SetVariableStatement setVariableStatement = new SetVariableStatement() { ScalarExpression = scalarMock.Object, VariableReference = variableMock.Object }; KoraliumSqlVisitor koraliumSqlVisitor = new KoraliumSqlVisitor(); koraliumSqlVisitor.Visit(setVariableStatement); scalarMock.Verify(x => x.Accept(koraliumSqlVisitor)); variableMock.Verify(x => x.Accept(koraliumSqlVisitor)); }
public void TestSetVariable() { var actual = new SetVariableStatement() { VariableReference = new VariableReference() { Name = "@testvar" }, ScalarExpression = new StringLiteral() { Value = "test" } }.Print(); var expected = "SET @testvar = 'test'"; actual.Should().Be(expected); }
private string buildChunkedDelete(DeleteSpecification delete) { var counter = new DeclareVariableStatement(); var counterVariable = new DeclareVariableElement(); counterVariable.DataType = new SqlDataTypeReference() {SqlDataTypeOption = SqlDataTypeOption.Int}; counterVariable.VariableName = new Identifier() {Value = "@rowcount"}; counterVariable.Value = new IntegerLiteral() {Value = "10000"}; counter.Declarations.Add(counterVariable); delete.TopRowFilter = new TopRowFilter(); delete.TopRowFilter.Expression = new ParenthesisExpression() {Expression = new IntegerLiteral() {Value = "10000"} }; var setCounter = new SetVariableStatement(); setCounter.Variable = new VariableReference() {Name = "@rowcount"}; setCounter.Expression = new GlobalVariableExpression() {Name = "@@rowcount"}; setCounter.AssignmentKind = AssignmentKind.Equals; var deleteStatement = new DeleteStatement(); deleteStatement.DeleteSpecification = delete; var beginEnd = new BeginEndBlockStatement(); beginEnd.StatementList = new StatementList(); beginEnd.StatementList.Statements.Add(deleteStatement); beginEnd.StatementList.Statements.Add(setCounter); var whilePredicate = new BooleanComparisonExpression(); whilePredicate.ComparisonType = BooleanComparisonType.GreaterThan; whilePredicate.FirstExpression = new VariableReference() {Name = "@rowcount"}; whilePredicate.SecondExpression = new IntegerLiteral() {Value = "0"}; var whileStatement = new WhileStatement(); whileStatement.Predicate = whilePredicate; whileStatement.Statement = beginEnd; var text = ScriptDom.GenerateTSql(counter) + "\r\n" + ScriptDom.GenerateTSql(whileStatement); return text; }
public override void Visit(SetVariableStatement node) { ErrorCallback(RULE_NAME, RULE_TEXT, node.StartLine, node.StartColumn); }
public override SetStatement Execute() { string identifier = GetIdentifier(); if (identifier.StartsWith("@")) { var variableStatement = new SetVariableStatement(); variableStatement.Variable = identifier; Tokenizer.ExpectToken(Constants.Assignment); variableStatement.Assignment = new ExpressionParser(Tokenizer).Execute(); return(variableStatement); } else if (_options.Contains(identifier)) { var optionStatement = new SetOptionStatement(); if (String.Compare(identifier, Constants.Statistics, true) == 0) { if (!Tokenizer.IsNextToken(Constants.Io, Constants.Xml, Constants.Profile, Constants.Time)) { throw new SyntaxException("STATISTIC expects IO, XML, PROFILE, or TIME"); } identifier += " " + Tokenizer.Current.Value; Tokenizer.ReadNextToken(); } optionStatement.Option = identifier; if (!Tokenizer.IsNextToken(Constants.On, Constants.Off)) { throw new SyntaxException("SET [option] expects ON or OFF"); } optionStatement.Assignment = new StringExpression(Tokenizer.Current.Value, null); Tokenizer.ReadNextToken(); return(optionStatement); } else { switch (identifier) { case Constants.DateFirst: { SetDateFirstStatement statement = new SetDateFirstStatement(); ReadAssignment(statement); return(statement); } case Constants.DateFormat: { SetDateFormatStatement statement = new SetDateFormatStatement(); ReadAssignment(statement); return(statement); } case Constants.DeadlockPriority: { SetDeadlockPriorityStatement statement = new SetDeadlockPriorityStatement(); ReadAssignment(statement); return(statement); } } } throw new ParserNotImplementedException(String.Format("SET {0} is not supported", identifier)); }
public override void Visit(SetVariableStatement node) { this.action(node); }
public void TestSetVariableStatementEquals() { SetVariableStatement first = new SetVariableStatement() { ScalarExpression = new StringLiteral() { Value = "test" }, VariableReference = new VariableReference() { Name = "t" } }; SetVariableStatement firstClone = new SetVariableStatement() { ScalarExpression = new StringLiteral() { Value = "test" }, VariableReference = new VariableReference() { Name = "t" } }; SetVariableStatement second = new SetVariableStatement() { ScalarExpression = new StringLiteral() { Value = "test2" }, VariableReference = new VariableReference() { Name = "t" } }; SetVariableStatement third = new SetVariableStatement() { ScalarExpression = new StringLiteral() { Value = "test" }, VariableReference = new VariableReference() { Name = "t2" } }; //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(SetVariableStatement fragment) { _fragments.Add(fragment); }
public override void Visit(SetVariableStatement setVariableStatement) { var result = ParseScalarExpression(setVariableStatement.Expression); StoreResult(result); }
public override void Visit(SetVariableStatement node) { Traverse(node); }
public virtual void VisitSetVariableStatement(SetVariableStatement setVariableStatement) { Visit(setVariableStatement.VariableReference); Visit(setVariableStatement.ScalarExpression); //DONE }
private string buildChunkedDelete(DeleteSpecification delete) { var counter = new DeclareVariableStatement(); var counterVariable = new DeclareVariableElement(); counterVariable.DataType = new SqlDataTypeReference() { SqlDataTypeOption = SqlDataTypeOption.Int }; counterVariable.VariableName = new Identifier() { Value = "@rowcount" }; counterVariable.Value = new IntegerLiteral() { Value = "10000" }; counter.Declarations.Add(counterVariable); delete.TopRowFilter = new TopRowFilter(); delete.TopRowFilter.Expression = new ParenthesisExpression() { Expression = new IntegerLiteral() { Value = "10000" } }; var setCounter = new SetVariableStatement(); setCounter.Variable = new VariableReference() { Name = "@rowcount" }; setCounter.Expression = new GlobalVariableExpression() { Name = "@@rowcount" }; setCounter.AssignmentKind = AssignmentKind.Equals; var deleteStatement = new DeleteStatement(); deleteStatement.DeleteSpecification = delete; var beginEnd = new BeginEndBlockStatement(); beginEnd.StatementList = new StatementList(); beginEnd.StatementList.Statements.Add(deleteStatement); beginEnd.StatementList.Statements.Add(setCounter); var whilePredicate = new BooleanComparisonExpression(); whilePredicate.ComparisonType = BooleanComparisonType.GreaterThan; whilePredicate.FirstExpression = new VariableReference() { Name = "@rowcount" }; whilePredicate.SecondExpression = new IntegerLiteral() { Value = "0" }; var whileStatement = new WhileStatement(); whileStatement.Predicate = whilePredicate; whileStatement.Statement = beginEnd; var text = ScriptDom.GenerateTSql(counter) + "\r\n" + ScriptDom.GenerateTSql(whileStatement); return(text); }
public override void Visit(SetVariableStatement node) { errorCallback(RULE_NAME, RULE_TEXT, node.StartLine, GetColumnNumber(node)); }