Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacraig/sqlparser
An SQL Parser/Lexer for C#
https://github.com/jacraig/sqlparser
sql sql-parser tsql tsql-parser
Last synced: 6 days ago
JSON representation
An SQL Parser/Lexer for C#
- Host: GitHub
- URL: https://github.com/jacraig/sqlparser
- Owner: JaCraig
- License: apache-2.0
- Created: 2017-09-13T20:08:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-01-10T20:46:03.000Z (14 days ago)
- Last Synced: 2025-01-11T16:07:29.012Z (13 days ago)
- Topics: sql, sql-parser, tsql, tsql-parser
- Language: C#
- Homepage: https://jacraig.github.io/SQLParser/
- Size: 33.5 MB
- Stars: 109
- Watchers: 7
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
## 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:```csharp
using SQLParser.Parsers.TSql;
using SQLParser;
```3. Create a parser listener class:
```csharp
///
/// This is an example of a printer that can be used to parse a statement.
///
///
internal class Printer : TSqlParserBaseListener
{
///
/// Gets or sets a value indicating whether [statement found].
///
///
/// true if [statement found]; otherwise, false.
///
public bool StatementFound { get; set; }///
/// Enter a parse tree produced by .
/// The default implementation does nothing.
///
/// The parse tree.
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:
```csharp
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](https://github.com/JaCraig/SQLParser/issues) 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](https://github.com/JaCraig/SQLParser/blob/master/LICENSE).
## Acknowledgments
- This library was built using ANTLR (version 4).