|
1 | | -# Project |
| 1 | +--- |
| 2 | +ArtifactType: nupkg |
| 3 | +Documentation: URL |
| 4 | +Language: csharp, powershell |
| 5 | +Platform: dotnet |
| 6 | +Stackoverflow: URL |
| 7 | +Tags: ScriptDOM, SqlDOM |
| 8 | +--- |
2 | 9 |
|
3 | | -> This repo has been populated by an initial template to help get you started. Please |
4 | | -> make sure to update the content to build a great experience for community-building. |
| 10 | +# SQL ScriptDOM |
5 | 11 |
|
6 | | -As the maintainer of this project, please make a few updates: |
| 12 | +SQL Script DOM is a .NET library that provides formatting and parsing capabilities to analyze SQL Scripts. It can be used by Powershell and C#. |
7 | 13 |
|
8 | | -- Improving this README.MD file to provide a great experience |
9 | | -- Updating SUPPORT.MD with content about this project's support experience |
10 | | -- Understanding the security reporting process in SECURITY.MD |
11 | | -- Remove this section from the README |
| 14 | +Script DOM is used by DacFX and as an standalone library for client applications. |
12 | 15 |
|
| 16 | +## Getting Started |
| 17 | + |
| 18 | +1. Install Visual Studio 2022 or newer. |
| 19 | + |
| 20 | +2. Download .NET SDKS from https://dotnet.microsoft.com/download/visual-studio-sdks |
| 21 | + - .NET Framework SDK (4.6.2 or higher) |
| 22 | + - .NET 6 SDK (see [global.json](./global.json) for latest version) |
| 23 | +3. Install the [SlnGen](https://microsoft.github.io/slngen/) tool. |
| 24 | + ```cmd |
| 25 | + dotnet tool install --global Microsoft.VisualStudio.SlnGen.Tool |
| 26 | + ``` |
| 27 | +4. Install antlr-2.7.5.exe from https://www.antlr2.org/download.html |
| 28 | +
|
| 29 | +5. Create environment variable named Antlr2Exe pointing to the installation path. |
| 30 | +
|
| 31 | +6. Clone the repository |
| 32 | + ``` |
| 33 | + git clone https://github.com/microsoft/SqlScriptDOM |
| 34 | + ``` |
| 35 | + |
| 36 | +### Building |
| 37 | +
|
| 38 | +Navigate to the root of the source code: |
| 39 | +```cmd |
| 40 | +cd C:\SqlScriptDOM\ |
| 41 | +``` |
| 42 | +Open Visual Studio solution |
| 43 | +```cmd |
| 44 | +slngen |
| 45 | +``` |
| 46 | + |
| 47 | +Restore project dependencies: |
| 48 | +```cmd |
| 49 | +msbuild /t:Restore |
| 50 | +``` |
| 51 | + |
| 52 | +To build: |
| 53 | +```cmd |
| 54 | +msbuild |
| 55 | +``` |
13 | 56 | ## Contributing |
| 57 | +Notes for SQLDOM extensions: |
| 58 | + |
| 59 | +1. Make the changes in |
| 60 | + For changing the DOM classes, modify the XML file (the C# code is generated based on this during the build process) |
| 61 | + $(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\Parser\TSql\Ast.xml |
| 62 | + Change Ast.xml to put the class pieces on their appropriate statements |
| 63 | + |
| 64 | + Note for above: |
| 65 | + 1. The build process is defined in ```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.props``` (Target Name="CreateAST") |
| 66 | + 2. The generated files are dropped in ```$(EnlistmentRoot)\obj\<x64|x86>\<Debug|Release>\SqlScriptDom.csproj\``` |
| 67 | + |
| 68 | + For changing the parser, modify the .g file here: |
| 69 | +```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\Parser\TSql\TSql<#>.g``` where # is the version (ie - 100, 120, 130). This will usually be the latest number if adding new grammar. |
| 70 | + Change the Tsql(xxx).g file to parse the new syntax. |
| 71 | + |
| 72 | + Note for above: |
| 73 | + 1. The build process is defined in ```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.props``` (Target Name="CreateAST") |
| 74 | + 2. The generated files are dropped in ```$(EnlistmentRoot)\obj\x86|x64\Debug|Release\sqlscriptdom.csproj\``` |
| 75 | + |
| 76 | + For changing the ScriptGenerator, modify the appropriate file |
| 77 | + (i.e. Visitor that accepts the modified DOM class) in here |
| 78 | + ```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\ScriptDom\SqlServer\ScriptGenerator``` |
| 79 | + To add a new ScriptGenerator, you need to add the file to ```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.props``` |
| 80 | + Change The visitors SqlScriptGenerator.X to use the new piece from AST.XML |
| 81 | + If you're adding syntax that's Azure-only or Standalone-only, implement appropriate Versioning Visitor for your constructs. |
14 | 82 |
|
15 | | -This project welcomes contributions and suggestions. Most contributions require you to agree to a |
16 | | -Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us |
17 | | -the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. |
| 83 | +2. When adding/removing new files please add/remove an entry to/from ```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.csproj``` |
| 84 | + |
| 85 | +3. To extend the tests do the following: |
| 86 | + a. Baselines# needs to be updated or added with the appropriate .sql file as expected results. |
| 87 | + b. The Only#SyntaxTests.cs needs to be extended or added to specify the appropriate TestScripts script. |
| 88 | + c. Positive tests go in Only#SyntaxTests.cs if adding new grammar. |
| 89 | + d. Create a \TestScripts script that is the input for the test. (This is what is run and is checked against the .sql files in Baselines#) |
| 90 | + e. Negative tests go in ParserErrorsTests.cs. |
| 91 | + |
| 92 | +## Running the tests |
| 93 | + |
| 94 | +You can run tests directly in Visual Studio Text Explorer or by using the ```dotnet test``` command. |
| 95 | + |
| 96 | +Example: To run all priority 0 tests |
| 97 | +```cmd |
| 98 | +dotnet test --filter Priority=0 |
| 99 | +``` |
| 100 | + |
| 101 | +## Built With |
| 102 | +* https://www.antlr.org/ |
| 103 | +* https://www.gnu.org/software/sed/manual/sed.html |
| 104 | + |
| 105 | +## Contributing |
18 | 106 |
|
19 | | -When you submit a pull request, a CLA bot will automatically determine whether you need to provide |
20 | | -a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions |
21 | | -provided by the bot. You will only need to do this once across all repos using our CLA. |
| 107 | +Please read our [CONTRIBUTING.md](CONTRIBUTING.md) which outlines all of our policies, procedures, and requirements for contributing to this project. |
22 | 108 |
|
23 | | -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). |
24 | | -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or |
25 | | -contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. |
| 109 | +## License |
26 | 110 |
|
27 | | -## Trademarks |
| 111 | +Copyright (c) Microsoft Corporation. All rights reserved. |
28 | 112 |
|
29 | | -This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft |
30 | | -trademarks or logos is subject to and must follow |
31 | | -[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). |
32 | | -Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. |
33 | | -Any use of third-party trademarks or logos are subject to those third-party's policies. |
| 113 | +Licensed under the [Source MIT](LICENSE). |
0 commit comments