SQLParser 4.0.2

SQLParser

This C# library provides a SQL parser and lexer implementation using ANTLR. It allows you to parse SQL queries into an abstract syntax tree (AST) and perform various operations on the parsed queries.

Features

  • Lexical analysis: Tokenizing SQL queries into individual tokens.
  • Syntactic analysis: Parsing SQL queries into an abstract syntax tree.
  • Query manipulation: Modifying and transforming the parsed SQL queries.
  • Query analysis: Extracting metadata and information from SQL queries.

Installation

You can install the library via NuGet:

dotnet add package SQLParser

Usage

To use this library in your C# project, follow these steps:

  1. Add a reference to the SQLParser package in your project.

  2. Import the SQLParser namespace in your code:

    using SQLParser.Parsers.TSql;
    using SQLParser;
    
  3. Create a parser listener class:

    /// <summary>
    /// This is an example of a printer that can be used to parse a statement.
    /// </summary>
    /// <seealso cref="TSqlParserBaseListener" />
    internal class Printer : TSqlParserBaseListener
    {
        /// <summary>
        /// Gets or sets a value indicating whether [statement found].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [statement found]; otherwise, <c>false</c>.
        /// </value>
        public bool StatementFound { get; set; }
    
        /// <summary>
        /// Enter a parse tree produced by <see cref="M:SQLParser.Parsers.TSql.TSqlParser.dml_clause" />.
        /// <para>The default implementation does nothing.</para>
        /// </summary>
        /// <param name="context">The parse tree.</param>
        public override void EnterDml_clause([NotNull] TSqlParser.Dml_clauseContext context)
        {
            // This is a select statement if the select_statement_standalone is not null
            StatementFound |= context.select_statement_standalone() != null;
            base.EnterDml_clause(context);
        }
    }
    
    
  4. Parse the query:

    Parser.Parse("SELECT * FROM Somewhere", ExamplePrinter, Enums.SQLType.TSql);
    

Contributing

Contributions are welcome! If you encounter any bugs, issues, or have feature requests, please create an issue on this repository.

If you want to contribute to the codebase, follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature/bug fix.
  3. Make your changes and write tests if applicable.
  4. Submit a pull request.

Please ensure that your code follows the existing code style and passes the tests before submitting a pull request.

License

This library is released under the Apache 2 License.

Acknowledgments

  • This library was built using ANTLR (version 4).

Showing the top 20 packages that depend on SQLParser.

Packages Downloads
SummerBoot
将SpringBoot的先进理念与C#的简洁优雅合二为一,声明式编程,专注于”做什么”而不是”如何去做”。在更高层面写代码,更关心的是目标,而不是底层算法实现的过程,SummerBoot,致力于让.net开发变得更简单。
2

https://github.com/JaCraig/SQLParser/blob/master/CHANGELOG.md

.NET 8.0

.NET 9.0

Version Downloads Last updated
4.0.2 1 2025/9/19
4.0.1 1 2025/6/7
4.0.0 1 2025/6/8
3.0.22 1 2025/6/9
3.0.21 1 2025/6/9
3.0.20 1 2025/6/8
3.0.19 1 2025/6/9
3.0.18 1 2025/6/9
3.0.17 1 2025/6/9
3.0.16 1 2025/6/9
3.0.15 1 2025/6/9
3.0.14 1 2025/6/9
3.0.13 1 2025/6/9
3.0.12 1 2025/6/9
3.0.11 1 2025/6/9
3.0.10 1 2025/6/9
3.0.9 1 2025/6/9
3.0.8 1 2025/6/8
3.0.7 1 2025/6/8
3.0.6 1 2025/6/9
3.0.5 1 2025/6/9
3.0.4 1 2025/6/8
3.0.3 1 2025/6/8
3.0.1 1 2025/6/8
3.0.0 1 2025/6/9
2.0.15 1 2025/6/8
2.0.14 1 2025/6/8
2.0.13 1 2025/6/8
2.0.11 1 2025/6/8
2.0.10 1 2025/6/9
2.0.9 1 2025/6/8
2.0.7 1 2025/6/8
2.0.6 1 2025/6/8
2.0.5 1 2025/6/8
2.0.4 1 2025/6/8
2.0.3 1 2025/6/8
2.0.2 1 2025/6/8
2.0.1 1 2025/6/8
2.0.0 1 2025/6/8
1.0.3 1 2025/6/8
1.0.2 1 2025/6/8