public static SyntaxNode BuildSyntaxTree(string statement) { if (string.IsNullOrWhiteSpace(statement)) { throw new ArgumentException("No statement to process", nameof(statement)); } var tokens = SqlLexer.Tokenise(statement, OperationTokens.AllTokens); var syntaxTree = SyntaxTreeBuilder.Build(tokens); return(syntaxTree); }
public void CorrectlyTokenisesUseExample(string statement) { var result = SqlLexer.Tokenise(statement, OperationTokens.AllTokens); var expectedResult = new List <SyntaxToken> { OperationTokens.Use, new SyntaxToken("database1") }; Assert.Equal(expectedResult.Count, result.Count); for (int i = 0; i < expectedResult.Count; i++) { Assert.Equal(expectedResult[i].Value, result[i].Value); } }
public void CorrectlyTokenisesInsertExample(string statement) { var result = SqlLexer.Tokenise(statement, OperationTokens.AllTokens); var expectedResult = new List <SyntaxToken> { OperationTokens.InsertInto, new SyntaxToken("user_notes (id, user_id, note, created)"), OperationTokens.Values, new SyntaxToken("(1, 1, \"Note 1\", NOW())") }; Assert.Equal(expectedResult.Count, result.Count); for (int i = 0; i < expectedResult.Count; i++) { Assert.Equal(expectedResult[i].Value, result[i].Value); } }
public void CorrectlyTokenisesDeleteExample(string statement) { var result = SqlLexer.Tokenise(statement, OperationTokens.AllTokens); var expectedResult = new List <SyntaxToken> { OperationTokens.Delete, OperationTokens.From, new SyntaxToken("database2.logs"), OperationTokens.Where, new SyntaxToken("id"), OperationTokens.LessThan, new SyntaxToken("1000") }; Assert.Equal(expectedResult.Count, result.Count); for (int i = 0; i < expectedResult.Count; i++) { Assert.Equal(expectedResult[i].Value, result[i].Value); } }
public void CorrectlyTokenisesSelectExample(string statement) { var result = SqlLexer.Tokenise(statement, OperationTokens.AllTokens); var expectedResult = new List <SyntaxToken> { OperationTokens.Select, new SyntaxToken("id, name, address"), OperationTokens.From, new SyntaxToken("users"), OperationTokens.Where, new SyntaxToken("is_customer"), OperationTokens.Is, new SyntaxToken("NOT NULL"), OperationTokens.OrderBy, new SyntaxToken("created") }; Assert.Equal(expectedResult.Count, result.Count); for (int i = 0; i < expectedResult.Count; i++) { Assert.Equal(expectedResult[i].Value, result[i].Value); } }
public void PassingEmptyStatementReturnsNoTokens(string statement) { var expectedResult = new List <SyntaxToken>(0); Assert.Equal(expectedResult, SqlLexer.Tokenise(statement, OperationTokens.AllTokens)); }
public void PassingEmptyOperationTokensThrowsException() { var operationTokens = new List <OperationToken>().AsReadOnly(); Assert.Throws <ArgumentException>(() => SqlLexer.Tokenise("", operationTokens)); }
public void PassingNullOperationTokensThrowsException() { Assert.Throws <ArgumentException>(() => SqlLexer.Tokenise("", null)); }