├── .github ├── dependabot.yml └── workflows │ ├── codeql-analysis.yml │ └── gradle.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── config ├── checkstyle │ ├── checkstyle.xml │ ├── checkstyle_checks.xml │ ├── google_checks.xml │ ├── sun_checks.xml │ └── suppressions.xml ├── formatter │ └── eclipse-java-google-style.xml ├── pmd │ └── ruleset.xml └── spotbugs │ └── spotBugsExcludeFilter.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── manifest.mf ├── settings.gradle └── src ├── main ├── java │ └── com │ │ └── manticore │ │ └── jsqlformatter │ │ ├── Comment.java │ │ ├── CommentMap.java │ │ └── JSQLFormatter.java └── resources │ ├── antlr │ ├── JavaLexer.g4 │ └── JavaParser.g4 │ ├── graal.txt │ └── rr │ └── xhtml2rst.xsl ├── site └── sphinx │ ├── _static │ ├── ansi-terminal.png │ ├── css │ │ ├── badge_only.css │ │ ├── bower_components │ │ │ └── font-awesome │ │ │ │ └── scss │ │ │ │ └── font-awesome.css │ │ ├── fonts │ │ │ ├── Roboto-Slab-Bold.woff │ │ │ ├── Roboto-Slab-Bold.woff2 │ │ │ ├── Roboto-Slab-Regular.woff │ │ │ ├── Roboto-Slab-Regular.woff2 │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.svg │ │ │ ├── fontawesome-webfont.ttf │ │ │ ├── fontawesome-webfont.woff │ │ │ ├── fontawesome-webfont.woff2 │ │ │ ├── lato-bold-italic.woff │ │ │ ├── lato-bold-italic.woff2 │ │ │ ├── lato-bold.woff │ │ │ ├── lato-bold.woff2 │ │ │ ├── lato-normal-italic.woff │ │ │ ├── lato-normal-italic.woff2 │ │ │ ├── lato-normal.woff │ │ │ └── lato-normal.woff2 │ │ └── theme.css │ ├── manticore_logo.png │ ├── pygments.css │ ├── theme.js │ └── vbox.html │ ├── conf.py │ ├── demo.rst │ ├── index.rst │ ├── install.rst │ ├── resources │ ├── samples.rst │ ├── syntax_snapshot.rst │ └── usage.rst └── test ├── java └── com │ └── manticore │ └── jsqlformatter │ ├── DebugStatementTest.java │ ├── FormatTest.java │ ├── LineCountTest.java │ ├── ParserTest.java │ ├── SimpleFileTest.java │ └── StandardFileTest.java └── resources ├── com └── manticore │ └── jsqlformatter │ ├── simple │ ├── AllTableColumns.sql │ ├── ExplainTest.sql │ ├── Issue0005.sql │ ├── SQLFileTest.sql │ ├── SQLFileTest_1.sql │ ├── SQLFileTest_short.sql │ ├── aggregate.todo │ ├── case.sql │ ├── cast.sql │ ├── duckdb.sql │ ├── fetch.sql │ ├── groupby.sql │ ├── pivot.sql │ └── window.sql │ ├── standard │ ├── BracketQuotationTest.sql │ ├── ExpressionTest.sql │ ├── FormattingOptionsTest.sql │ ├── H2OrderedAggregateTest.sql │ ├── MeanChallenges.sql │ ├── MsSqlServerTest.sql │ ├── MySQLTest.sql │ ├── SeparationAfterTest.sql │ ├── StandardAlterTest.sql │ ├── StandardCommentTest.sql │ ├── StandardCreateIndexTest.sql │ ├── StandardCreateTableTest.sql │ ├── StandardCreateViewTest.sql │ ├── StandardDeleteTest.sql │ ├── StandardInsertTest.sql │ ├── StandardMergeTest.sql │ ├── StandardOffsetLimitTest.sql │ ├── StandardSelectTest.sql │ ├── StandardTruncateTest.sql │ ├── StandardUpdateTest.sql │ └── StandardValueStatementTest.sql │ └── wip │ ├── EmptyStatementTest.sql │ └── Issue0003.sql └── net └── sf └── jsqlparser ├── expression ├── JsonFunctionTest.sql ├── LikeExpressionTest.sql ├── LimitExpressionTest.sql ├── OracleNamedFunctionParameterTest.sql ├── OverlapsConditionTest.sql ├── StringValueTest.sql ├── mysql │ └── MySqlSqlCalcFoundRowsTest.sql └── operators │ └── relational │ └── FullTextSearchExpressionTest.sql └── statement ├── BlockTest.sql ├── DeclareStatementTest.sql ├── DescribeTest.sql ├── ExplainTest.sql ├── IfElseStatementTest.sql ├── KeywordsTest.sql ├── PurgeStatementTest.sql ├── ResetStatementTest.sql ├── SavepointRollbackCommitTest.sql ├── SetStatementTest.sql ├── ShowColumnsStatementTest.sql ├── ShowStatementTest.sql ├── StatementSeparatorTest.sql ├── UnsupportedStatementTest.sql ├── UseStatementTest.sql ├── alter ├── AlterSequenceTest.sql ├── AlterSessionTest.sql ├── AlterSystemTest.sql ├── AlterTest.sql └── RenameTableStatementTest.sql ├── analyze └── AnalyzeTest.sql ├── builder └── JSQLParserFluentModelTests.sql ├── comment └── CommentTest.sql ├── create ├── AlterSequenceTest.sql ├── AlterViewTest.sql ├── CreateFunctionalStatementTest.sql ├── CreateIndexTest.sql ├── CreateSequenceTest.sql ├── CreateTableTest.sql ├── CreateViewTest.sql ├── schema │ └── CreateSchemaTest.sql └── synonym │ └── CreateSynonymTest.sql ├── delete └── DeleteTest.sql ├── drop └── DropTest.sql ├── execute └── ExecuteTest.sql ├── grant └── GrantTest.sql ├── insert └── InsertTest.sql ├── merge └── MergeTest.sql ├── replace └── ReplaceTest.sql ├── select ├── ClickHouseTest.sql ├── HiveTest.sql ├── KSQLTest.sql ├── NestedBracketsPerformanceTest.sql ├── PostgresTest.sql ├── SQLiteTest.sql ├── SelectTest.sql ├── SelectXMLSerializeTest.sql ├── SpecialOracleTest.sql └── WindowFunctionTest.sql ├── show └── ShowTablesStatementTest.sql ├── truncate └── TruncateTest.sql ├── update └── UpdateTest.sql ├── upsert └── UpsertTest.sql └── values └── ValuesTest.sql /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "gradle" # Specify Gradle as the package manager 4 | directory: "/" # Root directory of your project 5 | schedule: 6 | interval: "weekly" # Define how often Dependabot should check for updates 7 | ignore: 8 | - dependency-name: "se.bjurr.gitchangelog.git-changelog-gradle-plugin" 9 | versions: ["*"] # This will ignore all versions for this specific plugin 10 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ main ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ main ] 20 | schedule: 21 | - cron: '29 14 * * 2' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'java' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v3 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v2 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | 52 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 53 | # queries: security-extended,security-and-quality 54 | 55 | 56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 57 | # If this step fails, then you should remove it and run the build manually (see below) 58 | - name: Autobuild 59 | uses: github/codeql-action/autobuild@v2 60 | 61 | # ℹ️ Command-line programs to run using the OS shell. 62 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 63 | 64 | # If the Autobuild fails above, remove it and uncomment the following three lines. 65 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 66 | 67 | # - run: | 68 | # echo "Run, Build Application using script" 69 | # ./location_of_script_within_repo/buildscript.sh 70 | 71 | - name: Perform CodeQL Analysis 72 | uses: github/codeql-action/analyze@v2 73 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle 3 | 4 | name: Gradle CI 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | 12 | permissions: write-all 13 | 14 | jobs: 15 | gradle_check: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@main 19 | with: 20 | fetch-depth: 0 21 | - name: Set up JDK 17 22 | uses: actions/setup-java@main 23 | with: 24 | java-version: '17' 25 | distribution: 'temurin' 26 | - name: Build with Gradle 27 | uses: gradle/actions/setup-gradle@main 28 | - name: Run Gradle Check 29 | run: ./gradlew check 30 | 31 | gradle_publish: 32 | needs: gradle_check 33 | runs-on: ubuntu-latest 34 | steps: 35 | - uses: actions/checkout@main 36 | with: 37 | fetch-depth: 0 38 | - name: Set up JDK 17 39 | uses: actions/setup-java@main 40 | with: 41 | java-version: '17' 42 | distribution: 'temurin' 43 | 44 | - id: install-gradle-properties 45 | name: Install Gradle Properties from Secret 46 | env: 47 | GRADLE_PROPERTIES: ${{ secrets.GRADLE_PROPERTIES }} 48 | shell: bash 49 | run: | 50 | mkdir -p ~/.gradle/ 51 | echo "GRADLE_USER_HOME=${HOME}/.gradle" >> $GITHUB_ENV 52 | echo "${GRADLE_PROPERTIES}" > ~/.gradle/gradle.properties 53 | 54 | # create the ASCII armour: 55 | # gpg -a --export-secret-keys > keyfile.asc 56 | # then store the content of as github secret 57 | - id: install-secret-key 58 | name: Install GPG Key from Secret 59 | run: | 60 | cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import 61 | gpg --export-secret-keys -o /home/runner/.gnupg/secring.gpg 62 | 63 | 64 | - name: Build with Gradle 65 | uses: gradle/actions/setup-gradle@main 66 | - name: Publish with Gradle 67 | run: ./gradlew publish 68 | env: 69 | USERNAME: ${{ github.actor }} 70 | TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | /build/ 26 | /out/ 27 | /dist/ 28 | /target/ 29 | 30 | # Sphinx Theme related stuff, which shall be downloaded separately 31 | /src/site/sphinx/_themes 32 | 33 | # Exclude the Auto-generated Changelog 34 | /src/site/sphinx/changelog.rst 35 | /src/site/sphinx/javadoc.rst 36 | /src/site/sphinx/syntax.rst 37 | 38 | release.properties 39 | pom.xml.releaseBackup 40 | pom.xml.versionsBackup 41 | /nbproject/private/ 42 | /.gradle 43 | /.idea 44 | 45 | /pom.xml 46 | /dependency-reduced-pom.xml 47 | /src/site/sphinx/javadoc_snapshot.rst 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Manticore Projects JSQLFormatter is a SQL Beautifying and Formatting Software. 2 | Copyright (C) ${year} ${name} <${email}> 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License as published 6 | by the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero General Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see . 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # manticore JSQLFormatter 2 | Java SQL Formatter, Beautifier and Pretty Printer. Please visit our [Website](http://manticore-projects.com/JSQLFormatter/index.html) and try the [ONLINE Demo](http://jsqlformatter.manticore-projects.com). 3 | 4 | [![Gradle CI](https://github.com/manticore-projects/jsqlformatter/actions/workflows/gradle.yml/badge.svg)](https://github.com/manticore-projects/jsqlformatter/actions/workflows/gradle.yml) 5 | [![Maven](https://badgen.net/maven/v/maven-central/com.manticore-projects.jsqlformatter/jsqlformatter)](https://mvnrepository.com/artifact/com.manticore-projects.jsqlformatter/jsqlformatter) 6 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/80374649d914462ebd6e5b160a1ebdbb)](https://app.codacy.com/gh/manticore-projects/jsqlformatter/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) 7 | [![Coverage Status](https://coveralls.io/repos/github/manticore-projects/jsqlformatter/badge.svg)](https://coveralls.io/github/manticore-projects/jsqlformatter) 8 | [![License](https://img.shields.io/badge/License-AGPL-blue)](#LICENSE) 9 | [![issues - JSQLFormatter](https://img.shields.io/github/issues/manticore-projects/jsqlformatter)](https://github.com/manticore-projects/jsqlformatter/issues) 10 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) 11 | 12 | ![ANSI Output](./src/site/sphinx/_static/ansi-terminal.png) 13 | 14 | ## Features 15 | * Based on [JSQLParser](https://github.com/JSQLParser/JSqlParser) 16 | * Supports complex SELECT, INSERT INTO, MERGE, UPDATE, DELETE, CREATE, ALTER statements 17 | * RDBMS agnostic and compatible to 18 | * ANSI syntax highlighting 19 | * Formatting Options for Indent Width, Comma Before or After, Upper/Lower/Camel Case spelling 20 | * Import from Java String or StringBuilder, while preserving variables 21 | * Export to Java String, StringBuilder or MessageFormat, while handling parameters 22 | * Command Line Option (CLI) and SQL Inline Options 23 | 24 | ```shell 25 | java -jar JSQLFormatter.jar [-i ] [-o ] [-f | 26 | --ansi | --html] [-t | -2 | -8] [--keywordSpelling ] 27 | [--functionSpelling ] [--objectSpelling ] [--separation 28 | ] [--squareBracketQuotation ] 29 | 30 | -i,--inputFile The input SQL file or folder. 31 | -o,--outputFile The out SQL file for the formatted 32 | statements. 33 | -f,--outputFormat The output-format. 34 | [PLAIN* ANSI HTML RTF] 35 | --ansi Output ANSI annotated text. 36 | --html Output HTML annotated text. 37 | -t,--indent The indent width. 38 | [2 4* 8] 39 | -2 Indent with 2 characters. 40 | -8 Indent with 8 characters. 41 | --keywordSpelling Keyword spelling. 42 | [UPPER*, LOWER, CAMEL, KEEP] 43 | --functionSpelling Function name spelling. 44 | [UPPER, LOWER, CAMEL*, KEEP] 45 | --objectSpelling Object name spelling. 46 | [UPPER, LOWER*, CAMEL, KEEP] 47 | --separation Position of the field separator. 48 | [BEFORE*, AFTER] 49 | --squareBracketQuotation Position of the field separator. 50 | [AUTO*, YES, NO] 51 | ``` 52 | 53 | 54 | * simple usage of the Java library 55 | 56 | ```java 57 | import com.manticore.jsqlformatter.JSQLFormatter; 58 | ... 59 | String formattedSql = JSQLFormatter.format("SELECT * FROM table1") 60 | ``` 61 | 62 | with Maven Artifact: 63 | 64 | ```xml 65 | 66 | com.manticore-projects.jsqlformatter 67 | jsqlformatter 68 | 4.8.0 69 | 70 | ``` 71 | 72 | 73 | ## Samples 74 | 75 | ### Inline Formatting Options 76 | ```sql 77 | -- @JSQLFormatter(indentWidth=8, keywordSpelling=UPPER, functionSpelling=CAMEL, objectSpelling=LOWER, separation=BEFORE) 78 | UPDATE cfe.calendar 79 | SET year_offset = ? /* year offset */ 80 | , settlement_shift = To_Char( ? ) /* settlement shift */ 81 | , friday_is_holiday = ? /* friday is a holiday */ 82 | , saturday_is_holiday = ? /* saturday is a holiday */ 83 | , sunday_is_holiday = ? /* sunday is a holiday */ 84 | WHERE id_calendar = ? 85 | ; 86 | 87 | -- @JSQLFormatter(indentWidth=2, keywordSpelling=LOWER, functionSpelling=KEEP, objectSpelling=UPPER, separation=AFTER) 88 | update CFE.CALENDAR 89 | set YEAR_OFFSET = ? /* year offset */, 90 | SETTLEMENT_SHIFT = to_char( ? ) /* settlement shift */, 91 | FRIDAY_IS_HOLIDAY = ? /* friday is a holiday */, 92 | SATURDAY_IS_HOLIDAY = ? /* saturday is a holiday */, 93 | SUNDAY_IS_HOLIDAY = ? /* sunday is a holiday */ 94 | where ID_CALENDAR = ? 95 | ; 96 | ``` 97 | 98 | ### Complex Comments 99 | ```sql 100 | -- UPDATE CALENDAR 101 | UPDATE cfe.calendar 102 | SET year_offset = ? /* year offset */ 103 | , settlement_shift = ? /* settlement shift */ 104 | , friday_is_holiday = ? /* friday is a holiday */ 105 | , saturday_is_holiday = ? /* saturday is a holiday */ 106 | , sunday_is_holiday = ? /* sunday is a holiday */ 107 | WHERE id_calendar = ? 108 | ; 109 | 110 | -- BOTH CLAUSES PRESENT 'with a string' AND "a field" 111 | MERGE /*+ PARALLEL */ INTO test1 /*the target table*/ a 112 | USING all_objects /*the source table*/ 113 | ON ( /*joins in()!*/ a.object_id = b.object_id ) 114 | -- INSERT CLAUSE 115 | WHEN /*comments between keywords!*/ NOT MATCHED THEN 116 | INSERT ( object_id /*ID Column*/ 117 | , status /*Status Column*/ ) 118 | VALUES ( b.object_id 119 | , b.status ) 120 | /* UPDATE CLAUSE 121 | WITH A WHERE CONDITION */ 122 | WHEN MATCHED THEN /* Lets rock */ 123 | UPDATE SET a.status = '/*this is no comment!*/ and -- this ain''t either' 124 | WHERE b."--status" != 'VALID' 125 | ; 126 | ``` 127 | 128 | [More Samples](http://manticore-projects.com/JSQLFormatter/samples.html) 129 | -------------------------------------------------------------------------------- /config/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /config/checkstyle/sun_checks.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 33 | 34 | 35 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | -------------------------------------------------------------------------------- /config/pmd/ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | The default ruleset used by the Maven PMD Plugin, when no other ruleset is specified. 24 | It contains the rules of the old (pre PMD 6.0.0) rulesets java-basic, java-empty, java-imports, 25 | java-unnecessary, java-unusedcode. 26 | 27 | This ruleset might be used as a starting point for an own customized ruleset [0]. 28 | 29 | [0] https://pmd.github.io/latest/pmd_userdocs_making_rulesets.html 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /config/spotbugs/spotBugsExcludeFilter.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Specifies the JVM arguments used for the daemon process. 2 | # The setting is particularly useful for tweaking memory settings. 3 | org.gradle.jvmargs=-Xmx1G -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError 4 | 5 | org.gradle.caching=true 6 | 7 | # Modularise your project and enable parallel build 8 | org.gradle.parallel=true 9 | 10 | # Enable configure on demand. 11 | org.gradle.configureondemand=true 12 | 13 | # see https://docs.gradle.org/current/userguide/upgrading_version_8.html#xml_parsing_now_requires_recent_parsers 14 | systemProp.javax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl 15 | systemProp.javax.xml.transform.TransformerFactory=com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl 16 | systemProp.javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl 17 | 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | X-COMMENT: Main-Class will be added automatically by build 3 | 4 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | */ 4 | 5 | rootProject.name = 'JSQLFormatter' 6 | -------------------------------------------------------------------------------- /src/main/java/com/manticore/jsqlformatter/Comment.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Manticore Projects JSQLFormatter is a SQL Beautifying and Formatting Software. 3 | * Copyright (C) 2024 Andreas Reichel 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package com.manticore.jsqlformatter; 19 | 20 | /** @author are */ 21 | public class Comment implements Comparable { 22 | protected boolean newLine; 23 | protected boolean extraNewLine; 24 | protected int absolutePosition; 25 | protected int relativePosition; 26 | protected String text; 27 | 28 | public Comment(int absolutePosition, String text) { 29 | this.absolutePosition = absolutePosition; 30 | this.text = text; 31 | } 32 | 33 | @Override 34 | public int compareTo(Comment o) { 35 | return Integer.compare(absolutePosition, o.absolutePosition); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return text; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/resources/antlr/JavaLexer.g4: -------------------------------------------------------------------------------- 1 | /* 2 | [The "BSD licence"] 3 | Copyright (c) 2013 Terence Parr, Sam Harwell 4 | Copyright (c) 2017 Ivan Kochurkin (upgrade to Java 8) 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 3. The name of the author may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | lexer grammar JavaLexer; 31 | 32 | // Keywords 33 | 34 | ABSTRACT: 'abstract'; 35 | ASSERT: 'assert'; 36 | BOOLEAN: 'boolean'; 37 | BREAK: 'break'; 38 | BYTE: 'byte'; 39 | CASE: 'case'; 40 | CATCH: 'catch'; 41 | CHAR: 'char'; 42 | CLASS: 'class'; 43 | CONST: 'const'; 44 | CONTINUE: 'continue'; 45 | DEFAULT: 'default'; 46 | DO: 'do'; 47 | DOUBLE: 'double'; 48 | ELSE: 'else'; 49 | ENUM: 'enum'; 50 | EXTENDS: 'extends'; 51 | FINAL: 'final'; 52 | FINALLY: 'finally'; 53 | FLOAT: 'float'; 54 | FOR: 'for'; 55 | IF: 'if'; 56 | GOTO: 'goto'; 57 | IMPLEMENTS: 'implements'; 58 | IMPORT: 'import'; 59 | INSTANCEOF: 'instanceof'; 60 | INT: 'int'; 61 | INTERFACE: 'interface'; 62 | LONG: 'long'; 63 | NATIVE: 'native'; 64 | NEW: 'new'; 65 | PACKAGE: 'package'; 66 | PRIVATE: 'private'; 67 | PROTECTED: 'protected'; 68 | PUBLIC: 'public'; 69 | RETURN: 'return'; 70 | SHORT: 'short'; 71 | STATIC: 'static'; 72 | STRICTFP: 'strictfp'; 73 | SUPER: 'super'; 74 | SWITCH: 'switch'; 75 | SYNCHRONIZED: 'synchronized'; 76 | THIS: 'this'; 77 | THROW: 'throw'; 78 | THROWS: 'throws'; 79 | TRANSIENT: 'transient'; 80 | TRY: 'try'; 81 | VOID: 'void'; 82 | VOLATILE: 'volatile'; 83 | WHILE: 'while'; 84 | 85 | // Literals 86 | 87 | DECIMAL_LITERAL: ('0' | [1-9] (Digits? | '_'+ Digits)) [lL]?; 88 | HEX_LITERAL: '0' [xX] [0-9a-fA-F] ([0-9a-fA-F_]* [0-9a-fA-F])? [lL]?; 89 | OCT_LITERAL: '0' '_'* [0-7] ([0-7_]* [0-7])? [lL]?; 90 | BINARY_LITERAL: '0' [bB] [01] ([01_]* [01])? [lL]?; 91 | 92 | FLOAT_LITERAL: (Digits '.' Digits? | '.' Digits) ExponentPart? [fFdD]? 93 | | Digits (ExponentPart [fFdD]? | [fFdD]) 94 | ; 95 | 96 | HEX_FLOAT_LITERAL: '0' [xX] (HexDigits '.'? | HexDigits? '.' HexDigits) [pP] [+-]? Digits [fFdD]?; 97 | 98 | BOOL_LITERAL: 'true' 99 | | 'false' 100 | ; 101 | 102 | CHAR_LITERAL: '\'' (~['\\\r\n] | EscapeSequence) '\''; 103 | 104 | STRING_LITERAL: '"' (~["\\\r\n] | EscapeSequence)* '"'; 105 | 106 | NULL_LITERAL: 'null'; 107 | 108 | // Separators 109 | 110 | LPAREN: '('; 111 | RPAREN: ')'; 112 | LBRACE: '{'; 113 | RBRACE: '}'; 114 | LBRACK: '['; 115 | RBRACK: ']'; 116 | SEMI: ';'; 117 | COMMA: ','; 118 | DOT: '.'; 119 | 120 | // Operators 121 | 122 | ASSIGN: '='; 123 | GT: '>'; 124 | LT: '<'; 125 | BANG: '!'; 126 | TILDE: '~'; 127 | QUESTION: '?'; 128 | COLON: ':'; 129 | EQUAL: '=='; 130 | LE: '<='; 131 | GE: '>='; 132 | NOTEQUAL: '!='; 133 | AND: '&&'; 134 | OR: '||'; 135 | INC: '++'; 136 | DEC: '--'; 137 | ADD: '+'; 138 | SUB: '-'; 139 | MUL: '*'; 140 | DIV: '/'; 141 | BITAND: '&'; 142 | BITOR: '|'; 143 | CARET: '^'; 144 | MOD: '%'; 145 | 146 | ADD_ASSIGN: '+='; 147 | SUB_ASSIGN: '-='; 148 | MUL_ASSIGN: '*='; 149 | DIV_ASSIGN: '/='; 150 | AND_ASSIGN: '&='; 151 | OR_ASSIGN: '|='; 152 | XOR_ASSIGN: '^='; 153 | MOD_ASSIGN: '%='; 154 | LSHIFT_ASSIGN: '<<='; 155 | RSHIFT_ASSIGN: '>>='; 156 | URSHIFT_ASSIGN: '>>>='; 157 | 158 | // Java 8 tokens 159 | 160 | ARROW: '->'; 161 | COLONCOLON: '::'; 162 | 163 | // Additional symbols not defined in the lexical specification 164 | 165 | AT: '@'; 166 | ELLIPSIS: '...'; 167 | 168 | // Whitespace and comments 169 | 170 | WS: [ \t\r\n\u000C]+ -> channel(HIDDEN); 171 | COMMENT: '/*' .*? '*/' -> channel(HIDDEN); 172 | LINE_COMMENT: '//' ~[\r\n]* -> channel(HIDDEN); 173 | 174 | // Identifiers 175 | 176 | IDENTIFIER: Letter LetterOrDigit*; 177 | 178 | // Fragment rules 179 | 180 | fragment ExponentPart 181 | : [eE] [+-]? Digits 182 | ; 183 | 184 | fragment EscapeSequence 185 | : '\\' [btnfr"'\\] 186 | | '\\' ([0-3]? [0-7])? [0-7] 187 | | '\\' 'u'+ HexDigit HexDigit HexDigit HexDigit 188 | ; 189 | 190 | fragment HexDigits 191 | : HexDigit ((HexDigit | '_')* HexDigit)? 192 | ; 193 | 194 | fragment HexDigit 195 | : [0-9a-fA-F] 196 | ; 197 | 198 | fragment Digits 199 | : [0-9] ([0-9_]* [0-9])? 200 | ; 201 | 202 | fragment LetterOrDigit 203 | : Letter 204 | | [0-9] 205 | ; 206 | 207 | fragment Letter 208 | : [a-zA-Z$_] // these are the "java letters" below 0x7F 209 | | ~[\u0000-\u007F\uD800-\uDBFF] // covers all characters above 0x7F which are not a surrogate 210 | | [\uD800-\uDBFF] [\uDC00-\uDFFF] // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF 211 | ; 212 | -------------------------------------------------------------------------------- /src/main/resources/graal.txt: -------------------------------------------------------------------------------- 1 | rm dist/lib/polyglot-native-api.jar 2 | 3 | /usr/lib/jvm/java-11-graalvm/bin/native-image --no-server --no-fallback -H:+StaticExecutableWithDynamicLibC \ 4 | -cp dist/JSQLFormatter.jar:dist/lib/'*.jar' \ 5 | -H:Name=dist/JSQLFormatter \ 6 | com.manticore.jsqlformatter.JSQLFormatter 7 | 8 | /usr/lib/jvm/java-11-graalvm/bin/native-image --no-server --no-fallback -H:+StaticExecutableWithDynamicLibC \ 9 | -cp JSQLFormatterUI.jar \ 10 | -H:Name=dist/JSQLFormatterUI \ 11 | com.manticore.jsqlformatter.JSQLFormatterUI 12 | 13 | upx --lzma dist/JSQLFormatter 14 | 15 | /usr/lib/jvm/java-11-graalvm/bin/native-image --no-server --no-fallback -cp dist/JSQLFormatter.jar:dist/lib/jsqlparser-4.1-SNAPSHOT.jar --shared -H:Name=dist/libSQLFormatter --native-compiler-options='-Os' --native-compiler-options='-fno-inline' --native-compiler-options='-fno-exceptions' --native-compiler-options='-flto' --native-compiler-options='-Wl,--gc-sections' --native-image-info 16 | 17 | C:\Users\andre\Documents\graalvm-ce-java11-21.0.0.2\bin\native-image.cmd --no-server --no-fallback -cp dist/JSQLFormatter.jar;dist/lib/jsqlparser-4.1-SNAPSHOT.jar -H:+StaticExecutableWithDynamicLibC -H:Name=dist\JSQLFormatter com.manticore.jsqlformatter.JSQLFormatter 18 | C:\Users\andre\Documents\upx.exe --lzma dist\JSQLFormatter.exe 19 | 20 | export LD_LIBRARY_PATH=. 21 | clang -I. -L. -o sqlformatter1 sqlformatter.c libSQLFormatter.so 22 | 23 | 24 | 25 | Activate support globally by default, persistently, via the registry, as detailed in this SU answer. 26 | 27 | In short: In registry key [HKEY_CURRENT_USER\Console], create or set the VirtualTerminalLevel DWORD value to 1 28 | From PowerShell, you can do this programmatically as follows: 29 | Set-ItemProperty HKCU:\Console VirtualTerminalLevel -Type DWORD 1 30 | From cmd.exe (also works from PowerShell): 31 | reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1 32 | Open a new console window for changes to take effect. 33 | 34 | -------------------------------------------------------------------------------- /src/main/resources/rr/xhtml2rst.xsl: -------------------------------------------------------------------------------- 1 | 2 | 8 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ******************** 22 | Supported SQL Syntax 23 | ******************** 24 | 25 | The EBNF and Railroad Diagrams for the supported SQL Syntax. 26 | Kindly provided by Gunther Rademacher. 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | ================================================= 35 | 36 | 37 | 38 | ================================================= 39 | 40 | 41 | 42 | 43 | .. raw:: html 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/site/sphinx/_static/ansi-terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/ansi-terminal.png -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before { 2 | -webkit-font-smoothing: antialiased; } 3 | 4 | .clearfix { 5 | *zoom: 1; } 6 | .clearfix:before, .clearfix:after { 7 | display: table; 8 | content: ""; } 9 | .clearfix:after { 10 | clear: both; } 11 | 12 | @font-face { 13 | font-family: FontAwesome; 14 | font-weight: normal; 15 | font-style: normal; 16 | src: url("../bower_components/font-awesome/fonts/fontawesome-webfont.eot"); 17 | src: url("../bower_components/font-awesome/fonts/fontawesome-webfont.eot?#iefix") format("embedded-opentype"), url("../bower_components/font-awesome/fonts/fontawesome-webfont.woff") format("woff"), url("../bower_components/font-awesome/fonts/fontawesome-webfont.ttf") format("truetype"), url("../bower_components/font-awesome/fonts/fontawesome-webfont.svg#FontAwesome") format("svg"); } 18 | 19 | .fa:before { 20 | display: inline-block; 21 | font-family: FontAwesome; 22 | font-style: normal; 23 | font-weight: normal; 24 | line-height: 1; 25 | text-decoration: inherit; } 26 | 27 | a .fa { 28 | display: inline-block; 29 | text-decoration: inherit; } 30 | 31 | li .fa { 32 | display: inline-block; } 33 | 34 | li .fa-large:before, 35 | li .fa-large:before { 36 | /* 1.5 increased font size for fa-large * 1.25 width */ 37 | width: 1.875em; } 38 | 39 | ul.fas { 40 | list-style-type: none; 41 | margin-left: 2em; 42 | text-indent: -0.8em; } 43 | ul.fas li .fa { 44 | width: 0.8em; } 45 | ul.fas li .fa-large:before, 46 | ul.fas li .fa-large:before { 47 | /* 1.5 increased font size for fa-large * 1.25 width */ 48 | vertical-align: baseline; } 49 | 50 | .fa-book:before { 51 | content: "\f02d"; } 52 | 53 | .icon-book:before { 54 | content: "\f02d"; } 55 | 56 | .fa-caret-down:before { 57 | content: "\f0d7"; } 58 | 59 | .icon-caret-down:before { 60 | content: "\f0d7"; } 61 | 62 | .fa-caret-up:before { 63 | content: "\f0d8"; } 64 | 65 | .icon-caret-up:before { 66 | content: "\f0d8"; } 67 | 68 | .fa-caret-left:before { 69 | content: "\f0d9"; } 70 | 71 | .icon-caret-left:before { 72 | content: "\f0d9"; } 73 | 74 | .fa-caret-right:before { 75 | content: "\f0da"; } 76 | 77 | .icon-caret-right:before { 78 | content: "\f0da"; } 79 | 80 | .rst-versions { 81 | position: fixed; 82 | bottom: 0; 83 | left: 0; 84 | width: 23rem; 85 | color: #fcfcfc; 86 | background: #1f1d1d; 87 | font-family: "Roboto Slab", serif; 88 | z-index: 400; } 89 | .rst-versions a { 90 | color: #ff420e; 91 | text-decoration: none; } 92 | .rst-versions .rst-badge-small { 93 | display: none; } 94 | .rst-versions .rst-current-version { 95 | padding: 12px; 96 | background-color: #272525; 97 | display: block; 98 | text-align: right; 99 | font-size: 90%; 100 | cursor: pointer; 101 | color: #27AE60; 102 | *zoom: 1; } 103 | .rst-versions .rst-current-version:before, .rst-versions .rst-current-version:after { 104 | display: table; 105 | content: ""; } 106 | .rst-versions .rst-current-version:after { 107 | clear: both; } 108 | .rst-versions .rst-current-version .fa { 109 | color: #fcfcfc; } 110 | .rst-versions .rst-current-version .fa-book { 111 | float: left; } 112 | .rst-versions .rst-current-version .icon-book { 113 | float: left; } 114 | .rst-versions .rst-current-version.rst-out-of-date { 115 | background-color: #E74C3C; 116 | color: #fff; } 117 | .rst-versions .rst-current-version.rst-active-old-version { 118 | background-color: #F1C40F; 119 | color: #000; } 120 | .rst-versions.shift-up { 121 | height: auto; 122 | max-height: 100%; 123 | overflow-y: scroll; } 124 | .rst-versions.shift-up .rst-other-versions { 125 | display: block; } 126 | .rst-versions .rst-other-versions { 127 | font-size: 90%; 128 | padding: 12px; 129 | color: gray; 130 | display: none; } 131 | .rst-versions .rst-other-versions hr { 132 | display: block; 133 | height: 1px; 134 | border: 0; 135 | margin: 20px 0; 136 | padding: 0; 137 | border-top: solid 1px #413d3d; } 138 | .rst-versions .rst-other-versions dd { 139 | display: inline-block; 140 | margin: 0; } 141 | .rst-versions .rst-other-versions dd a { 142 | display: inline-block; 143 | padding: 6px; 144 | color: #fcfcfc; } 145 | .rst-versions.rst-badge { 146 | width: auto; 147 | bottom: 20px; 148 | right: 20px; 149 | left: auto; 150 | border: none; 151 | max-width: 23rem; 152 | max-height: 90%; } 153 | .rst-versions.rst-badge .icon-book { 154 | float: none; 155 | line-height: 30px; } 156 | .rst-versions.rst-badge .fa-book { 157 | float: none; 158 | line-height: 30px; } 159 | .rst-versions.rst-badge.shift-up .rst-current-version { 160 | text-align: right; } 161 | .rst-versions.rst-badge.shift-up .rst-current-version .fa-book { 162 | float: left; } 163 | .rst-versions.rst-badge.shift-up .rst-current-version .icon-book { 164 | float: left; } 165 | .rst-versions.rst-badge > .rst-current-version { 166 | width: auto; 167 | height: 30px; 168 | line-height: 30px; 169 | padding: 0 6px; 170 | display: block; 171 | text-align: center; } 172 | 173 | @media screen and (max-width: 768px) { 174 | .rst-versions { 175 | width: 85%; 176 | display: none; } 177 | .rst-versions.shift { 178 | display: block; } } 179 | -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/Roboto-Slab-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/Roboto-Slab-Bold.woff -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/Roboto-Slab-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/Roboto-Slab-Bold.woff2 -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/Roboto-Slab-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/Roboto-Slab-Regular.woff -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/Roboto-Slab-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/Roboto-Slab-Regular.woff2 -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/lato-bold-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/lato-bold-italic.woff -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/lato-bold-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/lato-bold-italic.woff2 -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/lato-bold.woff -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/lato-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/lato-bold.woff2 -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/lato-normal-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/lato-normal-italic.woff -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/lato-normal-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/lato-normal-italic.woff2 -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/lato-normal.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/lato-normal.woff -------------------------------------------------------------------------------- /src/site/sphinx/_static/css/fonts/lato-normal.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/css/fonts/lato-normal.woff2 -------------------------------------------------------------------------------- /src/site/sphinx/_static/manticore_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manticore-projects/jsqlformatter/f4654944c3a02ea74af3541498f7c5d65c7fb9f1/src/site/sphinx/_static/manticore_logo.png -------------------------------------------------------------------------------- /src/site/sphinx/_static/pygments.css: -------------------------------------------------------------------------------- 1 | pre { line-height: 125%; } 2 | td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 3 | span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } 4 | td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 5 | span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } 6 | .highlight .hll { background-color: #ffffcc } 7 | .highlight { background: #fff; } 8 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 9 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 10 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 11 | .highlight .o { color: #666666 } /* Operator */ 12 | .highlight .ch { color: #408090; font-style: italic } /* Comment.Hashbang */ 13 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 14 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 15 | .highlight .cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */ 16 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 17 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 18 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 19 | .highlight .ge { font-style: italic } /* Generic.Emph */ 20 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 21 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 22 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 23 | .highlight .go { color: #333333 } /* Generic.Output */ 24 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 25 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 26 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 27 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 28 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 29 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 30 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 31 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 32 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 33 | .highlight .kt { color: #902000 } /* Keyword.Type */ 34 | .highlight .m { color: #208050 } /* Literal.Number */ 35 | .highlight .s { color: #4070a0 } /* Literal.String */ 36 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 37 | .highlight .nb { color: #007020 } /* Name.Builtin */ 38 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 39 | .highlight .no { color: #60add5 } /* Name.Constant */ 40 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 41 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 42 | .highlight .ne { color: #007020 } /* Name.Exception */ 43 | .highlight .nf { color: #06287e } /* Name.Function */ 44 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 45 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 46 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 47 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 48 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 49 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 50 | .highlight .mb { color: #208050 } /* Literal.Number.Bin */ 51 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 52 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 53 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 54 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 55 | .highlight .sa { color: #4070a0 } /* Literal.String.Affix */ 56 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 57 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 58 | .highlight .dl { color: #4070a0 } /* Literal.String.Delimiter */ 59 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 60 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 61 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 62 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 63 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 64 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 65 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 66 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 67 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 68 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 69 | .highlight .fm { color: #06287e } /* Name.Function.Magic */ 70 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 71 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 72 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 73 | .highlight .vm { color: #bb60d5 } /* Name.Variable.Magic */ 74 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /src/site/sphinx/_static/vbox.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Webswing 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 | 21 |
22 |
23 | 24 | 45 | 46 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /src/site/sphinx/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # General options 4 | needs_sphinx = '1.0' 5 | add_function_parentheses = True 6 | 7 | extensions = ['myst_parser', 'sphinx.ext.autodoc', 'sphinx.ext.autosectionlabel', 'sphinx.ext.extlinks', 'sphinx-prompt', 'sphinx_substitution_extensions', 'sphinx_issues', 'sphinx_tabs.tabs', 'pygments.sphinxext', ] 8 | 9 | issues_github_path = "JSQLParser/JSqlParser" 10 | 11 | source_encoding = 'utf-8-sig' 12 | pygments_style = 'friendly' 13 | show_sphinx = False 14 | master_doc = 'index' 15 | exclude_patterns = ['_themes', '_static/css'] 16 | 17 | 18 | # HTML options 19 | html_theme = "manticore_sphinx_theme" 20 | html_theme_path = ["_themes"] 21 | html_short_title = "JSQLFormatter" 22 | htmlhelp_basename = "JSQLFormatter" + '-doc' 23 | html_use_index = True 24 | html_show_sourcelink = False 25 | html_static_path = ['_static'] 26 | html_logo = '_static/manticore_logo.png' 27 | html_css_files = ["css/theme.css"] 28 | 29 | 30 | html_theme_options = { 31 | 'canonical_url': '', 32 | 'analytics_id': 'UA-XXXXXXX-1', 33 | 'style_external_links': True, 34 | 'collapse_navigation': True, 35 | 'sticky_navigation': True, 36 | 'navigation_depth': 4, 37 | 'includehidden': True, 38 | 'titles_only': False, 39 | } 40 | 41 | 42 | html_context = { 43 | 'landing_page': { 44 | 'menu': [ 45 | {'title': 'Online Demo', 'url': 'http://217.160.215.75:8080/jsqlformatter/demo.html'}, 46 | {'title': 'Issue Tracker', 'url': 'https://github.com/JSQLParser/JSqlParser/issues'} 47 | ] 48 | } 49 | } 50 | 51 | html_sidebars = { 52 | '**': [ 53 | 'about.html', 54 | 'navigation.html', 55 | 'relations.html', 56 | 'searchbox.html', 57 | 'donate.html', 58 | ] 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/site/sphinx/demo.rst: -------------------------------------------------------------------------------- 1 | **************** 2 | Interactive Demo 3 | **************** 4 | 5 | Using latest JSQLParser version: |JSQLPARSER_SNAPSHOT_VERSION_LINK| 6 | 7 | .. raw:: html 8 | 9 | 10 | 16 | -------------------------------------------------------------------------------- /src/site/sphinx/index.rst: -------------------------------------------------------------------------------- 1 | .. meta:: 2 | :description: Java Software Library for formatting and pretty printing SQL Statements 3 | :keywords: java sql statement format formatter pretty printing 4 | 5 | *************************** 6 | Java SQL Formatting Library 7 | *************************** 8 | 9 | .. image:: https://github.com/manticore-projects/jsqlformatter/actions/workflows/gradle.yml/badge.svg 10 | :alt: Gradle CI 11 | :target: https://github.com/manticore-projects/jsqlformatter/actions/workflows/gradle.yml 12 | 13 | .. image:: https://badgen.net/maven/v/maven-central/com.manticore-projects.jsqlformatter/jsqlformatter 14 | :alt: Maven 15 | :target: https://mvnrepository.com/artifact/com.manticore-projects.jsqlformatter/jsqlformatter 16 | .. image:: https://app.codacy.com/project/badge/Grade/80374649d914462ebd6e5b160a1ebdbb 17 | :alt: Codacy Badge 18 | :target: https://app.codacy.com/gh/manticore-projects/jsqlformatter/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade 19 | 20 | .. image:: https://coveralls.io/repos/github/manticore-projects/jsqlformatter/badge.svg 21 | :alt: Coverage Status 22 | :target: https://coveralls.io/github/manticore-projects/jsqlformatter 23 | 24 | .. image:: https://img.shields.io/badge/License-AGPL-blue 25 | :alt: License 26 | :target: https://www.gnu.org/licenses/agpl-3.0.en.html#license-text 27 | 28 | .. image:: https://img.shields.io/github/issues/manticore-projects/jsqlformatter 29 | :alt: issues - JSQLFormatter 30 | :target: https://github.com/manticore-projects/jsqlformatter/issues 31 | 32 | .. image:: https://img.shields.io/badge/PRs-welcome-brightgreen.svg 33 | :alt: PRs Welcome 34 | :target: http://makeapullrequest.com 35 | 36 | .. toctree:: 37 | :caption: Documentation 38 | :maxdepth: 2 39 | :hidden: 40 | 41 | install 42 | usage 43 | Syntax 44 | Java API 45 | samples 46 | demo 47 | 48 | 49 | .. toctree:: 50 | :maxdepth: 1 51 | :hidden: 52 | 53 | changelog 54 | 55 | .. sidebar:: Ansi output 56 | 57 | .. image:: _static/ansi-terminal.png 58 | 59 | Format SQL files in the Terminal Console. 60 | 61 | Platform independent SQL Formatter, Beautifier and Pretty Printer by Manticore Projects. 62 | 63 | Latest stable release: |JSQLFORMATTER_STABLE_VERSION_LINK| 64 | 65 | Development version: |JSQLFORMATTER_SNAPSHOT_VERSION_LINK| 66 | 67 | `GitHub Repository `_ 68 | 69 | 70 | ......... 71 | Features 72 | ......... 73 | * based on `JSQLParser `_ 74 | * supports complex ``SELECT``, ``INSERT INTO``, ``MERGE``, ``UPDATE``, ``DELETE``, ``CREATE``, ``ALTER`` statements 75 | * Syntax highlighting (ANSI, HTML, RTF) 76 | * Command Line Options (CLI) and SQL Inline Formatting Options 77 | 78 | * Indent Width 79 | * Comma Before or After 80 | * Upper/Lower/Camel-Case Spelling of Keywords, Functions and Object Names 81 | 82 | * Import from Java String or StringBuilder Code preserving variables 83 | * Export to Java String, StringBuilder or MessageFormat handling variables 84 | 85 | ......... 86 | Platform 87 | ......... 88 | * Java Library (JAR) 89 | * Native Static Binary or Dynamic Library for Windows, Linux or MacOS 90 | * Netbeans Plugin (Other platforms such as Eclipse, JEdit, Squirrel SQL, DBeaver coming soon) 91 | -------------------------------------------------------------------------------- /src/site/sphinx/install.rst: -------------------------------------------------------------------------------- 1 | ***************************** 2 | Installation of JSQLFormatter 3 | ***************************** 4 | 5 | Git 6 | =================== 7 | .. code:: Bash 8 | 9 | git clone https://github.com/manticore-projects/jsqlformatter.git 10 | cd jsqlformatter 11 | ./gradlew publishToMavenLocal 12 | 13 | 14 | Maven Repo 15 | =================== 16 | 17 | .. tab:: Maven Release 18 | 19 | .. code-block:: xml 20 | :substitutions: 21 | 22 | 23 | com.manticore-projects.jsqlformatter 24 | jsqlformatter 25 | |JSQLFORMATTER_VERSION| 26 | 27 | 28 | .. tab:: Maven Snapshot 29 | 30 | .. code-block:: xml 31 | :substitutions: 32 | 33 | 34 | 35 | jsqlformatter-snapshots 36 | 37 | true 38 | 39 | https://s01.oss.sonatype.org/content/repositories/snapshots/ 40 | 41 | 42 | 43 | com.manticore-projects.jsqlformatter 44 | jsqlformatter 45 | |JSQLFORMATTER_SNAPSHOT_VERSION| 46 | 47 | 48 | .. tab:: Gradle Stable 49 | 50 | .. code-block:: groovy 51 | :substitutions: 52 | 53 | repositories { 54 | mavenCentral() 55 | } 56 | 57 | dependencies { 58 | implementation 'com.manticore-projects.jsqlformatter:jsqlformatter:|JSQLFORMATTER_VERSION|' 59 | } 60 | 61 | .. tab:: Gradle Snapshot 62 | 63 | .. code-block:: groovy 64 | :substitutions: 65 | 66 | repositories { 67 | maven { 68 | url = uri('https://s01.oss.sonatype.org/content/repositories/snapshots/') 69 | } 70 | } 71 | 72 | dependencies { 73 | implementation 'com.manticore-projects.jsqlformatter:jsqlformatter:|JSQLFORMATTER_SNAPSHOT_VERSION|' 74 | } 75 | 76 | 77 | 78 | Download 79 | =================== 80 | 81 | Static Binaries 82 | --------------------------------------------- 83 | 84 | .. list-table:: Static Binaries Direct Download Links 85 | :widths: 35 50 15 86 | :header-rows: 1 87 | 88 | * - Operating System 89 | - File 90 | - Size 91 | * - Java Stable Release 92 | - |JSQLFORMATTER_STABLE_VERSION_LINK| 93 | - (80 kB) 94 | * - Java Development Snapshot 95 | - |JSQLFORMATTER_SNAPSHOT_VERSION_LINK| 96 | - (80 kB) 97 | * - Java Fat JAR Devel. Snapshot 98 | - |JSQLFORMATTER_FAT_SNAPSHOT_VERSION_LINK| 99 | - (15 MB) 100 | 101 | .. note:: 102 | 103 | On MacOS, grant an exception for a blocked app by clicking the Open Anyway button in the General pane of Security & Privacy preferences. 104 | 105 | Native Dynamic Libraries 106 | --------------------------------------------- 107 | 108 | Coming soon. 109 | -------------------------------------------------------------------------------- /src/site/sphinx/resources: -------------------------------------------------------------------------------- 1 | ../../test/resources/com/manticore/jsqlformatter/ -------------------------------------------------------------------------------- /src/site/sphinx/samples.rst: -------------------------------------------------------------------------------- 1 | ********* 2 | Samples 3 | ********* 4 | 5 | Create 6 | -------------- 7 | 8 | .. literalinclude:: resources/standard/StandardCreateTableTest.sql 9 | :language: SQL 10 | :force: 11 | :linenos: 12 | 13 | .. literalinclude:: resources/standard/StandardCreateIndexTest.sql 14 | :language: SQL 15 | :force: 16 | :linenos: 17 | 18 | Alter 19 | -------------- 20 | 21 | .. literalinclude:: resources/standard/StandardAlterTest.sql 22 | :language: SQL 23 | :force: 24 | :linenos: 25 | 26 | Select 27 | -------------- 28 | 29 | .. literalinclude:: resources/standard/StandardSelectTest.sql 30 | :language: SQL 31 | :force: 32 | :linenos: 33 | 34 | 35 | Merge 36 | -------------- 37 | 38 | .. literalinclude:: resources/standard/StandardMergeTest.sql 39 | :language: SQL 40 | :force: 41 | :linenos: 42 | 43 | Insert 44 | -------------- 45 | 46 | .. literalinclude:: resources/standard/StandardInsertTest.sql 47 | :language: SQL 48 | :force: 49 | :linenos: 50 | 51 | 52 | Update 53 | -------------- 54 | 55 | .. literalinclude:: resources/standard/StandardUpdateTest.sql 56 | :language: SQL 57 | :force: 58 | :linenos: 59 | 60 | 61 | Comments 62 | -------------- 63 | 64 | .. literalinclude:: resources/standard/StandardCommentTest.sql 65 | :language: SQL 66 | :force: 67 | :linenos: 68 | 69 | MS Sql Server 70 | ------------------- 71 | 72 | .. literalinclude:: resources/standard/BracketQuotationTest.sql 73 | :language: SQL 74 | :force: 75 | :linenos: 76 | 77 | .. literalinclude:: resources/standard/MsSqlServerTest.sql 78 | :language: SQL 79 | :force: 80 | :linenos: 81 | 82 | Formatting Options 83 | ------------------- 84 | .. literalinclude:: resources/standard/FormattingOptionsTest.sql 85 | :language: SQL 86 | :force: 87 | :linenos: 88 | -------------------------------------------------------------------------------- /src/site/sphinx/usage.rst: -------------------------------------------------------------------------------- 1 | ***************** 2 | How to use it 3 | ***************** 4 | 5 | ----------------- 6 | Static Binaries 7 | ----------------- 8 | 9 | .. tab:: JVM 10 | 11 | .. code:: Bash 12 | 13 | java -jar JSQLFormatterCLI.jar [-i ] [-o ] [-f | --ansi | --html] [-t | -2 | -8] [--keywordSpelling ] [--functionSpelling ] [--objectSpelling ] [--separation ] [--squareBracketQuotation ] [--statementTerminator ] 14 | 15 | .. tab:: Linux Shell 16 | 17 | .. code:: Bash 18 | 19 | ./JSQLFormatterCLI [-i ] [-o ] [-f | --ansi | --html] [-t | -2 | -8] [--keywordSpelling ] [--functionSpelling ] [--objectSpelling ] [--separation ] [--squareBracketQuotation ] [--statementTerminator ] 20 | 21 | .. tab:: Windows Power Shell 22 | 23 | .. code:: Bash 24 | 25 | JSQLFormatterCLI.exe [-i ] [-o ] [-f | --ansi | --html] [-t | -2 | -8] [--keywordSpelling ] [--functionSpelling ] [--objectSpelling ] [--separation ] [--squareBracketQuotation ] [--statementTerminator ] 26 | 27 | .......................... 28 | Command Line Options (CLI) 29 | .......................... 30 | --inputFile, -i The input SQL file or folder. 31 | --outputFile, -o The out SQL file for the formatted statements. 32 | --format, -f The output-format [PLAIN* ANSI HTML RTF] 33 | --ansi Output ANSI annotated text. 34 | --html Output HTML annotated text. 35 | --indentWidth, -t The Indent Width [2 4* 8] 36 | -2 Indent with 2 characters. 37 | -8 Indent with 8 characters. 38 | --keywordSpelling Spelling of keywords. [UPPER* LOWER CAMEL KEEP] 39 | --objectSpelling Spelling of object names. [UPPER* LOWER CAMEL KEEP] 40 | --functionSpelling Spelling of function names. [UPPER* LOWER CAMEL KEEP] 41 | --separation Position of the field separator. [BEFORE* AFTER] 42 | --squareBracketQuotation Interpret Square Brackets "[]" as quotes instead of arrays. [AUTO* YES NO] 43 | --statementTerminator Set the statement terminator. [SEMICOLON* NONE GO BACKSLASH] 44 | 45 | .. note:: 46 | 47 | You can provide the SQL Statement as an argument to the program, e. g. 48 | 49 | .. code:: Bash 50 | 51 | java -jar JSQLFormatterCLI.jar "select * from dual;" 52 | 53 | .. note:: 54 | 55 | You can provide the formatting options as comment in front of the sql statement 56 | 57 | .. code:: SQL 58 | 59 | -- @JSQLFormatter(indentWidth=8, keywordSpelling=UPPER, functionSpelling=CAMEL, objectSpelling=LOWER, separation=BEFORE) 60 | SELECT 'something' FROM DUAL; 61 | 62 | 63 | .. warning:: 64 | 65 | On Windows 10, you will need to active ANSI output first 66 | 67 | .. code:: Shell 68 | 69 | Set-ItemProperty HKCU:\Console VirtualTerminalLevel -Type DWORD 1 70 | 71 | 72 | 73 | ----------------- 74 | Dynamic Libraries 75 | ----------------- 76 | 77 | .. tab:: Java 78 | 79 | .. code:: Java 80 | 81 | import com.manticore.jsqlformatter.JSqlFormatter; 82 | 83 | class Sample { 84 | public static void main(String[] args) { 85 | String formattedSql = JSqlFormatter.format("select * from dual;"); 86 | } 87 | } 88 | 89 | .. tab:: C++ 90 | 91 | .. code:: python 92 | 93 | #include 94 | #include 95 | 96 | #include 97 | 98 | int main(int argc, char **argv) { 99 | graal_isolate_t *isolate = NULL; 100 | graal_isolatethread_t *thread = NULL; 101 | 102 | if (graal_create_isolate(NULL, &isolate, &thread) != 0) { 103 | fprintf(stderr, "graal_create_isolate error\n"); 104 | return 1; 105 | } 106 | 107 | printf("%s", format(thread, "select * from dual;")); 108 | 109 | if (graal_detach_thread(thread) != 0) { 110 | fprintf(stderr, "graal_detach_thread error\n"); 111 | return 1; 112 | } 113 | 114 | return 0; 115 | } 116 | 117 | -------------------------------------------------------------------------------- /src/test/java/com/manticore/jsqlformatter/DebugStatementTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Manticore Projects JSQLFormatter is a SQL Beautifying and Formatting Software. 3 | * Copyright (C) 2023 Andreas Reichel 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package com.manticore.jsqlformatter; 19 | 20 | import net.sf.jsqlparser.parser.CCJSqlParserUtil; 21 | import net.sf.jsqlparser.statement.Statement; 22 | import net.sf.jsqlparser.statement.select.Select; 23 | import org.junit.jupiter.api.Assertions; 24 | import org.junit.jupiter.api.Test; 25 | 26 | public class DebugStatementTest { 27 | @Test 28 | public void debugStatementTest() throws Exception { 29 | String sqlStr = "SELECT sales.* EXCLUDE( a, b, c )\n" + "FROM sales\n" + ";"; 30 | Statement statement1 = 31 | CCJSqlParserUtil.parse(sqlStr, parser -> parser.withUnsupportedStatements(false)); 32 | 33 | Assertions.assertInstanceOf(Select.class, statement1); 34 | 35 | String formatteredSqlStr = JSQLFormatter.format(sqlStr); 36 | System.out.println(formatteredSqlStr); 37 | Statement statement2 = CCJSqlParserUtil.parse(formatteredSqlStr, 38 | parser -> parser.withUnsupportedStatements(false)); 39 | 40 | Assertions.assertInstanceOf(Select.class, statement2); 41 | 42 | Assertions.assertEquals(statement1.toString().toLowerCase(), 43 | statement2.toString().toLowerCase()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/manticore/jsqlformatter/FormatTest.java: -------------------------------------------------------------------------------- 1 | package com.manticore.jsqlformatter; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class FormatTest { 7 | @Test 8 | void testStatementTerminator() throws Exception { 9 | String provided = "Select 1"; 10 | String expected = "SELECT 1"; 11 | 12 | String result = JSQLFormatter.format(provided, "statementTerminator=NONE"); 13 | Assertions.assertEquals(expected, result); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/manticore/jsqlformatter/LineCountTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Manticore Projects JSQLFormatter is a SQL Beautifying and Formatting Software. 3 | * Copyright (C) 2023 Andreas Reichel 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package com.manticore.jsqlformatter; 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | public class LineCountTest { 23 | 24 | @Test 25 | public void lineCountTest() throws Exception { 26 | String sqlString = "select 1,2,3 from dual where a=b and b=c;"; 27 | System.out.println(JSQLFormatter.format(sqlString, "showLineNumbers=YES")); 28 | System.out.println(JSQLFormatter.format(sqlString, "outputFormat=ANSI")); 29 | } 30 | 31 | @Test 32 | public void lineCountTestHtml() throws Exception { 33 | String sqlString = "select 1,2,3 from dual where a=b and b=c;"; 34 | System.out.println(JSQLFormatter.format(sqlString, "showLineNumbers=YES")); 35 | System.out.println(JSQLFormatter.format(sqlString, "outputFormat=HTML")); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/manticore/jsqlformatter/ParserTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Manticore Projects JSQLFormatter is a SQL Beautifying and Formatting Software. 3 | * Copyright (C) 2023 Andreas Reichel 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package com.manticore.jsqlformatter; 19 | 20 | import net.sf.jsqlparser.JSQLParserException; 21 | import net.sf.jsqlparser.expression.Expression; 22 | import net.sf.jsqlparser.expression.ExpressionVisitorAdapter; 23 | import net.sf.jsqlparser.expression.operators.conditional.AndExpression; 24 | import net.sf.jsqlparser.expression.operators.conditional.OrExpression; 25 | import net.sf.jsqlparser.parser.CCJSqlParserUtil; 26 | import net.sf.jsqlparser.statement.Statement; 27 | import net.sf.jsqlparser.statement.StatementVisitor; 28 | import net.sf.jsqlparser.statement.StatementVisitorAdapter; 29 | import net.sf.jsqlparser.statement.select.PlainSelect; 30 | import net.sf.jsqlparser.statement.select.Select; 31 | import net.sf.jsqlparser.statement.select.SelectVisitorAdapter; 32 | import org.junit.jupiter.api.Test; 33 | 34 | import java.util.logging.Logger; 35 | 36 | public class ParserTest { 37 | Logger LOGGER = Logger.getLogger(ParserTest.class.getName()); 38 | 39 | @Test 40 | public void testExpressionClassInstances() throws JSQLParserException { 41 | String sqlStr = 42 | "SELECT * FROM test WHERE aaa = 1 or bbb = 2 and case when ccc = 3 then 4 else 5 end = 6"; 43 | Statement statement = CCJSqlParserUtil.parse(sqlStr); 44 | 45 | if (statement instanceof Select) { 46 | Select select = (Select) statement; 47 | 48 | if (select instanceof PlainSelect) { 49 | PlainSelect plainSelect = (PlainSelect) select; 50 | Expression whereExpression = plainSelect.getWhere(); 51 | 52 | if (whereExpression instanceof AndExpression) { 53 | AndExpression andExpression = (AndExpression) whereExpression; 54 | LOGGER.info("Found AND Expression: " + andExpression); 55 | } else if (whereExpression instanceof OrExpression) { 56 | OrExpression orExpression = (OrExpression) whereExpression; 57 | LOGGER.info("Found OR Expression: " + orExpression); 58 | } 59 | } 60 | } 61 | } 62 | 63 | @Test 64 | public void testExpressionVisitor() throws JSQLParserException { 65 | String sqlStr = 66 | "SELECT * FROM test WHERE aaa = 1 or bbb = 2 and case when ccc = 3 then 4 else 5 end = 6"; 67 | Statement statement = CCJSqlParserUtil.parse(sqlStr); 68 | 69 | ExpressionVisitorAdapter expressionVisitorAdapter = new ExpressionVisitorAdapter<>() { 70 | @Override 71 | public void visit(OrExpression orExpression) { 72 | super.visit(orExpression); 73 | LOGGER.info("Found OR Expression: " + orExpression); 74 | } 75 | 76 | @Override 77 | public void visit(AndExpression andExpression) { 78 | super.visit(andExpression); 79 | LOGGER.info("Found AND Expression: " + andExpression); 80 | } 81 | }; 82 | 83 | SelectVisitorAdapter selectVisitorAdapter = new SelectVisitorAdapter<>() { 84 | @Override 85 | public void visit(PlainSelect plainSelect) { 86 | plainSelect.getWhere().accept(expressionVisitorAdapter); 87 | } 88 | }; 89 | 90 | StatementVisitorAdapter statementVisitorAdapter = new StatementVisitorAdapter<>() { 91 | @Override 92 | public void visit(Select select) { 93 | select.accept((StatementVisitor) selectVisitorAdapter); 94 | } 95 | }; 96 | 97 | statement.accept(statementVisitorAdapter); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/test/java/com/manticore/jsqlformatter/SimpleFileTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Manticore Projects JSQLFormatter is a SQL Beautifying and Formatting Software. 3 | * Copyright (C) 2023 Andreas Reichel 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package com.manticore.jsqlformatter; 19 | 20 | import java.io.BufferedReader; 21 | import java.io.File; 22 | import java.io.FileReader; 23 | import java.io.IOException; 24 | import java.util.LinkedHashMap; 25 | import java.util.Map.Entry; 26 | import java.util.Objects; 27 | import java.util.logging.Level; 28 | import java.util.stream.Stream; 29 | 30 | /** 31 | * @author Andreas Reichel 32 | */ 33 | public class SimpleFileTest extends StandardFileTest { 34 | 35 | public final static String TEST_FOLDER_STR = 36 | "build/resources/test/com/manticore/jsqlformatter/simple"; 37 | 38 | public static Stream> getSqlMap() { 39 | LinkedHashMap sqlMap = new LinkedHashMap<>(); 40 | 41 | for (File file : Objects.requireNonNull(new File(TEST_FOLDER_STR).listFiles(FILENAME_FILTER))) { 42 | StringBuilder stringBuilder = new StringBuilder(); 43 | String line; 44 | String k = ""; 45 | 46 | try (FileReader fileReader = new FileReader(file); 47 | BufferedReader bufferedReader = new BufferedReader(fileReader)) { 48 | while ((line = bufferedReader.readLine()) != null) { 49 | stringBuilder.append(line).append("\n"); 50 | } 51 | sqlMap.put(new SQLKeyEntry(file, k), stringBuilder.toString().trim()); 52 | } catch (IOException ex) { 53 | LOGGER.log(Level.SEVERE, "Failed to read " + file.getAbsolutePath(), ex); 54 | } 55 | } 56 | 57 | return sqlMap.entrySet().stream(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/manticore/jsqlformatter/StandardFileTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Manticore Projects JSQLFormatter is a SQL Beautifying and Formatting Software. 3 | * Copyright (C) 2023 Andreas Reichel 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Affero General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package com.manticore.jsqlformatter; 19 | 20 | import net.sf.jsqlparser.parser.CCJSqlParserUtil; 21 | import net.sf.jsqlparser.statement.Statements; 22 | import org.junit.jupiter.api.Assertions; 23 | import org.junit.jupiter.params.ParameterizedTest; 24 | import org.junit.jupiter.params.provider.MethodSource; 25 | 26 | import java.io.BufferedReader; 27 | import java.io.File; 28 | import java.io.FileReader; 29 | import java.io.FilenameFilter; 30 | import java.io.IOException; 31 | import java.util.LinkedHashMap; 32 | import java.util.Map.Entry; 33 | import java.util.Objects; 34 | import java.util.logging.Level; 35 | import java.util.logging.Logger; 36 | import java.util.stream.Stream; 37 | 38 | import static com.manticore.jsqlformatter.CommentMap.COMMENT_PATTERN; 39 | import static com.manticore.jsqlformatter.JSQLFormatter.SQUARED_BRACKET_QUOTATION_PATTERN; 40 | 41 | /** 42 | * @author Andreas Reichel 43 | */ 44 | 45 | public class StandardFileTest { 46 | public final static String TEST_FOLDER_STR = 47 | "build/resources/test/com/manticore/jsqlformatter/standard"; 48 | 49 | public static final FilenameFilter FILENAME_FILTER = new FilenameFilter() { 50 | @Override 51 | public boolean accept(File dir, String name) { 52 | return name.toLowerCase().endsWith(".sql"); 53 | } 54 | }; 55 | 56 | public final static Logger LOGGER = Logger.getLogger(StandardFileTest.class.getName()); 57 | 58 | public static Stream> getSqlMap() { 59 | LinkedHashMap sqlMap = new LinkedHashMap<>(); 60 | 61 | for (File file : Objects.requireNonNull(new File(TEST_FOLDER_STR).listFiles(FILENAME_FILTER))) { 62 | boolean start = false; 63 | boolean end; 64 | 65 | StringBuilder stringBuilder = new StringBuilder(); 66 | String line; 67 | String k = ""; 68 | 69 | try (FileReader fileReader = new FileReader(file); 70 | BufferedReader bufferedReader = new BufferedReader(fileReader)) { 71 | while ((line = bufferedReader.readLine()) != null) { 72 | 73 | if (!start && line.startsWith("--") && !line.startsWith("-- @")) { 74 | k = line.substring(3).trim().toUpperCase(); 75 | } 76 | 77 | start = start 78 | || (!line.startsWith("--") || line.startsWith("-- @")) && !line.trim().isEmpty(); 79 | end = start && !line.startsWith("--") && line.trim().endsWith(";"); 80 | 81 | if (start) { 82 | stringBuilder.append(line).append("\n"); 83 | } 84 | 85 | if (end) { 86 | sqlMap.put(new SQLKeyEntry(file, k), stringBuilder.toString().trim()); 87 | stringBuilder.setLength(0); 88 | start = false; 89 | } 90 | 91 | } 92 | } catch (IOException ex) { 93 | LOGGER.log(Level.SEVERE, "Failed to read " + file.getAbsolutePath(), ex); 94 | } 95 | } 96 | 97 | return sqlMap.entrySet().stream(); 98 | } 99 | 100 | public String buildSqlString(final String originalSql, boolean laxDeparsingCheck) { 101 | String sql = COMMENT_PATTERN.matcher(originalSql).replaceAll(""); 102 | if (laxDeparsingCheck) { 103 | String s = sql.replaceAll("\\n*\\s*;", ";").replaceAll("\\s+", " ") 104 | .replaceAll("\\s*([!/,()=+\\-*|\\{\\}\\[\\]<>:])\\s*", "$1").toLowerCase().trim(); 105 | return !s.endsWith(";") ? s + ";" : s; 106 | } else { 107 | return sql; 108 | } 109 | } 110 | 111 | /** 112 | * Test of format method, of class JSQLFormatter. 113 | * 114 | */ 115 | @ParameterizedTest(name = "{index} {0}: {1}") 116 | @MethodSource("getSqlMap") 117 | void testFormat(Entry entry) throws Exception { 118 | String expected = entry.getValue(); 119 | 120 | String formatted = JSQLFormatter.format(expected, "indentWidth=4", "keywordSpelling=UPPER", 121 | "functionSpelling=CAMEL", "objectSpelling=LOWER", "separation=BEFORE"); 122 | 123 | // check if the formatted version matches the provided version 124 | Assertions.assertEquals(expected.trim(), formatted.trim()); 125 | } 126 | 127 | /** 128 | * Test parsing the provided examples 129 | * 130 | */ 131 | @ParameterizedTest(name = "{index} {0}: {1}") 132 | @MethodSource("getSqlMap") 133 | void testParser(Entry entry) { 134 | String expected = entry.getValue(); 135 | 136 | if (expected.length() <= new CommentMap(expected).getLength()) { 137 | LOGGER.warning("Skip empty statement, when found only comments: " + expected); 138 | } else { 139 | // check if the formatted statement still can be parsed and gives the same content 140 | String sqlStringFromStatement = buildSqlString(expected, true); 141 | 142 | boolean foundSquareBracketQuotes = SQUARED_BRACKET_QUOTATION_PATTERN.matcher(expected).find(); 143 | try { 144 | Statements parsed = CCJSqlParserUtil.parseStatements(expected, 145 | parser -> parser.withSquareBracketQuotation(foundSquareBracketQuotes)); 146 | 147 | String sqlStringFromDeparser = buildSqlString(parsed.toString(), true); 148 | 149 | Assertions.assertEquals(sqlStringFromStatement, sqlStringFromDeparser); 150 | } catch (Exception ex) { 151 | Assertions.fail("Failed to parse: " + expected); 152 | } 153 | } 154 | } 155 | 156 | public static class SQLKeyEntry implements Entry { 157 | File key; 158 | String value; 159 | 160 | public SQLKeyEntry(File key, String value) { 161 | this.key = key; 162 | this.value = value; 163 | } 164 | 165 | @Override 166 | public File getKey() { 167 | return key; 168 | } 169 | 170 | @Override 171 | public String getValue() { 172 | return value; 173 | } 174 | 175 | @Override 176 | public String setValue(String value) { 177 | return this.value = value; 178 | } 179 | 180 | @Override 181 | public String toString() { 182 | return value + " @ " + key.getName(); 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/AllTableColumns.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | , a.* 3 | , b.* 4 | , c.* 5 | FROM a 6 | , b 7 | , c 8 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/ExplainTest.sql: -------------------------------------------------------------------------------- 1 | EXPLAIN PLAN FOR 2 | SELECT osuser 3 | , sl.sql_id 4 | , sl.sql_hash_value 5 | , opname 6 | , target 7 | , elapsed_seconds 8 | , time_remaining 9 | FROM v$session_longops sl 10 | INNER JOIN v$session s 11 | ON sl.sid = s.sid 12 | AND sl.serial# = s.serial# 13 | WHERE time_remaining > 0 14 | ; 15 | 16 | SUMMARIZE 17 | SELECT osuser 18 | , sl.sql_id 19 | , sl.sql_hash_value 20 | , opname 21 | , target 22 | , elapsed_seconds 23 | , time_remaining 24 | FROM v$session_longops sl 25 | INNER JOIN v$session s 26 | ON sl.sid = s.sid 27 | AND sl.serial# = s.serial# 28 | WHERE time_remaining > 0 29 | ; 30 | 31 | EXPLAIN cfe.execution 32 | ; 33 | 34 | SUMMARIZE cfe.execution 35 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/Issue0005.sql: -------------------------------------------------------------------------------- 1 | -- Keyword Spelling of NULL, DISTINCT, INTERVAL 2 | -- @JSQLFormatter(keywordSpelling=LOWER) 3 | update sms_queue sq 4 | set sq.gateway_sms_id = null 5 | , sq.date_sent_sms = null 6 | , sq.sms_status_id = 1 7 | , sq.date_added = Now() - interval 1 minute 8 | , sq.date_should_sent = Now() - interval 1 minute 9 | where sq.sms_id = 2864158 10 | ; 11 | 12 | select ccp.product_id 13 | , Count( distinct ccp.campaign_id ) 14 | from campaign_constraint_product ccp 15 | left join campaign c 16 | on c.campaign_id = ccp.campaign_id 17 | and c.status = 1 18 | where product_id in ( 414732, 530729 ) 19 | group by ccp.product_id 20 | order by 2 desc 21 | limit 10 22 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/SQLFileTest.sql: -------------------------------------------------------------------------------- 1 | SELECT osuser 2 | , sl.sql_id 3 | , sl.sql_hash_value 4 | , opname 5 | , target 6 | , elapsed_seconds 7 | , time_remaining 8 | FROM v$session_longops sl 9 | INNER JOIN v$session s 10 | ON sl.sid = s.sid 11 | AND sl.serial# = s.serial# 12 | WHERE time_remaining > 0 13 | ; 14 | 15 | CREATE VIEW sys.running_sql 16 | AS SELECT s.username 17 | , sl.sid 18 | , sq.executions 19 | , sl.last_update_time 20 | , sl.sql_id 21 | , sl.sql_hash_value 22 | , opname 23 | , target 24 | , elapsed_seconds 25 | , time_remaining 26 | , sq.sql_fulltext 27 | FROM v$session_longops sl 28 | INNER JOIN v$sql sq 29 | ON sq.sql_id = sl.sql_id 30 | INNER JOIN v$session s 31 | ON sl.sid = s.sid 32 | AND sl.serial# = s.serial# 33 | WHERE time_remaining > 0 34 | ; 35 | 36 | SET pagesize 55 37 | ; 38 | 39 | SET linesize 170 40 | ; 41 | 42 | /* 43 | something crazy; 44 | something crazy; 45 | something crazy; 46 | something crazy; 47 | */ 48 | 49 | 50 | -- something crazy; 51 | SELECT Substr( v$session.username, 1, 8 ) username 52 | , v$session.osuser osuser 53 | , Decode( v$session.server 54 | , 'DEDICATED', 'D' 55 | , 'SHARED', 'S' 56 | , 'O' ) server 57 | , v$sqlarea.disk_reads disk_reads 58 | , v$sqlarea.buffer_gets buffer_gets 59 | , Substr( v$session.lockwait, 1, 10 ) lockwait 60 | , v$session.process pid 61 | , v$session_wait.event event 62 | , v$sqlarea.sql_text sql 63 | FROM v$session_wait 64 | , v$sqlarea 65 | , v$session 66 | WHERE v$session.sql_address = v$sqlarea.address 67 | AND v$session.sql_hash_value = v$sqlarea.hash_value 68 | AND v$session.sid = v$session_wait.sid 69 | AND v$session.status = 'ACTIVE' 70 | AND v$session_wait.event != 'client message' 71 | ORDER BY v$session.lockwait ASC 72 | , v$session.username 73 | ; 74 | 75 | SELECT 'exec DBMS_SHARED_POOL.PURGE (''' || address || ',' || hash_value || ''', ''C'');' 76 | FROM v$sqlarea 77 | WHERE sql_id LIKE '9z1ufprvt2pk2' 78 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/SQLFileTest_short.sql: -------------------------------------------------------------------------------- 1 | DELETE FROM cfe.ledger_branch_balance 2 | WHERE ( value_date, posting_date, something_else 3 | , value_date, posting_date, something_else ) = ( SELECT value_date 4 | , posting_date 5 | , something_else 6 | , value_date 7 | , posting_date 8 | , something_else 9 | FROM cfe.execution 10 | WHERE id_status = 'R' 11 | AND value_date = :VALUE_DATE ) 12 | ; 13 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/aggregate.todo: -------------------------------------------------------------------------------- 1 | SELECT STRING_AGG( FRUIT,' & ' ORDER BY CASE TYPEOF(FRUIT) 2 | WHEN 'VARCHAR' THEN LENGTH(TRY_CAST(FRUIT AS VARCHAR)) 3 | WHEN 'BLOB' THEN OCTET_LENGTH(TRY_CAST(FRUIT AS BLOB)) 4 | END ) AS STRING_AGG 5 | FROM ( SELECT UNNEST( ['apple','pear','banana','pear'] ) AS FRUIT) AS FRUIT 6 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/case.sql: -------------------------------------------------------------------------------- 1 | SELECT t 2 | , len 3 | , Printf( '%s', CASE Typeof( t ) 4 | WHEN 'VARCHAR' 5 | THEN Rpad( t::VARCHAR, len, ' ' ) 6 | END ) AS rpad 7 | FROM ( SELECT Unnest( [ 8 | { t:'abc',len:5 } 9 | , ( 'abc', 2 ) 10 | , ( '例子', 4 ) 11 | ], recursive => true ) ) 12 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/cast.sql: -------------------------------------------------------------------------------- 1 | SELECT Cast( ( SELECT 1 ) AS DECIMAL (1) ) 2 | ; 3 | 4 | SELECT Cast( CASE 5 | WHEN Position('(' IN description) > 0 6 | THEN Trim( substr(description, 1, POSITION('(' IN description) - 1) ) 7 | ELSE description 8 | END AS CHAR ) accounting_event 9 | ; 10 | 11 | SELECT id 12 | , Try_Cast( v AS JSON ) j 13 | , '2013-05-08'::DATE AS v1 14 | FROM vartab 15 | ORDER BY id 16 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/duckdb.sql: -------------------------------------------------------------------------------- 1 | SELECT sales.* EXCLUDE( a, b, c ) 2 | FROM sales 3 | ; 4 | 5 | SELECT * EXCLUDE( a, b, c ) 6 | FROM sales 7 | ; 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/fetch.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM mytable 3 | WHERE mytable.col = 9 4 | ORDER BY mytable.id 5 | FETCH NEXT 5 ROWS ONLY 6 | ; 7 | 8 | SELECT 1 9 | FROM test.dual 10 | FETCH FIRST ROW ONLY 11 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/groupby.sql: -------------------------------------------------------------------------------- 1 | -- GROUP BY resulting in an Unsupported Statement 2 | SELECT a 3 | , b 4 | , c 5 | , Sum( d ) 6 | FROM t 7 | GROUP BY a 8 | , b 9 | , c 10 | HAVING Sum( d ) > 0 11 | AND Count( * ) > 1 12 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/pivot.sql: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT 2 | product 3 | FROM ( SELECT * 4 | FROM ( SELECT 'kale' AS product 5 | , 55 AS q1 6 | , 45 AS q2 7 | UNION ALL 8 | SELECT 'apple' 9 | , 8 10 | , 10 ) 11 | UNPIVOT (sales FOR quarter IN (Q1, Q2)) 12 | ORDER BY 1 ) 13 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/simple/window.sql: -------------------------------------------------------------------------------- 1 | WITH finishers AS ( 2 | SELECT 'Sophia Liu' AS name 3 | , TIMESTAMP '2016-10-18 2:51:45' AS finish_time 4 | , 'F30-34' AS division 5 | UNION ALL 6 | SELECT 'Lisa Stelzner' 7 | , TIMESTAMP '2016-10-18 2:54:11' 8 | , 'F35-39' 9 | UNION ALL 10 | SELECT 'Nikki Leith' 11 | , TIMESTAMP '2016-10-18 2:59:01' 12 | , 'F30-34' 13 | UNION ALL 14 | SELECT 'Lauren Matthews' 15 | , TIMESTAMP '2016-10-18 3:01:17' 16 | , 'F35-39' 17 | UNION ALL 18 | SELECT 'Desiree Berry' 19 | , TIMESTAMP '2016-10-18 3:05:42' 20 | , 'F35-39' 21 | UNION ALL 22 | SELECT 'Suzy Slane' 23 | , TIMESTAMP '2016-10-18 3:06:24' 24 | , 'F35-39' 25 | UNION ALL 26 | SELECT 'Jen Edwards' 27 | , TIMESTAMP '2016-10-18 3:06:36' 28 | , 'F30-34' 29 | UNION ALL 30 | SELECT 'Meghan Lederer' 31 | , TIMESTAMP '2016-10-18 3:07:41' 32 | , 'F30-34' 33 | UNION ALL 34 | SELECT 'Carly Forte' 35 | , TIMESTAMP '2016-10-18 3:08:58' 36 | , 'F25-29' 37 | UNION ALL 38 | SELECT 'Lauren Reasoner' 39 | , TIMESTAMP '2016-10-18 3:10:14' 40 | , 'F30-34' ) 41 | SELECT name 42 | , Strftime( finish_time, '%X' ) AS finish_time 43 | , division 44 | , Strftime( fastest_time, '%X' ) AS fastest_time 45 | , Strftime( second_fastest, '%X' ) AS second_fastest 46 | FROM ( SELECT name 47 | , finish_time 48 | , division 49 | , finishers 50 | , First( finish_time ) 51 | OVER w1 AS fastest_time 52 | , Nth_Value( finish_time, 2 ) 53 | OVER w1 AS second_fastest 54 | FROM finishers 55 | WINDOW 56 | w1 AS ( 57 | PARTITION BY division 58 | ORDER BY finish_time ASC 59 | ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) ) 60 | ORDER BY 3 61 | , 2 62 | , 1 63 | ; 64 | 65 | SELECT First_Value( bc.merch_l1_name IGNORE NULLS ) 66 | OVER (PARTITION BY sku, channel_id ORDER BY feed_date DESC) AS merch_l1_name 67 | , First_Value( bc.brand IGNORE NULLS ) 68 | OVER (PARTITION BY sku, channel_id ORDER BY feed_date DESC) AS brand 69 | FROM temp.abc bc 70 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/BracketQuotationTest.sql: -------------------------------------------------------------------------------- 1 | 2 | -- BRACKETS 1 3 | SELECT columnname 4 | FROM [server-name\\server-instance]..schemaname.tablename 5 | ; 6 | 7 | -- BRACKETS 2 8 | SELECT columnname 9 | FROM [server-name\\server-instance]..[schemaName].[table Name] 10 | ; 11 | 12 | -- BRACKETS 3 13 | SELECT columnname 14 | FROM [server-name\\server-instance]..[schemaName].[table-Name] 15 | ; 16 | 17 | -- BRACKETS 4 18 | SELECT columnname 19 | FROM [schemaName].[tableName] 20 | ; 21 | 22 | -- BRACKETS 5 23 | SELECT columnname 24 | FROM schemaname.[tableName] 25 | ; 26 | 27 | -- BRACKETS 6 28 | SELECT columnname 29 | FROM [schemaName].tablename 30 | ; 31 | 32 | -- READ INSTRUMENT TRANSACTIONS WITH COLLATERAL ONLY 33 | SELECT a.* 34 | FROM [cfe].[TRANSACTION] a 35 | INNER JOIN cfe.instrument b 36 | ON a.id_instrument = b.id_instrument 37 | WHERE a.id_instrument >= ? 38 | AND a.id_instrument <= ? 39 | AND EXISTS ( SELECT 1 40 | FROM cfe.instrument_ref b 41 | INNER JOIN cfe.instrument_collateral_hst c 42 | ON b.id_instrument_ref = c.id_instrument_ref 43 | WHERE b.id_instrument = a.id_instrument ) 44 | ; 45 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/ExpressionTest.sql: -------------------------------------------------------------------------------- 1 | -- BETWEEN 2 | SELECT kal_datum BETWEEN Trunc( a.adate ) 3 | AND ( SELECT Max( Trunc( change_date ) ) 4 | FROM besch_statusaenderung 5 | WHERE beschwerden_id = a.beschwerden_id 6 | AND beschstatus_id = 9 7 | AND Nvl( inaktiv, 'F' ) != 'T' ) 8 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/FormattingOptionsTest.sql: -------------------------------------------------------------------------------- 1 | -- 1 UPDATE CALENDAR 2 | -- @JSQLFormatter(indentWidth=8, keywordSpelling=UPPER, functionSpelling=CAMEL, objectSpelling=LOWER, separation=BEFORE) 3 | UPDATE cfe.calendar 4 | SET year_offset = ? /* year offset */ 5 | , settlement_shift = To_Char( ? ) /* settlement shift */ 6 | , friday_is_holiday = ? /* friday is a holiday */ 7 | , saturday_is_holiday = ? /* saturday is a holiday */ 8 | , sunday_is_holiday = ? /* sunday is a holiday */ 9 | WHERE id_calendar = ? 10 | ; 11 | 12 | 13 | -- 2 UPDATE CALENDAR 14 | -- @JSQLFormatter(indentWidth=2, keywordSpelling=LOWER, functionSpelling=KEEP, objectSpelling=UPPER, separation=AFTER) 15 | update CFE.CALENDAR 16 | set YEAR_OFFSET = ? /* year offset */, 17 | SETTLEMENT_SHIFT = to_char( ? ) /* settlement shift */, 18 | FRIDAY_IS_HOLIDAY = ? /* friday is a holiday */, 19 | SATURDAY_IS_HOLIDAY = ? /* saturday is a holiday */, 20 | SUNDAY_IS_HOLIDAY = ? /* sunday is a holiday */ 21 | where ID_CALENDAR = ? 22 | ; 23 | 24 | 25 | -- 3 MERGE DELETE WHERE 26 | -- @JSQLFormatter(indentWidth=2, keywordSpelling=LOWER, functionSpelling=KEEP, objectSpelling=UPPER, separation=AFTER) 27 | merge into EMPL_CURRENT TAR 28 | using ( select EMPNO, 29 | ENAME, 30 | case 31 | when LEAVEDATE <= SYSDATE 32 | then 'Y' 33 | else 'N' 34 | end as DELETE_FLAG 35 | from EMPL ) SRC 36 | on ( TAR.EMPNO = SRC.EMPNO ) 37 | when not matched then 38 | insert ( EMPNO, 39 | ENAME ) 40 | values ( SRC.EMPNO, 41 | SRC.ENAME ) 42 | when matched then 43 | update set TAR.ENAME = SRC.ENAME 44 | where DELETE_FLAG = 'N' 45 | delete where DELETE_FLAG = 'Y' 46 | ; 47 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/H2OrderedAggregateTest.sql: -------------------------------------------------------------------------------- 1 | -- LISTAGG 1 2 | SELECT Listagg( name, ', ' ) 3 | WITHIN GROUP (ORDER BY ID) 4 | ; 5 | 6 | -- LISTAGG 2 7 | SELECT Listagg( Coalesce( name, 'null' ), ', ' ) 8 | WITHIN GROUP (ORDER BY ID) 9 | ; 10 | 11 | -- LISTAGG 3 12 | /* Unsupported: SELECT LISTAGG(ID, ', ') WITHIN GROUP (ORDER BY ID) OVER (ORDER BY ID); */ 13 | SELECT 1 14 | FROM dual 15 | ; 16 | 17 | -- ARRAY_AGG 1 18 | SELECT Array_Agg( name ) 19 | ; 20 | 21 | -- ARRAY_AGG 2 22 | SELECT Array_Agg( name ORDER BY ID ) 23 | FILTER ( WHERE NAME IS NOT NULL ) 24 | ; 25 | 26 | -- ARRAY_AGG 3 27 | /* SELECT ARRAY_AGG(ID ORDER BY ID) OVER (ORDER BY ID); */ 28 | SELECT 1 29 | FROM dual 30 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/MeanChallenges.sql: -------------------------------------------------------------------------------- 1 | -- SELECT Date Ranges of available data 2 | 3 | WITH p 4 | AS (SELECT DISTINCT value_date 5 | FROM risk.migration_data_v 6 | WHERE (:1 IS NULL OR :2 ='' OR id_portfolio = Decode (:3 , '001', 'IFRS1', 7 | '002', 'IFRS2', 8 | '003', 'IFRS3', 9 | '004', 'IFRS4', 10 | '005', 'IFRS5', 11 | '006', 'IFRS6', 12 | :4 )) 13 | AND value_date >= :5 14 | AND value_date <= :6 ), 15 | ri 16 | AS (SELECT a.id_risk_indicator 17 | , Greatest((SELECT Min(value_date) 18 | FROM p 19 | WHERE value_date >= :7 ), (SELECT Max(value_date) 20 | FROM risk.risk_indicator_value 21 | WHERE id_risk_indicator_ref = a.id_risk_indicator_ref 22 | AND value_date <= :8 )) min_ri_date 23 | , Greatest((SELECT Min(value_date) 24 | FROM p 25 | WHERE value_date >= :9 ), (SELECT Min(value_date) 26 | FROM risk.risk_indicator_value 27 | WHERE id_risk_indicator_ref = a.id_risk_indicator_ref 28 | AND value_date >= :10 )) min_ri_date_1 29 | , Least((SELECT Max(value_date) 30 | FROM p 31 | WHERE value_date <= :11 ), (SELECT Min(value_date) 32 | FROM risk.risk_indicator_value 33 | WHERE id_risk_indicator_ref = a.id_risk_indicator_ref 34 | AND value_date >= :12 )) max_ri_date 35 | , Least((SELECT Max(value_date) 36 | FROM p 37 | WHERE value_date <= :13 ), (SELECT Max(value_date) 38 | FROM risk.risk_indicator_value 39 | WHERE id_risk_indicator_ref = a.id_risk_indicator_ref 40 | AND value_date <= :14 )) max_ri_date_1 41 | FROM risk.risk_indicator a 42 | WHERE a.id_status = 'C' 43 | AND a.id_risk_indicator_ref = (SELECT Max(id_risk_indicator_ref) 44 | FROM risk.risk_indicator 45 | WHERE id_status = 'C' 46 | AND id_risk_indicator = a.id_risk_indicator) 47 | AND ( ( :15 IS NULL 48 | OR id_risk_indicator = :16 ) 49 | )) 50 | SELECT /*+parallel*/ ri.id_risk_indicator 51 | , Min(p.value_date) "Min. Observation Date" 52 | , Max(p.value_date) "Max. Observation Date" 53 | FROM ri 54 | , p 55 | WHERE p.value_date >= Nvl(ri.min_ri_date, ri.min_ri_date_1) 56 | AND p.value_date <= Nvl(ri.max_ri_date, ri.max_ri_date_1) 57 | GROUP BY ri.id_risk_indicator 58 | order by 1 59 | 60 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/MsSqlServerTest.sql: -------------------------------------------------------------------------------- 1 | 2 | -- DELETE INSTRUMENT ATTRIBUTE HST AFTER VALUE_DATE_P 3 | DELETE a FROM cfe.instrument_attribute_hst2 a 4 | INNER JOIN ( SELECT value_date 5 | , posting_date 6 | FROM cfe.execution 7 | WHERE posting_date > ( SELECT Max( posting_date ) 8 | FROM cfe.execution 9 | WHERE id_status = 'R' 10 | AND value_date <= :value_date_p ) 11 | OR ( SELECT Max( posting_date ) 12 | FROM cfe.execution 13 | WHERE id_status = 'R' 14 | AND value_date <= :value_date_p ) IS NULL ) b 15 | ON a.value_date = b.value_date 16 | AND b.posting_date = b.posting_date 17 | ; 18 | 19 | -- READ INSTRUMENT TRANSACTIONS WITH COLLATERAL ONLY1 20 | SELECT a.* 21 | FROM [cfe].[TRANSACTION] a 22 | INNER JOIN cfe.instrument b 23 | ON a.id_instrument = b.id_instrument 24 | WHERE a.id_instrument >= ? 25 | AND a.id_instrument <= ? 26 | AND EXISTS ( SELECT 1 27 | FROM cfe.instrument_ref b 28 | INNER JOIN cfe.instrument_collateral_hst c 29 | ON b.id_instrument_ref = c.id_instrument_ref 30 | WHERE b.id_instrument = a.id_instrument ) 31 | ; 32 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/MySQLTest.sql: -------------------------------------------------------------------------------- 1 | -- GROUP_CONCAT 2 | SELECT Group_Concat( DISTINCT Trim( Concat(m.title, ' ', m.firstname, ' ', m.lastname) ) 3 | ORDER BY p2m.manufacturer_type_id ASC 4 | SEPARATOR ' ' ) AS manufacturer_name 5 | FROM product_to_manufacturer p2m 6 | LEFT JOIN manufacturer m 7 | ON m.manufacturer_id = p2m.manufacturer_id 8 | WHERE p2m.product_id = 574768 9 | ; 10 | 11 | -- WITHOUT A FROM ITEM 12 | -- @JSQLFormatter(indentWidth=2, keywordSpelling=LOWER, functionSpelling=CAMEL, objectSpelling=LOWER, separation=BEFORE) 13 | select case 14 | when ( select ccp.campaign_id 15 | from campaign_constraint_product ccp 16 | inner join campaign_free_shipping_products_visibility cfspv 17 | on cfspv.campaign_id = ccp.campaign_id 18 | where ccp.product_id = 530729 19 | and cfspv.status = 1 20 | union 21 | select cap.campaign_id 22 | from campaign_action_product cap 23 | inner join campaign_free_shipping_products_visibility cfspv 24 | on cfspv.campaign_id = cap.campaign_id 25 | where cap.product_id = 530729 26 | and cfspv.status = 1 ) is not null 27 | then 1 28 | else 0 29 | end as is_free_shipping 30 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardAlterTest.sql: -------------------------------------------------------------------------------- 1 | 2 | -- ALTER TABLE ADD FOREIGN KEY 3 | ALTER TABLE cfe.ledger_acc_entry_manual 4 | ADD FOREIGN KEY (id_manual_posting_batch) 5 | REFERENCES manual_posting_batch (id_manual_posting_batch) 6 | ; 7 | 8 | -- ALTER TABLE DROP COLUMN 9 | ALTER TABLE risk.collateral 10 | DROP COLUMN id_status 11 | ; 12 | 13 | -- ORACLE DROP MULTIPLE COLUMNS 14 | ALTER TABLE risk.collateral 15 | DROP (id_status, city ) 16 | ; 17 | 18 | -- ORACLE DROP MANY MULTIPLE COLUMNS 19 | ALTER TABLE risk.collateral 20 | DROP ( id_status 21 | , city 22 | , column3 23 | , column4 ) 24 | ; 25 | 26 | -- ALTER TABLE ADD COLUMN 27 | ALTER TABLE risk.collateral 28 | ADD COLUMN id_status VARCHAR (1) NULL 29 | ; 30 | 31 | -- ALTER TABLE ALTER COLUMN 32 | ALTER TABLE risk.collateral 33 | ALTER COLUMN id_status VARCHAR (1) NOT NULL 34 | ; 35 | 36 | -- ORACLE ALTER TABLE ADD COLUMN 37 | ALTER TABLE risk.collateral 38 | ADD id_status VARCHAR (1) NULL 39 | ; 40 | 41 | -- ORACLE ALTER TABLE MODIFY 42 | ALTER TABLE risk.collateral 43 | MODIFY id_status VARCHAR (1) NOT NULL 44 | ; 45 | 46 | -- ORACLE ADD MULTIPLE COLUMNS 47 | ALTER TABLE customers 48 | ADD ( customer_name VARCHAR2 (45) 49 | , city VARCHAR2 (40) DEFAULT 'SEATTLE') 50 | ; 51 | 52 | -- ORACLE MODIFY MULTIPLE COLUMNS 53 | ALTER TABLE customers 54 | MODIFY ( customer_name VARCHAR2 (100) NOT NULL 55 | , city VARCHAR2 (75) DEFAULT 'SEATTLE' NOT NULL) 56 | ; 57 | 58 | -- RENAME 59 | ALTER TABLE departments 60 | RENAME COLUMN department_name TO dept_name 61 | ; 62 | 63 | -- issue14 64 | ALTER TABLE table1 65 | RENAME TO table2 66 | ; 67 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardCommentTest.sql: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------------------------------------------------ 2 | -- CONFIGURATION 3 | ------------------------------------------------------------------------------------------------------------------------ 4 | 5 | -- UPDATE CALENDAR 6 | UPDATE cfe.calendar 7 | SET year_offset = ? /* year offset */ 8 | , settlement_shift = ? /* settlement shift */ 9 | , friday_is_holiday = ? /* friday is a holiday */ 10 | , saturday_is_holiday = ? /* saturday is a holiday */ 11 | , sunday_is_holiday = ? /* sunday is a holiday */ 12 | WHERE id_calendar = ? 13 | ; 14 | 15 | -- BOTH CLAUSES PRESENT 'with a string' AND "a field" 16 | MERGE /*+ PARALLEL */ INTO test1 /*the target table*/ a 17 | USING all_objects /*the source table*/ 18 | ON ( /*joins in()!;*/ a.object_id = b.object_id ) 19 | -- INSERT CLAUSE; 20 | WHEN /*comments between keywords!;*/ NOT MATCHED THEN 21 | INSERT ( object_id /*ID Column*/ 22 | , status /*Status Column*/ ) 23 | VALUES ( b.object_id 24 | , b.status ) 25 | /* UPDATE CLAUSE 26 | WITH A WHERE CONDITION */ 27 | WHEN MATCHED THEN /* Lets rock */ 28 | UPDATE SET a.status = '/*this is no comment!*/ and -- this ain''t either;' 29 | WHERE b."--status;" != 'VALID' 30 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardCreateIndexTest.sql: -------------------------------------------------------------------------------- 1 | 2 | -- SIMPLE 3 | CREATE INDEX cfe.version_info_idx1 4 | ON cfe.version_info( major_version 5 | , minor_version 6 | , patch_level ) 7 | ; 8 | 9 | -- UNIQUE 10 | CREATE UNIQUE INDEX cfe.interest_period_idx1 11 | ON cfe.interest_period( id_instrument, change_date ) 12 | ; 13 | 14 | -- MANY COLUMNS 15 | CREATE UNIQUE INDEX cfe.version_info_idx2 16 | ON cfe.version_info( major_version 17 | , minor_version 18 | , patch_level 19 | , major_version 20 | , minor_version 21 | , patch_level ) 22 | ; 23 | 24 | -- MANY COLUMNS WITH TAIL OPTIONS 25 | CREATE UNIQUE INDEX cfe.version_info_idx2 26 | ON cfe.version_info( major_version 27 | , minor_version 28 | , patch_level 29 | , major_version 30 | , minor_version 31 | , patch_level ) PARALLEL COMPRESS NOLOGGING 32 | ; 33 | 34 | 35 | -- Z MANY COLUMNS WITH TAIL OPTIONS 36 | -- @JSQLFormatter(indentWidth=2, keywordSpelling=LOWER, functionSpelling=KEEP, objectSpelling=UPPER, separation=AFTER) 37 | create unique index CFE.VERSION_INFO_IDX2 38 | on CFE.VERSION_INFO( MAJOR_VERSION, 39 | MINOR_VERSION, 40 | PATCH_LEVEL, 41 | MAJOR_VERSION, 42 | MINOR_VERSION, 43 | PATCH_LEVEL ) parallel compress nologging 44 | ; 45 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardCreateTableTest.sql: -------------------------------------------------------------------------------- 1 | 2 | -- CREATE TABLE CFE.INTEREST_PERIOD 3 | CREATE TABLE cfe.interest_period ( 4 | id_instrument VARCHAR (40) NOT NULL 5 | , id_fixingmode NUMBER (5) DEFAULT 0 NOT NULL 6 | , fixing_date DATE 7 | , change_date DATE 8 | , base_rate VARCHAR (12) 9 | , base_margin_rate DECIMAL (12,9) 10 | , par_rate VARCHAR (12) 11 | , par_margin_rate DECIMAL (12,9) 12 | , id_payment_convention VARCHAR (12) 13 | , id_day_count_convention VARCHAR (12) 14 | , id_day_incl_convention VARCHAR (12) 15 | , fix_amount DECIMAL (23,5) 16 | , id_currency_fix_amount VARCHAR (3) 17 | , id_script VARCHAR (12) 18 | ) 19 | ; 20 | 21 | -- SIMPLE 22 | CREATE TABLE employees ( 23 | employee_number INT NOT NULL 24 | , employee_name CHAR (50) NOT NULL 25 | , department_id INT 26 | , salary INT 27 | , PRIMARY KEY ( employee_number ) 28 | , UNIQUE ( employee_name ) 29 | , FOREIGN KEY ( department_id ) 30 | REFERENCES departments ( department_id ) 31 | ) PARALLEL COMPRESS NOLOGGING 32 | ; 33 | 34 | -- COMPLEX 35 | CREATE TABLE employees ( 36 | employee_number INT NOT NULL 37 | , employee_name CHAR (50) NOT NULL 38 | , department_id INT 39 | , salary INT 40 | , CONSTRAINT employees_pk 41 | PRIMARY KEY ( employee_number ) 42 | , CONSTRAINT fk_departments 43 | FOREIGN KEY ( department_id ) 44 | REFERENCES departments ( department_id ) 45 | ) PARALLEL COMPRESS NOLOGGING 46 | ; 47 | 48 | -- COMPLEX WITH MANY REFERENCES 49 | CREATE TABLE employees ( 50 | employee_number INT NOT NULL 51 | , employee_name CHAR (50) NOT NULL 52 | , department_id INT 53 | , salary INT 54 | , CONSTRAINT employees_pk 55 | PRIMARY KEY ( employee_number 56 | , employee_name 57 | , department_id ) 58 | , CONSTRAINT fk_departments 59 | FOREIGN KEY ( employee_number 60 | , employee_name 61 | , department_id ) 62 | REFERENCES departments ( employee_number 63 | , employee_name 64 | , department_id ) 65 | ) PARALLEL COMPRESS NOLOGGING 66 | ; 67 | 68 | -- CREATE TABLE CFE.RECONCILIATION_NOMINAL_HST 2 69 | CREATE TABLE cfe.reconciliation_nominal_hst PARALLEL COMPRESS NOLOGGING 70 | AS ( SELECT /*+ PARALLEL */ 71 | ( SELECT id_execution_ref 72 | FROM cfe.execution_ref c 73 | INNER JOIN cfe.execution_v d 74 | ON c.value_date = d.value_date 75 | AND c.posting_date = d.posting_date 76 | AND d.flag = 'L' ) id_execution_ref 77 | , b.id_instrument_ref 78 | , a.value_date 79 | , a.nominal_balance 80 | FROM cfe.reconciliation_nominal a 81 | INNER JOIN cfe.instrument_ref b 82 | ON a.id_instrument = b.id_instrument ) 83 | ; 84 | 85 | -- Z COMPLEX WITH MANY REFERENCES 86 | -- @JSQLFormatter(indentWidth=2, keywordSpelling=LOWER, functionSpelling=KEEP, objectSpelling=UPPER, separation=AFTER) 87 | create table EMPLOYEES ( 88 | EMPLOYEE_NUMBER int not null, 89 | EMPLOYEE_NAME char (50) not null, 90 | DEPARTMENT_ID int, 91 | SALARY int, 92 | constraint EMPLOYEES_PK 93 | primary key ( EMPLOYEE_NUMBER, 94 | EMPLOYEE_NAME, 95 | DEPARTMENT_ID ), 96 | constraint FK_DEPARTMENTS 97 | foreign key ( EMPLOYEE_NUMBER, 98 | EMPLOYEE_NAME, 99 | DEPARTMENT_ID ) 100 | references DEPARTMENTS ( EMPLOYEE_NUMBER, 101 | EMPLOYEE_NAME, 102 | DEPARTMENT_ID ) 103 | ) parallel compress nologging 104 | ; 105 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardCreateViewTest.sql: -------------------------------------------------------------------------------- 1 | 2 | -- VIEW 1 3 | CREATE OR REPLACE VIEW cfe.interest_period_on_value_day 4 | AS SELECT /*+ PARALLEL */ 5 | a.value_date 6 | , d.id_instrument 7 | , d.id_fixingmode 8 | , d.fixing_date 9 | , Coalesce( d.change_date, b.end_date ) change_date 10 | , d.base_rate 11 | , d.base_margin_rate 12 | , d.par_rate 13 | , d.par_margin_rate 14 | , d.id_payment_convention 15 | , d.id_day_count_convention 16 | , d.id_day_incl_convention 17 | , d.fix_amount 18 | , d.id_currency_fix_amount 19 | , d.id_script 20 | FROM ( SELECT value_date 21 | , posting_date 22 | FROM cfe.execution e 23 | WHERE id_status = 'R' 24 | AND value_date = ( SELECT Max( value_date ) 25 | FROM cfe.execution 26 | WHERE id_status = 'R' ) 27 | AND posting_date = ( SELECT Max( posting_date ) 28 | FROM cfe.execution 29 | WHERE id_status = 'R' 30 | AND value_date = e.value_date ) ) a 31 | INNER JOIN cfe.instrument_hst b 32 | ON a.value_date = b.value_date 33 | AND a.posting_date = b.posting_date 34 | INNER JOIN cfe.instrument_ref c 35 | ON b.id_instrument_ref = c.id_instrument_ref 36 | INNER JOIN cfe.interest_period d 37 | ON d.id_instrument = c.id_instrument 38 | AND a.value_date <= Coalesce( d.change_date, b.end_date ) 39 | WHERE Coalesce( d.change_date, b.end_date ) = ( SELECT Min( Coalesce( change_date, b.end_date ) ) 40 | FROM cfe.interest_period 41 | WHERE id_instrument = d.id_instrument 42 | AND a.value_date <= Coalesce( change_date, b.end_date ) ) 43 | ORDER BY 2 44 | , 1 45 | , 4 46 | ; 47 | 48 | -- VIEW 2 49 | CREATE OR REPLACE VIEW cfe.execution_v 50 | AS SELECT /*+ PARALLEL */ 51 | e.start_timestamp 52 | , e.end_timestamp 53 | , EXTRACT( hour FROM 54 | e.end_timestamp 55 | - e.start_timestamp ) || ':' 56 | || Lpad( EXTRACT( minute FROM e.end_timestamp - e.start_timestamp ), 2, '0' ) duration 57 | , e.value_date 58 | , e.posting_date 59 | , CASE 60 | WHEN EXTRACT( year FROM e1.value_date ) > EXTRACT( year FROM e.value_date ) 61 | THEN 'Y' 62 | WHEN To_Char( e1.value_date, 'Q' ) > To_Char( e.value_date, 'Q' ) 63 | THEN 'Q' 64 | WHEN EXTRACT( month FROM e1.value_date ) > EXTRACT( month FROM e.value_date ) 65 | THEN 'M' 66 | WHEN To_Char( e1.value_date, 'IW' ) > To_Char( e.value_date, 'IW' ) 67 | THEN 'W' 68 | WHEN e1.value_date IS NULL 69 | AND e.id_status = 'R' 70 | THEN 'L' 71 | END flag 72 | , e.value_date_p 73 | , e.value_date_pp 74 | , e.id_status 75 | FROM cfe.execution e 76 | LEFT JOIN cfe.execution e1 77 | ON e.value_date < e1.value_date 78 | AND e.id_status IN ( 'R', 'H' ) 79 | AND e1.id_status IN ( 'R', 'H' ) 80 | WHERE ( e1.value_date = ( SELECT Min( value_date ) 81 | FROM cfe.execution 82 | WHERE id_status IN ( 'R', 'H' ) 83 | AND value_date > e.value_date ) 84 | OR e1.value_date IS NULL ) 85 | ORDER BY e.posting_date DESC 86 | , e.value_date DESC 87 | ; 88 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardDeleteTest.sql: -------------------------------------------------------------------------------- 1 | 2 | -- DELETE LEDGER BRANCH BALANCE 3 | DELETE FROM cfe.ledger_branch_balance 4 | WHERE ( value_date, posting_date ) = ( SELECT value_date 5 | , posting_date 6 | FROM cfe.execution 7 | WHERE id_status = 'R' 8 | AND value_date = :VALUE_DATE ) 9 | ; 10 | 11 | -- DELETE WITH MANY ITEMS 12 | DELETE FROM cfe.ledger_branch_balance 13 | WHERE ( value_date, posting_date, something_else ) = ( SELECT value_date 14 | , posting_date 15 | , something_else 16 | FROM cfe.execution 17 | WHERE id_status = 'R' 18 | AND value_date = :VALUE_DATE ) 19 | ; 20 | 21 | -- DELETE WITH MORE ITEMS 22 | DELETE FROM cfe.ledger_branch_balance 23 | WHERE ( value_date 24 | , posting_date 25 | , something_else 26 | , value_date ) = ( SELECT value_date 27 | , posting_date 28 | , something_else 29 | , value_date 30 | FROM cfe.execution 31 | WHERE id_status = 'R' 32 | AND value_date = :VALUE_DATE ) 33 | ; 34 | 35 | -- DELETE WITH EVEN MORE ITEMS 36 | DELETE FROM cfe.ledger_branch_balance 37 | WHERE ( value_date, posting_date, something_else 38 | , value_date, posting_date, something_else ) = ( SELECT value_date 39 | , posting_date 40 | , something_else 41 | , value_date 42 | , posting_date 43 | , something_else 44 | FROM cfe.execution 45 | WHERE id_status = 'R' 46 | AND value_date = :VALUE_DATE ) 47 | ; 48 | 49 | -- DELETE INSTRUMENT HST AFTER VALUE_DATE_P 50 | DELETE /*+ PARALLEL INDEX_FFS(A, INSTRUMENT_HST_IDX1) */ FROM cfe.instrument_hst a 51 | WHERE ( value_date, posting_date ) IN ( SELECT value_date 52 | , posting_date 53 | FROM cfe.execution 54 | WHERE posting_date > ( SELECT Max( posting_date ) 55 | FROM cfe.execution 56 | WHERE id_status = 'R' 57 | AND value_date <= :value_date_p ) 58 | OR ( SELECT Max( posting_date ) 59 | FROM cfe.execution 60 | WHERE id_status = 'R' 61 | AND value_date <= :value_date_p ) IS NULL ) 62 | ; 63 | 64 | -- DELETE REDUNDANT INSTRUMENT COLLATERAL HST 2 65 | DELETE FROM cfe.instrument_collateral_hst t1 66 | WHERE EXISTS ( SELECT 1 67 | FROM cfe.instrument_collateral a 68 | INNER JOIN cfe.collateral_ref b 69 | ON a.id_collateral = b.id_collateral 70 | INNER JOIN cfe.instrument_ref c 71 | ON a.id_instrument = c.id_instrument 72 | WHERE b.id_collateral_ref = t1.id_collateral_ref 73 | AND c.id_instrument_ref = t1.id_instrument_ref 74 | AND a.valid_date = t1.valid_date ) 75 | ; 76 | 77 | -- DELETE ACCOUNT ENTRIES AFTER VALUE_DATE_P 78 | DELETE FROM cfe.ledger_account_entry a 79 | WHERE posting_date IN ( SELECT posting_date 80 | FROM cfe.execution 81 | WHERE posting_date > ( SELECT Max( posting_date ) 82 | FROM cfe.execution 83 | WHERE id_status = 'R' 84 | AND value_date <= :value_date_p ) 85 | OR ( SELECT Max( posting_date ) 86 | FROM cfe.execution 87 | WHERE id_status = 'R' 88 | AND value_date <= :value_date_p ) IS NULL ) 89 | AND reversed = '0' 90 | ; 91 | 92 | -- DELETE WITH 93 | WITH scope AS ( 94 | SELECT * 95 | FROM cfe.accounting_scope 96 | WHERE id_status = 'C' 97 | AND id_accounting_scope_code = :SCOPE ) 98 | DELETE FROM cfe.accounting_scope a 99 | WHERE NOT EXISTS ( SELECT 1 100 | FROM scope ) 101 | ; 102 | -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardInsertTest.sql: -------------------------------------------------------------------------------- 1 | 2 | -- INSERT COUNTERPARTY COUNTERPARTY RELATIONSHIP 3 | INSERT INTO risk.counterparty_counterparty 4 | VALUES ( :id_counterparty_ref, :id_counterparty_beneficiary, :id_instrument_guarantee 5 | , :priority, :type, :description 6 | , :limit_amout, :id_currency, :end_date ) 7 | ; 8 | 9 | -- INSERT RATIO COLLECTION RATIOS 10 | INSERT INTO risk.counterparty_ratio 11 | VALUES ( ?, ?, ? ) 12 | ; 13 | 14 | -- INSERT TMP_CCF 15 | INSERT INTO risk.tmp_ccf ( 16 | "ID_INSTRUMENT" 17 | , "TENOR" 18 | , "STATUS" 19 | , "OBSERVATION_DATE" 20 | , "BALANCE" 21 | , "LIMIT" 22 | , "DR_BALANCE" 23 | , "OPEN_LIMIT" ) 24 | SELECT '1000042339' /* ID_INSTRUMENT */ 25 | , 0 /* TENOR */ 26 | , 'DEFAULT' /* STATUS */ 27 | , {d '2020-02-27'} /* OBSERVATION_DATE */ 28 | , - 142574953.65 /* BALANCE */ 29 | , 300000000 /* LIMIT */ 30 | , - 142574953.65 /* DR_BALANCE */ 31 | , 157425046.35 /* OPEN_LIMIT */ 32 | FROM dual 33 | ; 34 | 35 | -- APPEND ATTRIBUTE VALUE REF 36 | INSERT INTO cfe.attribute_value_ref 37 | SELECT cfe.id_attribute_value_ref.nextval 38 | , attribute_value 39 | FROM ( SELECT DISTINCT 40 | a.attribute_value 41 | FROM cfe.instrument_attribute a 42 | LEFT JOIN cfe.attribute_value_ref b 43 | ON a.attribute_value = b.attribute_value 44 | WHERE b.attribute_value IS NULL ) a 45 | ; 46 | 47 | -- INSERT WITH 48 | WITH scope AS ( 49 | SELECT * 50 | FROM cfe.accounting_scope 51 | WHERE id_status = 'C' 52 | AND id_accounting_scope_code = :SCOPE ) 53 | INSERT INTO cfe.accounting_scope a 54 | SELECT * 55 | FROM scope 56 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardOffsetLimitTest.sql: -------------------------------------------------------------------------------- 1 | -- SIMPLE LIMIT 2 | SELECT p.* 3 | FROM product p 4 | LEFT JOIN product_description pd 5 | ON ( p.product_id = pd.product_id ) 6 | LEFT JOIN product_type_google_category ptgc 7 | ON ( p.product_type_id = ptgc.product_type_id ) 8 | LEFT JOIN product_google_custom_label pgcl 9 | ON ( p.product_id = pgcl.product_id ) 10 | WHERE p.status = 1 11 | AND pd.language_id = 2 12 | AND p.product_id IN ( SELECT product_id 13 | FROM cj_googleshopping_products ) 14 | ORDER BY date_available DESC 15 | , p.purchased DESC 16 | LIMIT 200000 17 | ; 18 | 19 | -- LIMIT OFFSET EXPRESSIONS 20 | SELECT p.* 21 | FROM product p 22 | LIMIT '200000' 23 | OFFSET '5' 24 | ; 25 | 26 | -- MYSQL LIMIT OFFSET EXPRESSIONS 27 | SELECT p.* 28 | FROM product p 29 | LIMIT 5, 2000 30 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardTruncateTest.sql: -------------------------------------------------------------------------------- 1 | 2 | -- TRUNCATE 1 3 | TRUNCATE TABLE cfe.execution 4 | ; 5 | 6 | -- TRUNCATE 2 7 | TRUNCATE TABLE cfe.execution CASCADE 8 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardUpdateTest.sql: -------------------------------------------------------------------------------- 1 | 2 | -- UPDATE COUNTERPARTY 3 | UPDATE risk.counterparty 4 | SET id_counterparty = :id_counterparty 5 | , label = :label 6 | , description = :description 7 | , id_counterparty_group_type = :id_counterparty_group_type 8 | , id_counterparty_type = :id_counterparty_type 9 | , id_counterparty_sub_type = :id_counterparty_sub_type 10 | , id_country_group = :id_country_group 11 | , id_country = :id_country 12 | , id_country_state = :id_country_state 13 | , id_district = :id_district 14 | , id_city = :id_city 15 | , id_industrial_sector = :id_industrial_sector 16 | , id_industrial_sub_sector = :id_industrial_sub_sector 17 | , block_auto_update_flag = :block_auto_update_flag 18 | , id_user_editor = :id_user_editor 19 | , id_organization_unit = :id_organization_unit 20 | , id_status = :id_status 21 | , update_timestamp = current_timestamp 22 | WHERE id_counterparty_ref = :id_counterparty_ref 23 | ; 24 | 25 | -- UPDATE COLLATERAL_TYPE 26 | UPDATE common.collateral_type 27 | SET hair_cut = least 28 | WHERE id_collateral_type_ref IN ( SELECT id_collateral_type_ref 29 | FROM common.collateral_type a 30 | WHERE id_status IN ( 'C', 'H', 'C' 31 | , 'H', 'C', 'H' 32 | , 'C', 'H' ) 33 | AND id_collateral_type_ref = ( SELECT Max( id_collateral_type_ref ) 34 | FROM common.collateral_type 35 | WHERE id_status IN ( 'C', 'H' ) 36 | AND id_collateral_type = a.id_collateral_type ) ) 37 | ; 38 | 39 | -- UPDATE COUNTERPARTY_INSTRUMENT 40 | UPDATE risk.counterparty_instrument a1 41 | SET ( priority 42 | , type 43 | , description 44 | , limit_amout 45 | , id_currency 46 | , end_date ) = ( SELECT a.priority 47 | , a.type 48 | , a.description 49 | , a.limit_amout 50 | , a.id_currency 51 | , a.end_date 52 | FROM risk.imp_counterparty_instrument a 53 | INNER JOIN risk.counterparty b 54 | ON a.id_counterparty = b.id_counterparty 55 | AND b.id_status = 'C' 56 | INNER JOIN risk.instrument c 57 | ON a.id_instrument_beneficiary = c.id_instrument 58 | AND c.id_status = 'C' 59 | INNER JOIN risk.counterparty_instrument e 60 | ON b.id_counterparty_ref = e.id_counterparty_ref 61 | AND e.id_instrument_beneficiary = a.id_instrument_beneficiary 62 | AND e.id_instrument_guarantee = a.id_instrument_guarantee 63 | WHERE e.id_counterparty_ref = a1.id_counterparty_ref 64 | AND e.id_instrument_beneficiary = a1.id_instrument_beneficiary 65 | AND e.id_instrument_guarantee = a1.id_instrument_guarantee ) 66 | WHERE EXISTS ( SELECT a.priority 67 | , a.type 68 | , a.description 69 | , a.limit_amout 70 | , a.id_currency 71 | , a.end_date 72 | FROM risk.imp_counterparty_instrument a 73 | INNER JOIN risk.counterparty b 74 | ON a.id_counterparty = b.id_counterparty 75 | AND b.id_status = 'C' 76 | INNER JOIN risk.instrument c 77 | ON a.id_instrument_beneficiary = c.id_instrument 78 | AND c.id_status = 'C' 79 | INNER JOIN risk.counterparty_instrument e 80 | ON b.id_counterparty_ref = e.id_counterparty_ref 81 | AND e.id_instrument_beneficiary = a.id_instrument_beneficiary 82 | AND e.id_instrument_guarantee = a.id_instrument_guarantee 83 | WHERE e.id_counterparty_ref = a1.id_counterparty_ref 84 | AND e.id_instrument_beneficiary = a1.id_instrument_beneficiary 85 | AND e.id_instrument_guarantee = a1.id_instrument_guarantee ) 86 | ; 87 | 88 | -- UPDATE SETS ISSUE 1316 89 | UPDATE prpjpaymentbill b 90 | SET ( b.packagecode 91 | , b.packageremark 92 | , b.agentcode ) = ( SELECT p.payrefreason 93 | , p.classcode 94 | , p.riskcode 95 | FROM prpjcommbill p 96 | WHERE p.policertiid = 'SDDH200937010330006366' ) /* this is supposed to be UpdateSet 1 */ 97 | , b.payrefnotype = '05' /* this is supposed to be UpdateSet 2 */ 98 | , b.packageunit = '4101170402' /* this is supposed to be UpdateSet 3 */ 99 | WHERE b.payrefno = 'B370202091026000005' 100 | ; 101 | 102 | -- UPDATE START JOINS 103 | UPDATE sc_borrower b 104 | INNER JOIN sc_credit_apply a 105 | ON a.borrower_id = b.id 106 | SET b.name = '0.7505105896846266' 107 | , a.credit_line = a.credit_line + 1 108 | WHERE b.id = 3 109 | ; 110 | 111 | -- UPDATE JOINS 112 | UPDATE table1 113 | SET columna = 5 114 | FROM table1 115 | LEFT JOIN table2 116 | ON col1 = col2 117 | ; 118 | 119 | -- UPDATE WITH 120 | WITH s AS ( 121 | SELECT a.priority 122 | , a.type 123 | , a.description 124 | , a.limit_amout 125 | , a.id_currency 126 | , a.end_date 127 | FROM risk.imp_counterparty_instrument a 128 | INNER JOIN risk.counterparty b 129 | ON a.id_counterparty = b.id_counterparty 130 | AND b.id_status = 'C' 131 | INNER JOIN risk.instrument c 132 | ON a.id_instrument_beneficiary = c.id_instrument 133 | AND c.id_status = 'C' 134 | INNER JOIN risk.counterparty_instrument e 135 | ON b.id_counterparty_ref = e.id_counterparty_ref 136 | AND e.id_instrument_beneficiary = a.id_instrument_beneficiary 137 | AND e.id_instrument_guarantee = a.id_instrument_guarantee 138 | WHERE e.id_counterparty_ref = a1.id_counterparty_ref 139 | AND e.id_instrument_beneficiary = a1.id_instrument_beneficiary 140 | AND e.id_instrument_guarantee = a1.id_instrument_guarantee ) 141 | UPDATE risk.counterparty_instrument a1 142 | SET ( priority 143 | , type 144 | , description 145 | , limit_amout 146 | , id_currency 147 | , end_date ) = ( SELECT * 148 | FROM s ) 149 | WHERE EXISTS ( SELECT a.priority 150 | , a.type 151 | , a.description 152 | , a.limit_amout 153 | , a.id_currency 154 | , a.end_date 155 | FROM risk.imp_counterparty_instrument a 156 | INNER JOIN risk.counterparty b 157 | ON a.id_counterparty = b.id_counterparty 158 | AND b.id_status = 'C' 159 | INNER JOIN risk.instrument c 160 | ON a.id_instrument_beneficiary = c.id_instrument 161 | AND c.id_status = 'C' 162 | INNER JOIN risk.counterparty_instrument e 163 | ON b.id_counterparty_ref = e.id_counterparty_ref 164 | AND e.id_instrument_beneficiary = a.id_instrument_beneficiary 165 | AND e.id_instrument_guarantee = a.id_instrument_guarantee 166 | WHERE e.id_counterparty_ref = a1.id_counterparty_ref 167 | AND e.id_instrument_beneficiary = a1.id_instrument_beneficiary 168 | AND e.id_instrument_guarantee = a1.id_instrument_guarantee ) 169 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/standard/StandardValueStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- PREPARE TABLE 2 | CREATE TABLE sample_data ( 3 | "DAY" INT 4 | , "VALUE" INT 5 | ) 6 | ; 7 | 8 | -- SIMPLE EXPRESSION LIST WITH BRACKETS 9 | WITH sample_data ( "DAY" ) 10 | AS ( VALUES ( 0, 1, 2 ) ) 11 | SELECT "DAY" 12 | FROM sample_data 13 | ; 14 | 15 | -- MULTIPLE EXPRESSION LIST WITH BRACKETS 16 | WITH sample_data ( "DAY", "VALUE" ) 17 | AS ( VALUES ( ( 0, 13 ), ( 1, 12 ), ( 2, 15 ) 18 | , ( 3, 4 ), ( 4, 8 ), ( 5, 16 ) ) ) 19 | SELECT "DAY" 20 | , "VALUE" 21 | FROM sample_data 22 | ; 23 | 24 | -- SIMPLE EXPRESSION LIST WITHOUT BRACKETS 25 | WITH sample_data ( "DAY" ) 26 | AS ( VALUES 0, 1, 2 ) 27 | SELECT "DAY" 28 | FROM sample_data 29 | ; 30 | 31 | -- MULTIPLE EXPRESSION LIST WITHOUT BRACKETS 32 | WITH sample_data ( "DAY", "VALUE" ) 33 | AS ( VALUES ( 0, 13 ), ( 1, 12 ), ( 2, 15 ) 34 | , ( 3, 4 ), ( 4, 8 ), ( 5, 16 ) ) 35 | SELECT "DAY" 36 | , "VALUE" 37 | FROM sample_data 38 | ; 39 | 40 | -- VALUE LIST UNION SELECT 41 | WITH split ( word 42 | , str 43 | , hascomma ) 44 | AS ( VALUES ( '', 'Auto,A,1234444', 1 ) 45 | UNION ALL 46 | SELECT Substr( str, 0, CASE 47 | WHEN Instr( str, ',' ) 48 | THEN Instr( str, ',' ) 49 | ELSE Length( str ) + 1 50 | END ) 51 | , Ltrim( Substr( str, Instr( str, ',' ) ), ',' ) 52 | , Instr( str, ',' ) 53 | FROM split 54 | WHERE hascomma ) 55 | SELECT Trim( word ) 56 | FROM split 57 | WHERE word != '' 58 | ; -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/wip/EmptyStatementTest.sql: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | /** 7 | * Author: are 8 | * Created: May 15, 2021 9 | */ -------------------------------------------------------------------------------- /src/test/resources/com/manticore/jsqlformatter/wip/Issue0003.sql: -------------------------------------------------------------------------------- 1 | -- Leading or Trailing comments 2 | 3 | /* leading comment */ 4 | 5 | -- another one 6 | 7 | -- comment for the statement 8 | select 1 from dual; -- where a = b 9 | 10 | -- trailing comment -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/expression/JsonFunctionTest.sql: -------------------------------------------------------------------------------- 1 | -- testObjectMySQL 2 | select json_object('person',tp.person,'account',tp.account)obj 3 | ; 4 | 5 | -- testObjectWithExpression 6 | select json_object(key 'foo' value cast(bar as varchar(40)),key 'foo' value bar)from dual 7 | ; 8 | 9 | -- testObjectWithExpression 10 | select json_arrayagg(obj)from(select trt.relevance_id,json_object('id',cast(trt.id as char),'taskname',trt.task_name,'openstatus',trt.open_status,'tasksort',trt.task_sort)as obj from tb_review_task trt order by trt.task_sort asc) 11 | ; 12 | 13 | -- testArray 14 | select json_array((select*from dual))from dual 15 | ; 16 | 17 | -- testArray 18 | select json_array(1,2,3)from dual 19 | ; 20 | 21 | -- testArray 22 | select json_array("v0")from dual 23 | ; 24 | 25 | -- testObjectAgg 26 | select json_objectagg(key foo value bar)from dual 27 | ; 28 | 29 | -- testObjectAgg 30 | select json_objectagg(foo:bar)from dual 31 | ; 32 | 33 | -- testObjectAgg 34 | select json_objectagg(foo:bar format json)from dual 35 | ; 36 | 37 | -- testObjectAgg 38 | select json_objectagg(key foo value bar null on null)from dual 39 | ; 40 | 41 | -- testObjectAgg 42 | select json_objectagg(key foo value bar absent on null)from dual 43 | ; 44 | 45 | -- testObjectAgg 46 | select json_objectagg(key foo value bar with unique keys)from dual 47 | ; 48 | 49 | -- testObjectAgg 50 | select json_objectagg(key foo value bar without unique keys)from dual 51 | ; 52 | 53 | -- testObjectAgg 54 | select json_objectagg(key foo value bar null on null with unique keys)from dual 55 | ; 56 | 57 | -- testObjectAgg 58 | select json_objectagg(key foo value bar null on null with unique keys)filter(where name='raj')from dual 59 | ; 60 | 61 | -- testObjectAgg 62 | select json_objectagg(key foo value bar null on null with unique keys)over(partition by name)from dual 63 | ; 64 | 65 | -- testObjectAgg 66 | select json_objectagg(key foo value bar null on null with unique keys)filter(where name='raj')over(partition by name)from dual 67 | ; 68 | 69 | -- testArrayAgg 70 | select json_arrayagg(a)from dual 71 | ; 72 | 73 | -- testArrayAgg 74 | select json_arrayagg(a order by a)from dual 75 | ; 76 | 77 | -- testArrayAgg 78 | select json_arrayagg(a null on null)from dual 79 | ; 80 | 81 | -- testArrayAgg 82 | select json_arrayagg(a format json)from dual 83 | ; 84 | 85 | -- testArrayAgg 86 | select json_arrayagg(a format json null on null)from dual 87 | ; 88 | 89 | -- testArrayAgg 90 | select json_arrayagg(a format json absent on null)from dual 91 | ; 92 | 93 | -- testArrayAgg 94 | select json_arrayagg(a format json absent on null)filter(where name='raj')from dual 95 | ; 96 | 97 | -- testArrayAgg 98 | select json_arrayagg(a format json absent on null)over(partition by name)from dual 99 | ; 100 | 101 | -- testArrayAgg 102 | select json_arrayagg(a format json absent on null)filter(where name='raj')over(partition by name)from dual 103 | ; 104 | 105 | -- testArrayAgg 106 | select json_arrayagg(json_array("v0")order by "t"."v0")from dual 107 | ; 108 | 109 | -- testObjectIssue1504 110 | select json_object(key 'person' value tp.account)obj 111 | ; 112 | 113 | -- testObjectIssue1504 114 | select json_object(key 'person' value tp.account,key 'person' value tp.account)obj 115 | ; 116 | 117 | -- testObjectIssue1504 118 | select json_object('person':tp.account)obj 119 | ; 120 | 121 | -- testObjectIssue1504 122 | select json_object('person':tp.account,'person':tp.account)obj 123 | ; 124 | 125 | -- testObjectIssue1504 126 | select json_object('person':'1','person':'2')obj 127 | ; 128 | 129 | -- testObjectIssue1504 130 | select json_object('person' value tp.person,'account' value tp.account)obj 131 | ; 132 | 133 | -- testIssue1260 134 | select cast((select coalesce(json_arrayagg(json_array("v0")order by "t"."v0"),json_array(null on null))from(select 2 "v0" union select 4 "id")"t")as text) 135 | ; 136 | 137 | -- testIssue1260 138 | select(select coalesce(cast(('['||listagg(json_object(key 'v0' value "v0"),',')||']')as varchar(32672)),json_array())from(select cast(null as timestamp)"v0" from sysibm.dual union all select timestamp '2000-03-15 10:15:00.0' "a" from sysibm.dual)"t")from sysibm.dual 139 | ; 140 | 141 | -- testIssue1371 142 | select json_object('{a,1,b,2}') 143 | ; 144 | 145 | -- testIssue1371 146 | select json_object('{{a,1},{b,2}}') 147 | ; 148 | 149 | -- testIssue1371 150 | select json_object('{a,b}','{1,2 }') 151 | ; 152 | 153 | -- testObject 154 | select json_object(key 'foo' value bar,key 'foo' value bar)from dual 155 | ; 156 | 157 | -- testObject 158 | select json_object('foo':bar,'foo':bar)from dual 159 | ; 160 | 161 | -- testObject 162 | select json_object('foo':bar,'foo':bar format json)from dual 163 | ; 164 | 165 | -- testObject 166 | select json_object(key 'foo' value bar,'foo':bar format json,'foo':bar null on null)from dual 167 | ; 168 | 169 | -- testObject 170 | select json_object(key 'foo' value bar format json,'foo':bar,'foo':bar absent on null)from dual 171 | ; 172 | 173 | -- testObject 174 | select json_object(key 'foo' value bar format json,'foo':bar,'foo':bar absent on null with unique keys)from dual 175 | ; 176 | 177 | -- testObject 178 | select json_object(key 'foo' value bar format json,'foo':bar,'foo':bar absent on null without unique keys)from dual 179 | ; 180 | 181 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/expression/LikeExpressionTest.sql: -------------------------------------------------------------------------------- 1 | -- testLikeWithEscapeExpressionIssue420 2 | select*from dual where a like ?1 escape ?2 3 | ; 4 | 5 | -- testEscapingIssue578 6 | select*from t1 where upper(t1.tipcor_a8)like ? escape '' order by perfilb2||translate(upper(ap1sol10||' '||ap2sol10||','||nomsol10),'?','a')asc 7 | ; 8 | 9 | -- testEscapingIssue827 10 | insert into my_table(my_column_1,my_column_2)values('my_value_1\','my_value_2') 11 | ; 12 | 13 | -- testEscapingIssue832 14 | select*from t1 where(name like ? escape '\')and(description like ? escape '\') 15 | ; 16 | 17 | -- testEscapingIssue875 18 | insert into standard_table(gmt_create,gmt_modified,config_name,standard_code)values(now(),now(),null,'if @fac.sql_type in [ ''update'',''delete'',''insert'',''insert_select'']then @act.allow_submit end ') 19 | ; 20 | 21 | -- testEscapingIssue875 22 | insert into standard_table(gmt_create,gmt_modified,config_name,standard_code)values(now(),now(),null,'if @fac.sql_type in [ \'update\',\'delete\',\'insert\',\'insert_select\']then @act.allow_submit end ') 23 | ; 24 | 25 | -- testEscapingIssue1172 26 | select a alia1,case when b like 'abc\_%' escape '\' then 'def' else 'cccc' end as obj_sub_type from table2 27 | ; 28 | 29 | -- testEscapingIssue1173 30 | update param_tbl set para_desc=null where para_desc='\' and default_value='\' 31 | ; 32 | 33 | -- testEscapingIssue1209 34 | insert into "a"."b"("c","d","e")values('c c\','dd','ee\') 35 | ; 36 | 37 | -- testEscapeExpressionIssue1638 38 | select case when id_portfolio like '%\_1' escape '\' then '1' end 39 | ; 40 | 41 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/expression/LimitExpressionTest.sql: -------------------------------------------------------------------------------- 1 | -- testIssue1373 2 | select 1 limit 1+0 3 | ; 4 | 5 | -- testIssue1376 6 | select 1 offset '0' 7 | ; 8 | 9 | -- testIssue933 10 | select*from tmp3 limit '2' 11 | ; 12 | 13 | -- testIssue933 14 | select*from tmp3 limit(select 2) 15 | ; 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/expression/OracleNamedFunctionParameterTest.sql: -------------------------------------------------------------------------------- 1 | -- testExpression 2 | select r.*,test.numeric_function(p_1=>r.param1,p_2=>r.param2)as resultaat2 3 | ; 4 | 5 | -- testExpression 6 | exec dbms_stats.gather_schema_stats(ownname=>'common',estimate_percent=>dbms_stats.auto_sample_size,method_opt=>'for all columns size auto',degree=>dbms_stats.default_degree,cascade=>dbms_stats.auto_cascade,options=>'gather auto') 7 | ; 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/expression/OverlapsConditionTest.sql: -------------------------------------------------------------------------------- 1 | -- testOverlapsCondition 2 | select*from dual where(start_one,end_one)overlaps(start_two,end_two) 3 | ; 4 | 5 | -- testOverlapsCondition 6 | select*from t1 left join t2 on(t1.start,t1.end)overlaps(t2.start,t2.end) 7 | ; 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/expression/StringValueTest.sql: -------------------------------------------------------------------------------- 1 | -- testOracleAlternativeQuoting 2 | comment on column emp.name is q'{na'm\e}' 3 | ; 4 | 5 | -- testOracleAlternativeQuoting 6 | comment on column emp.name is q'(na'm\e)' 7 | ; 8 | 9 | -- testOracleAlternativeQuoting 10 | comment on column emp.name is q'[na'm\e]' 11 | ; 12 | 13 | -- testOracleAlternativeQuoting 14 | comment on column emp.name is q''na'm\e]'' 15 | ; 16 | 17 | -- testOracleAlternativeQuoting 18 | select q'{its good!}' from dual 19 | ; 20 | 21 | -- testOracleAlternativeQuoting 22 | select q'{it's good!}' from dual 23 | ; 24 | 25 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/expression/mysql/MySqlSqlCalcFoundRowsTest.sql: -------------------------------------------------------------------------------- 1 | -- testPossibleParsingWithSqlCalcFoundRowsHint 2 | SELECT SQL_CALC_FOUND_ROWS * FROM TABLE 3 | ; 4 | 5 | -- testPossibleParsingWithSqlCalcFoundRowsHint 6 | SELECT * FROM TABLE 7 | ; 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/expression/operators/relational/FullTextSearchExpressionTest.sql: -------------------------------------------------------------------------------- 1 | -- testFullTextSearchExpressionWithParameters 2 | select match(name)against(?)as full_text from commodity 3 | ; 4 | 5 | -- testFullTextSearchExpressionWithParameters 6 | select match(name)against(:parameter)as full_text from commodity 7 | ; 8 | 9 | -- testIssue1223 10 | select c.*,match(name)against(?)as full_text from commodity c where match(name)against(?)and c.deleted=0 order by full_text desc 11 | ; 12 | 13 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/BlockTest.sql: -------------------------------------------------------------------------------- 1 | -- testBlock2 2 | begin update table1 set a='xx' where b='condition1'; update table1 set a='xx' where b='condition2'; end; 3 | 4 | -- testGetStatements 5 | begin select*from feature; end; 6 | 7 | -- testIfElseBlock 8 | if(a=b)begin update table1 set a='xx' where b='condition1'; update table1 set a='xx' where b='condition2'; end 9 | ; 10 | 11 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/DeclareStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- testDeclareTable 2 | DECLARE @MyTableVar TABLE (EmpID int NOT NULL, OldVacationHours int, NewVacationHours int, ModifiedDate datetime) 3 | ; 4 | 5 | -- testDeclareTypeWithDefault 6 | DECLARE @find varchar (30) = 'Man%' 7 | ; 8 | 9 | -- testDeclareTypeList 10 | DECLARE @group nvarchar (50), @sales money 11 | ; 12 | 13 | -- testDeclareAs 14 | DECLARE @LocationTVP AS LocationTableType 15 | ; 16 | 17 | -- testDeclareType 18 | DECLARE @find nvarchar (30) 19 | ; 20 | 21 | -- testDeclareTypeList2 22 | DECLARE @group nvarchar (50), @sales varchar (50) 23 | ; 24 | 25 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/DescribeTest.sql: -------------------------------------------------------------------------------- 1 | -- testDescribeIssue1212 2 | DESCRIBE file_azbs.productcategory.json 3 | ; 4 | 5 | -- testDescribe 6 | DESCRIBE foo.products 7 | ; 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/ExplainTest.sql: -------------------------------------------------------------------------------- 1 | -- testAnalyze 2 | EXPLAIN ANALYZE SELECT * FROM mytable 3 | ; 4 | 5 | -- testCosts 6 | EXPLAIN COSTS SELECT * FROM mytable 7 | ; 8 | 9 | -- testMultiOptions_orderPreserved 10 | EXPLAIN VERBOSE ANALYZE BUFFERS COSTS SELECT * FROM mytable 11 | ; 12 | 13 | -- testBuffers 14 | EXPLAIN BUFFERS SELECT * FROM mytable 15 | ; 16 | 17 | -- testVerbose 18 | EXPLAIN VERBOSE SELECT * FROM mytable 19 | ; 20 | 21 | -- testFormat 22 | EXPLAIN FORMAT XML SELECT * FROM mytable 23 | ; 24 | 25 | -- testDescribe 26 | EXPLAIN SELECT * FROM mytable 27 | ; 28 | 29 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/IfElseStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- testSimpleIfElseStatement 2 | if object_id('torigin','u')is not null drop table torigin 3 | ; 4 | 5 | -- testSimpleIfElseStatement 6 | if object_id('torigin','u')is not null drop table torigin; 7 | 8 | -- testSimpleIfElseStatement 9 | if object_id('torigin','u')is not null drop table torigin; else create table torigin(id varchar(40)); 10 | 11 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/PurgeStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- testStatement 2 | purge table testtable 3 | ; 4 | 5 | -- testStatement 6 | purge table cfe.testtable 7 | ; 8 | 9 | -- testStatement 10 | purge index testtable_idx1 11 | ; 12 | 13 | -- testStatement 14 | purge index cfe.testtable_idx1 15 | ; 16 | 17 | -- testStatement 18 | purge recyclebin 19 | ; 20 | 21 | -- testStatement 22 | purge dba_recyclebin 23 | ; 24 | 25 | -- testStatement 26 | purge tablespace my_table_space 27 | ; 28 | 29 | -- testStatement 30 | purge tablespace my_table_space user cfe 31 | ; 32 | 33 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/ResetStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- tesResetAll 2 | RESET ALL 3 | ; 4 | 5 | -- tesResetTZ 6 | RESET Time Zone 7 | ; 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/SavepointRollbackCommitTest.sql: -------------------------------------------------------------------------------- 1 | -- testRollback 2 | rollback 3 | ; 4 | 5 | -- testRollback 6 | rollback work 7 | ; 8 | 9 | -- testRollback 10 | rollback to banda_sal 11 | ; 12 | 13 | -- testRollback 14 | rollback to savepoint banda_sal 15 | ; 16 | 17 | -- testRollback 18 | rollback work to banda_sal 19 | ; 20 | 21 | -- testRollback 22 | rollback work to savepoint banda_sal 23 | ; 24 | 25 | -- testRollback 26 | rollback force '25.32.87' 27 | ; 28 | 29 | -- testRollback 30 | rollback work force '25.32.87' 31 | ; 32 | 33 | -- testSavepoint 34 | savepoint banda_sal 35 | ; 36 | 37 | -- testCommit 38 | COMMIT 39 | ; 40 | 41 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/SetStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- tesLocalWithEq 2 | SET LOCAL cursor_tuple_fraction = 0.05 3 | ; 4 | 5 | -- testSimpleSet 6 | SET statement_timeout = 0 7 | ; 8 | 9 | -- testSettingUserVariable 10 | set @flag=1 11 | ; 12 | 13 | -- testSettingUserVariable 14 | set @@global.time_zone='01:00' 15 | ; 16 | 17 | -- testListValue 18 | SET v = 1, 3 19 | ; 20 | 21 | -- tesTimeZone 22 | SET LOCAL Time Zone 'UTC' 23 | ; 24 | 25 | -- testValueOnIssue927 26 | SET standard_conforming_strings = on 27 | ; 28 | 29 | -- testMultiValue 30 | SET v = 1, c = 3 31 | ; 32 | 33 | -- testIssue373_2 34 | SET tester 5 35 | ; 36 | 37 | -- testIssue373 38 | SET deferred_name_resolution true 39 | ; 40 | 41 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/ShowColumnsStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- testSimpleUse 2 | SHOW COLUMNS FROM mydatabase 3 | ; 4 | 5 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/ShowStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- testSimpleUse2 2 | SHOW transaction_isolation 3 | ; 4 | 5 | -- testSimpleUse 6 | SHOW mydatabase 7 | ; 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/StatementSeparatorTest.sql: -------------------------------------------------------------------------------- 1 | -- testOracleBlock 2 | begin select*from table; end; 3 | 4 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/UnsupportedStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- testSingleUnsupportedStatement 2 | this is an unsupported statement 3 | ; 4 | 5 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/UseStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- testSimpleUse 2 | USE mydatabase 3 | ; 4 | 5 | -- testUseSchema 6 | USE SCHEMA myschema 7 | ; 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/alter/AlterSequenceTest.sql: -------------------------------------------------------------------------------- 1 | -- testAlterSequence_preservesParamOrder 2 | ALTER SEQUENCE my_sec INCREMENT BY 2 START WITH 10 3 | ; 4 | 5 | -- testAlterSequence_preservesParamOrder 6 | ALTER SEQUENCE my_sec START WITH 2 INCREMENT BY 5 NOCACHE 7 | ; 8 | 9 | -- testAlterSequence_preservesParamOrder 10 | ALTER SEQUENCE my_sec START WITH 2 INCREMENT BY 5 CACHE 200 CYCLE 11 | ; 12 | 13 | -- testAlterSequence_withIncrement 14 | ALTER SEQUENCE my_seq INCREMENT BY 1 15 | ; 16 | 17 | -- testAlterSequence_restartIssue1405WithoutValue 18 | ALTER SEQUENCE my_seq RESTART 19 | ; 20 | 21 | -- testAlterSequence_withNoMaxValue 22 | ALTER SEQUENCE my_seq NOMAXVALUE 23 | ; 24 | 25 | -- testAlterSequence_withMinValue 26 | ALTER SEQUENCE my_seq MINVALUE 5 27 | ; 28 | 29 | -- testAlterSequence_withCache 30 | ALTER SEQUENCE my_seq CACHE 10 31 | ; 32 | 33 | -- testAlterSequence_withCycle 34 | ALTER SEQUENCE my_seq CYCLE 35 | ; 36 | 37 | -- testAlterSequence_withOrder 38 | ALTER SEQUENCE my_seq ORDER 39 | ; 40 | 41 | -- testAlterSequence_withStart 42 | ALTER SEQUENCE my_seq START WITH 10 43 | ; 44 | 45 | -- testAlterSequence_withSession 46 | ALTER SEQUENCE my_seq SESSION 47 | ; 48 | 49 | -- testAlterSequence_withNoCache 50 | ALTER SEQUENCE my_seq NOCACHE 51 | ; 52 | 53 | -- testAlterSequence_withNoCycle 54 | ALTER SEQUENCE my_seq NOCYCLE 55 | ; 56 | 57 | -- testAlterSequence_withNoOrder 58 | ALTER SEQUENCE my_seq NOORDER 59 | ; 60 | 61 | -- testAlterSequence_restartIssue1405 62 | ALTER SEQUENCE my_seq RESTART WITH 1 63 | ; 64 | 65 | -- testAlterSequence_withKeep 66 | ALTER SEQUENCE my_seq KEEP 67 | ; 68 | 69 | -- testAlterSequence_withGlobal 70 | ALTER SEQUENCE my_seq GLOBAL 71 | ; 72 | 73 | -- testAlterSequence_withMaxValue 74 | ALTER SEQUENCE my_seq MAXVALUE 5 75 | ; 76 | 77 | -- testAlterSequence_withNoKeep 78 | ALTER SEQUENCE my_seq NOKEEP 79 | ; 80 | 81 | -- testAlterSequence_withNoMinValue 82 | ALTER SEQUENCE my_seq NOMINVALUE 83 | ; 84 | 85 | -- testAlterSequence_noParams 86 | ALTER SEQUENCE my_seq 87 | ; 88 | 89 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/alter/AlterSessionTest.sql: -------------------------------------------------------------------------------- 1 | -- testAlterSessionCloseDatabaseLink 2 | alter session close database link mylink 3 | ; 4 | 5 | -- testAlterSessionSet 6 | alter session set ddl_lock_timeout=7200 7 | ; 8 | 9 | -- testAlterSessionSet 10 | alter session set ddl_lock_timeout=7200 11 | ; 12 | 13 | -- testAlterSessionDisable 14 | alter session disable commit in procedure 15 | ; 16 | 17 | -- testAlterSessionDisable 18 | alter session disable guard 19 | ; 20 | 21 | -- testAlterSessionDisable 22 | alter session disable parallel dml 23 | ; 24 | 25 | -- testAlterSessionDisable 26 | alter session disable parallel ddl 27 | ; 28 | 29 | -- testAlterSessionDisable 30 | alter session disable parallel query 31 | ; 32 | 33 | -- testAlterSessionForceParallel 34 | alter session force parallel dml 35 | ; 36 | 37 | -- testAlterSessionForceParallel 38 | alter session force parallel dml parallel 10 39 | ; 40 | 41 | -- testAlterSessionForceParallel 42 | alter session force parallel ddl 43 | ; 44 | 45 | -- testAlterSessionForceParallel 46 | alter session force parallel ddl parallel 10 47 | ; 48 | 49 | -- testAlterSessionForceParallel 50 | alter session force parallel query 51 | ; 52 | 53 | -- testAlterSessionForceParallel 54 | alter session force parallel query parallel 10 55 | ; 56 | 57 | -- testAlterSessionResumable 58 | alter session enable resumable 59 | ; 60 | 61 | -- testAlterSessionResumable 62 | alter session disable resumable 63 | ; 64 | 65 | -- testAlterSessionAdvise 66 | alter session advise commit 67 | ; 68 | 69 | -- testAlterSessionAdvise 70 | alter session advise rollback 71 | ; 72 | 73 | -- testAlterSessionAdvise 74 | alter session advise nothing 75 | ; 76 | 77 | -- testAlterSessionEnable 78 | alter session enable commit in procedure 79 | ; 80 | 81 | -- testAlterSessionEnable 82 | alter session enable guard 83 | ; 84 | 85 | -- testAlterSessionEnable 86 | alter session enable parallel dml 87 | ; 88 | 89 | -- testAlterSessionEnable 90 | alter session enable parallel dml parallel 10 91 | ; 92 | 93 | -- testAlterSessionEnable 94 | alter session enable parallel ddl 95 | ; 96 | 97 | -- testAlterSessionEnable 98 | alter session enable parallel ddl parallel 10 99 | ; 100 | 101 | -- testAlterSessionEnable 102 | alter session enable parallel query 103 | ; 104 | 105 | -- testAlterSessionEnable 106 | alter session enable parallel query parallel 10 107 | ; 108 | 109 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/alter/AlterSystemTest.sql: -------------------------------------------------------------------------------- 1 | -- testStatement 2 | alter system kill session '13,8' 3 | ; 4 | 5 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/alter/RenameTableStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- testStatement 2 | rename oldtablename to newtablename 3 | ; 4 | 5 | -- testStatement 6 | rename table old_table to backup_table,new_table to old_table 7 | ; 8 | 9 | -- testStatement 10 | rename table if exists old_table wait 20 to backup_table,new_table to old_table 11 | ; 12 | 13 | -- testStatement 14 | rename table if exists old_table nowait to backup_table,new_table to old_table 15 | ; 16 | 17 | -- testValidator 18 | rename oldtablename to newtablename 19 | ; 20 | 21 | -- testValidator 22 | alter table public.oldtablename rename to newtablename 23 | ; 24 | 25 | -- testValidator 26 | alter table if exists public.oldtablename rename to newtablename 27 | ; 28 | 29 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/analyze/AnalyzeTest.sql: -------------------------------------------------------------------------------- 1 | -- testAnalyze2 2 | ANALYZE mytable 3 | ; 4 | 5 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/builder/JSQLParserFluentModelTests.sql: -------------------------------------------------------------------------------- 1 | -- testParseAndBuildForXORComplexCondition 2 | SELECT * FROM tab1 AS t1 WHERE a AND b OR c XOR d 3 | ; 4 | 5 | -- testParseAndBuild 6 | SELECT * FROM tab1 AS t1 JOIN tab2 t2 ON t1.ref = t2.id WHERE (t1.col1 = ? OR t1.col2 = ?) AND t1.col3 IN ('A') 7 | ; 8 | 9 | -- testParseAndBuildForXORs 10 | SELECT * FROM tab1 AS t1 WHERE a XOR b XOR c 11 | ; 12 | 13 | -- testParseAndBuildForXOR 14 | SELECT * FROM tab1 AS t1 JOIN tab2 t2 ON t1.ref = t2.id WHERE (t1.col1 XOR t2.col2) AND t1.col3 IN ('B', 'C') XOR t2.col4 15 | ; 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/comment/CommentTest.sql: -------------------------------------------------------------------------------- 1 | -- testCommentColumnDeparseIssue696 2 | COMMENT ON COLUMN hotels.hotelid IS 'Primary key of the table' 3 | ; 4 | 5 | -- testCommentTableDeparse 6 | COMMENT ON TABLE table1 IS 'comment1' 7 | ; 8 | 9 | -- testCommentOnView 10 | COMMENT ON VIEW myschema.myView IS 'myComment' 11 | ; 12 | 13 | -- testCommentColumnDeparse 14 | COMMENT ON COLUMN table1.column1 IS 'comment1' 15 | ; 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/create/AlterSequenceTest.sql: -------------------------------------------------------------------------------- 1 | -- testCreateSequence_withIncrement 2 | ALTER SEQUENCE my_seq CACHE 100 3 | ; 4 | 5 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/create/AlterViewTest.sql: -------------------------------------------------------------------------------- 1 | -- testAlterView 2 | ALTER VIEW myview AS SELECT * FROM mytab 3 | ; 4 | 5 | -- testReplaceView 6 | REPLACE VIEW myview(a, b) AS SELECT a, b FROM mytab 7 | ; 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/create/CreateFunctionalStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- createFunctionMinimal 2 | CREATE FUNCTION foo RETURN 5; END; 3 | 4 | -- createProcedureMinimal 5 | CREATE PROCEDURE foo AS BEGIN END; 6 | 7 | -- createOrReplaceFunctionMinimal 8 | CREATE OR REPLACE FUNCTION foo RETURN 5; END; 9 | 10 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/create/CreateIndexTest.sql: -------------------------------------------------------------------------------- 1 | -- testCreateIndex6 2 | CREATE INDEX myindex ON mytab (mycol, mycol2) 3 | ; 4 | 5 | -- testCreateIndex7 6 | CREATE INDEX myindex1 ON mytab USING GIST (mycol) 7 | ; 8 | 9 | -- testFullIndexNameIssue936_2 10 | CREATE INDEX "TS"."IDX" ON "TEST" ("ID") TABLESPACE "TS" 11 | ; 12 | 13 | -- testFullIndexNameIssue936 14 | CREATE INDEX "TS"."IDX" ON "TEST" ("ID" ASC) TABLESPACE "TS" 15 | ; 16 | 17 | -- testCreateIndexIssue633 18 | CREATE INDEX idx_american_football_action_plays_1 ON american_football_action_plays USING btree (play_type) 19 | ; 20 | 21 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/create/CreateSequenceTest.sql: -------------------------------------------------------------------------------- 1 | -- testCreateSequence_noParams 2 | CREATE SEQUENCE my_seq 3 | ; 4 | 5 | -- testCreateSequence_withCache 6 | CREATE SEQUENCE my_seq CACHE 10 7 | ; 8 | 9 | -- testCreateSequence_withCycle 10 | CREATE SEQUENCE my_seq CYCLE 11 | ; 12 | 13 | -- testCreateSequence_withOrder 14 | CREATE SEQUENCE my_seq ORDER 15 | ; 16 | 17 | -- testCreateSequence_withStart 18 | CREATE SEQUENCE my_seq START WITH 10 19 | ; 20 | 21 | -- testCreateSequence_withGlobal 22 | CREATE SEQUENCE my_seq GLOBAL 23 | ; 24 | 25 | -- testCreateSequence_withNoKeep 26 | CREATE SEQUENCE my_seq NOKEEP 27 | ; 28 | 29 | -- testCreateSequence_withSession 30 | CREATE SEQUENCE my_seq SESSION 31 | ; 32 | 33 | -- testCreateSequence_withNoCache 34 | CREATE SEQUENCE my_seq NOCACHE 35 | ; 36 | 37 | -- testCreateSequence_withNoCycle 38 | CREATE SEQUENCE my_seq NOCYCLE 39 | ; 40 | 41 | -- testCreateSequence_withNoOrder 42 | CREATE SEQUENCE my_seq NOORDER 43 | ; 44 | 45 | -- testCreateSequence_withNoMinValue 46 | CREATE SEQUENCE my_seq NOMINVALUE 47 | ; 48 | 49 | -- testCreateSequence_withMinValue 50 | CREATE SEQUENCE my_seq MINVALUE 5 51 | ; 52 | 53 | -- testCreateSequence_withIncrement 54 | CREATE SEQUENCE db.schema.my_seq INCREMENT BY 1 55 | ; 56 | 57 | -- testCreateSequence_preservesParamOrder 58 | CREATE SEQUENCE my_sec INCREMENT BY 2 START WITH 10 59 | ; 60 | 61 | -- testCreateSequence_preservesParamOrder 62 | CREATE SEQUENCE my_sec START WITH 2 INCREMENT BY 5 NOCACHE 63 | ; 64 | 65 | -- testCreateSequence_preservesParamOrder 66 | CREATE SEQUENCE my_sec START WITH 2 INCREMENT BY 5 CACHE 200 CYCLE 67 | ; 68 | 69 | -- testCreateSequence_withKeep 70 | CREATE SEQUENCE my_seq KEEP 71 | ; 72 | 73 | -- testCreateSequence_withNoMaxValue 74 | CREATE SEQUENCE my_seq NOMAXVALUE 75 | ; 76 | 77 | -- testCreateSequence_withMaxValue 78 | CREATE SEQUENCE my_seq MAXVALUE 5 79 | ; 80 | 81 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/create/CreateViewTest.sql: -------------------------------------------------------------------------------- 1 | -- testCreateTemporaryViewIssue604 2 | CREATE TEMPORARY VIEW myview AS SELECT * FROM mytable 3 | ; 4 | 5 | -- testCreateTemporaryViewIssue665 6 | CREATE VIEW foo("BAR") AS WITH temp AS (SELECT temp_bar FROM foobar) SELECT bar FROM temp 7 | ; 8 | 9 | -- testCreateView2 10 | CREATE VIEW myview AS SELECT * FROM mytab 11 | ; 12 | 13 | -- testCreateView3 14 | CREATE OR REPLACE VIEW myview AS SELECT * FROM mytab 15 | ; 16 | 17 | -- testCreateView4 18 | CREATE OR REPLACE VIEW view2 AS SELECT a, b, c FROM testtab INNER JOIN testtab2 ON testtab.col1 = testtab2.col2 19 | ; 20 | 21 | -- testCreateViewAutoRefreshNo 22 | CREATE VIEW myview AUTO REFRESH NO AS SELECT * FROM mytab 23 | ; 24 | 25 | -- testCreateForceView 26 | CREATE FORCE VIEW view1 AS SELECT a, b FROM testtab 27 | ; 28 | 29 | -- testCreateViewAutoRefreshYes 30 | CREATE VIEW myview AUTO REFRESH YES AS SELECT * FROM mytab 31 | ; 32 | 33 | -- testCreateWithReadOnlyViewIssue838 34 | CREATE VIEW v14(c1, c2) AS SELECT c1, C2 FROM t1 WITH READ ONLY 35 | ; 36 | 37 | -- testCreateViewIfNotExists 38 | CREATE VIEW myview IF NOT EXISTS AS SELECT * FROM mytab 39 | ; 40 | 41 | -- testCreateTemporaryViewIssue604_2 42 | CREATE TEMP VIEW myview AS SELECT * FROM mytable 43 | ; 44 | 45 | -- testCreateForceView1 46 | CREATE NO FORCE VIEW view1 AS SELECT a, b FROM testtab 47 | ; 48 | 49 | -- testCreateForceView2 50 | CREATE OR REPLACE FORCE VIEW view1 AS SELECT a, b FROM testtab 51 | ; 52 | 53 | -- testCreateForceView3 54 | CREATE OR REPLACE NO FORCE VIEW view1 AS SELECT a, b FROM testtab 55 | ; 56 | 57 | -- testCreateViewUnion 58 | CREATE VIEW view1 AS (SELECT a, b FROM testtab) UNION (SELECT b, c FROM testtab2) 59 | ; 60 | 61 | -- testCreateMaterializedView 62 | CREATE MATERIALIZED VIEW view1 AS SELECT a, b FROM testtab 63 | ; 64 | 65 | -- testCreateViewAutoRefreshNone 66 | CREATE VIEW myview AS SELECT * FROM mytab 67 | ; 68 | 69 | -- testCreateMaterializedViewIfNotExists 70 | CREATE MATERIALIZED VIEW myview IF NOT EXISTS AS SELECT * FROM mytab 71 | ; 72 | 73 | -- testCreateViewWithColumnNames1 74 | CREATE OR REPLACE VIEW view1(col1, col2) AS SELECT a, b FROM testtab 75 | ; 76 | 77 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/create/schema/CreateSchemaTest.sql: -------------------------------------------------------------------------------- 1 | -- testSimpleCreateSchema 2 | CREATE SCHEMA myschema 3 | ; 4 | 5 | -- testSimpleCreateWithAuth 6 | CREATE SCHEMA myschema AUTHORIZATION myauth 7 | ; 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/create/synonym/CreateSynonymTest.sql: -------------------------------------------------------------------------------- 1 | -- createWithReplace 2 | CREATE OR REPLACE SYNONYM TBL_TABLE_NAME FOR SCHEMA.T_TBL_NAME 3 | ; 4 | 5 | -- createWithDbLink 6 | CREATE PUBLIC SYNONYM emp_table FOR hr.employees@remote.us.oracle.com 7 | ; 8 | 9 | -- createWithReplacePublic 10 | CREATE OR REPLACE PUBLIC SYNONYM TBL_TABLE_NAME FOR SCHEMA.T_TBL_NAME 11 | ; 12 | 13 | -- createPublic 14 | CREATE PUBLIC SYNONYM TBL_TABLE_NAME FOR SCHEMA.T_TBL_NAME 15 | ; 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/delete/DeleteTest.sql: -------------------------------------------------------------------------------- 1 | -- testDeleteMultipleModifiers 2 | DELETE LOW_PRIORITY QUICK FROM tablename 3 | ; 4 | 5 | -- testDeleteMultipleModifiers 6 | DELETE LOW_PRIORITY QUICK IGNORE FROM tablename 7 | ; 8 | 9 | -- testDeleteReturningIssue1527 10 | delete from t returning* 11 | ; 12 | 13 | -- testDeleteReturningIssue1527 14 | delete from products where price<=99.99 returning name,price as new_price 15 | ; 16 | 17 | -- testDeleteWithOrderByAndLimit 18 | DELETE FROM tablename WHERE a = 1 AND b = 1 ORDER BY col LIMIT 10 19 | ; 20 | 21 | -- testDeleteQuickModifier 22 | DELETE QUICK FROM tablename 23 | ; 24 | 25 | -- testDeleteQuickModifier 26 | DELETE FROM tablename 27 | ; 28 | 29 | -- testUsing 30 | DELETE A USING B.C D WHERE D.Z = 1 31 | ; 32 | 33 | -- testDeleteFromTableUsingInnerJoinToAnotherTableWithAlias 34 | DELETE gc FROM guide_category AS gc LEFT JOIN guide AS g ON g.id_guide = gc.id_guide WHERE g.title IS NULL LIMIT 5 35 | ; 36 | 37 | -- testWith 38 | with a as(select 1 id_instrument_ref),b as(select 1 id_instrument_ref)delete from cfe.instrument_ref where id_instrument_ref=(select id_instrument_ref from a) 39 | ; 40 | 41 | -- testDeleteFromTableUsingInnerJoinToAnotherTable 42 | DELETE Table1 FROM Table1 INNER JOIN Table2 ON Table1.ID = Table2.ID 43 | ; 44 | 45 | -- testDeleteFromTableUsingLeftJoinToAnotherTable 46 | DELETE g FROM Table1 AS g LEFT JOIN Table2 ON Table1.ID = Table2.ID 47 | ; 48 | 49 | -- testDeleteLowPriority 50 | DELETE LOW_PRIORITY FROM tablename 51 | ; 52 | 53 | -- testDeleteMultiTableIssue878 54 | DELETE table1, table2 FROM table1, table2 55 | ; 56 | 57 | -- testDeleteIgnoreModifier 58 | DELETE IGNORE FROM tablename 59 | ; 60 | 61 | -- testDeleteIgnoreModifier 62 | DELETE FROM tablename 63 | ; 64 | 65 | -- testDeleteOutputClause 66 | delete sales.shoppingcartitem output deleted.*from sales 67 | ; 68 | 69 | -- testDeleteOutputClause 70 | delete sales.shoppingcartitem output sales.shoppingcartitem from sales 71 | ; 72 | 73 | -- testDeleteOutputClause 74 | delete production.productproductphoto output deleted.productid,p.name,p.productmodelid,deleted.productphotoid into @mytablevar from production.productproductphoto as ph join production.product as p on ph.productid=p.productid where p.productmodelid between 120 and 130 75 | ; 76 | 77 | -- testNoFromWithSchema 78 | DELETE A.B WHERE Z = 1 79 | ; 80 | 81 | -- testDeleteWhereProblem1 82 | DELETE FROM tablename WHERE a = 1 AND b = 1 83 | ; 84 | 85 | -- testOracleHint 86 | delete from mytable where mytable.col=9 87 | ; 88 | 89 | -- testDeleteWithLimit 90 | DELETE FROM tablename WHERE a = 1 AND b = 1 LIMIT 5 91 | ; 92 | 93 | -- testNoFrom 94 | DELETE A WHERE Z = 1 95 | ; 96 | 97 | -- testDeleteWithOrderBy 98 | DELETE FROM tablename WHERE a = 1 AND b = 1 ORDER BY col 99 | ; 100 | 101 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/drop/DropTest.sql: -------------------------------------------------------------------------------- 1 | -- testDropIfExists 2 | DROP TABLE IF EXISTS my_table 3 | ; 4 | 5 | -- testDropFunctionWithNameAndParameterizedType 6 | DROP FUNCTION myFunc(amount integer, name varchar(255)) 7 | ; 8 | 9 | -- testUniqueFunctionDrop 10 | DROP FUNCTION myFunc 11 | ; 12 | 13 | -- testDropSequence 14 | DROP SEQUENCE mysequence 15 | ; 16 | 17 | -- testDropMaterializedView 18 | DROP MATERIALIZED VIEW myview 19 | ; 20 | 21 | -- testDropFunctionWithSimpleType 22 | DROP FUNCTION myFunc(integer, varchar) 23 | ; 24 | 25 | -- testZeroArgDropFunction 26 | DROP FUNCTION myFunc() 27 | ; 28 | 29 | -- testDropRestrictIssue510 30 | DROP TABLE TABLE2 RESTRICT 31 | ; 32 | 33 | -- dropTemporaryTableTestIssue1712 34 | drop temporary table if exists tmp_mwyt8n0z 35 | ; 36 | 37 | -- testOracleMultiColumnDrop 38 | ALTER TABLE foo DROP (bar, baz) CASCADE 39 | ; 40 | 41 | -- testDropIndexOnTable 42 | DROP INDEX idx ON abc 43 | ; 44 | 45 | -- testDropFunctionWithNameAndType 46 | DROP FUNCTION myFunc(amount integer, name varchar) 47 | ; 48 | 49 | -- testDropSchemaIssue855 50 | DROP SCHEMA myschema 51 | ; 52 | 53 | -- testDropViewIssue545_2 54 | DROP VIEW IF EXISTS myview 55 | ; 56 | 57 | -- testDropViewIssue545 58 | DROP VIEW myview 59 | ; 60 | 61 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/execute/ExecuteTest.sql: -------------------------------------------------------------------------------- 1 | -- testAcceptCall 2 | CALL myproc 'a', 2, 'b' 3 | ; 4 | 5 | -- testAcceptExec 6 | EXEC myproc 'a', 2, 'b' 7 | ; 8 | 9 | -- testAcceptExecute 10 | EXECUTE myproc 'a', 2, 'b' 11 | ; 12 | 13 | -- testAcceptCallWithParenthesis 14 | CALL myproc ('a', 2, 'b') 15 | ; 16 | 17 | -- testAcceptExecNamesParameters 18 | EXEC procedure @param 19 | ; 20 | 21 | -- testAcceptExecNamesParameters2 22 | EXEC procedure @param = 1 23 | ; 24 | 25 | -- testAcceptExecNamesParameters3 26 | EXEC procedure @param = 'foo' 27 | ; 28 | 29 | -- testAcceptExecNamesParameters4 30 | EXEC procedure @param = 'foo', @param2 = 'foo2' 31 | ; 32 | 33 | -- testCallWithMultiname 34 | CALL BAR.FOO 35 | ; 36 | 37 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/grant/GrantTest.sql: -------------------------------------------------------------------------------- 1 | -- testGrantQueryWithPrivileges 2 | GRANT SELECT, INSERT, UPDATE, DELETE ON T1 TO ADMIN_ROLE 3 | ; 4 | 5 | -- testGrantSchemaParsingIssue1080 6 | GRANT SELECT ON schema_name.table_name TO XYZ 7 | ; 8 | 9 | -- testGrantQueryWithRole 10 | GRANT ROLE_1 TO TEST_ROLE_1, TEST_ROLE_2 11 | ; 12 | 13 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/insert/InsertTest.sql: -------------------------------------------------------------------------------- 1 | -- testInsertTableArrays4 2 | insert into sal_emp values('carol',array[20000,25000,25000,25000],array[['breakfast','consulting'],['meeting','lunch']]) 3 | ; 4 | 5 | -- testModifierIgnore 6 | INSERT IGNORE INTO `AoQiSurvey_FlashVersion_Single` VALUES (302215163, 'WIN 16,0,0,235') 7 | ; 8 | 9 | -- testInsertMultiRowValue 10 | INSERT INTO mytable (col1, col2) VALUES (a, b), (d, e) 11 | ; 12 | 13 | -- testInsertTableWithAliasIssue526 14 | INSERT INTO account t (name, addr, phone) SELECT * FROM user 15 | ; 16 | 17 | -- testInsertWithReturning2 18 | INSERT INTO mytable (mycolumn) VALUES ('1') RETURNING * 19 | ; 20 | 21 | -- testInsertWithReturning3 22 | INSERT INTO mytable (mycolumn) VALUES ('1') RETURNING id AS a1, id2 AS a2 23 | ; 24 | 25 | -- testInsertUnionSelectIssue1491 26 | insert into table1(tf1,tf2,tf2)select sf1,sf2,sf3 from s1 union select rf1,rf2,rf2 from r1 27 | ; 28 | 29 | -- testInsertUnionSelectIssue1491 30 | insert into table1(tf1,tf2,tf2)(select sf1,sf2,sf3 from s1 union select rf1,rf2,rf2 from r1) 31 | ; 32 | 33 | -- testInsertUnionSelectIssue1491 34 | insert into table1(tf1,tf2,tf2)(select sf1,sf2,sf3 from s1)union(select rf1,rf2,rf2 from r1) 35 | ; 36 | 37 | -- testInsertUnionSelectIssue1491 38 | insert into table1(tf1,tf2,tf2)((select sf1,sf2,sf3 from s1)union(select rf1,rf2,rf2 from r1)) 39 | ; 40 | 41 | -- testInsertUnionSelectIssue1491 42 | (with a as(select*from dual)select*from a) 43 | ; 44 | 45 | -- testInsertKeyWordIntervalIssue682 46 | INSERT INTO BILLING_TASKS (TIMEOUT, INTERVAL, RETRY_UPON_FAILURE, END_DATE, MAX_RETRY_COUNT, CONTINUOUS, NAME, LAST_RUN, START_TIME, NEXT_RUN, ID, UNIQUE_NAME, INTERVAL_TYPE) VALUES (?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?) 47 | ; 48 | 49 | -- testNextValueFor 50 | INSERT INTO tracker (monitor_id, user_id, module_name, item_id, item_summary, team_id, date_modified, action, visible, id) VALUES (?, ?, ?, ?, ?, ?, to_date(?, 'YYYY-MM-DD HH24:MI:SS'), ?, ?, NEXT VALUE FOR TRACKER_ID_SEQ) 51 | ; 52 | 53 | -- testInsertValuesWithDuplicateEliminationInDeparsing 54 | INSERT INTO TEST (ID, COUNTER) VALUES (123, 0) ON DUPLICATE KEY UPDATE COUNTER = COUNTER + 1 55 | ; 56 | 57 | -- testHexValues2 58 | INSERT INTO TABLE2 VALUES ('1', "DSDD", 0xEFBFBDC7AB) 59 | ; 60 | 61 | -- testHexValues3 62 | INSERT INTO TABLE2 VALUES ('1', "DSDD", 0xabcde) 63 | ; 64 | 65 | -- testInsertSetInDeparsing 66 | INSERT INTO mytable SET col1 = 12, col2 = name1 * name2 67 | ; 68 | 69 | -- testHexValues 70 | INSERT INTO TABLE2 VALUES ('1', "DSDD", x'EFBFBDC7AB') 71 | ; 72 | 73 | -- testWithDeparsingIssue406 74 | insert into mytab3(a,b,c)select a,b,c from mytab where exists(with t as(select*from mytab2)select*from t) 75 | ; 76 | 77 | -- testSimpleInsert 78 | INSERT INTO example (num, name, address, tel) VALUES (1, 'name', 'test ', '1234-1234') 79 | ; 80 | 81 | -- testWithAtFront 82 | with foo as(select attr from bar)insert into lalelu(attr)select attr from foo 83 | ; 84 | 85 | -- testInsertSetWithDuplicateEliminationInDeparsing 86 | INSERT INTO mytable SET col1 = 122 ON DUPLICATE KEY UPDATE col2 = col2 + 1, col3 = 'saint' 87 | ; 88 | 89 | -- testInsertKeyWordEnableIssue592 90 | INSERT INTO T_USER (ID, EMAIL_VALIDATE, ENABLE, PASSWORD) VALUES (?, ?, ?, ?) 91 | ; 92 | 93 | -- testInsertWithKeywords 94 | INSERT INTO kvPair (value, key) VALUES (?, ?) 95 | ; 96 | 97 | -- testModifierPriority1 98 | INSERT DELAYED INTO kvPair (value, key) VALUES (?, ?) 99 | ; 100 | 101 | -- testModifierPriority2 102 | INSERT LOW_PRIORITY INTO kvPair (value, key) VALUES (?, ?) 103 | ; 104 | 105 | -- testModifierPriority3 106 | INSERT HIGH_PRIORITY INTO kvPair (value, key) VALUES (?, ?) 107 | ; 108 | 109 | -- testDisableKeywordIssue945 110 | INSERT INTO SOMESCHEMA.TEST (DISABLE, TESTCOLUMN) VALUES (1, 1) 111 | ; 112 | 113 | -- testWithListIssue282 114 | WITH myctl AS (SELECT a, b FROM mytable) INSERT INTO mytable SELECT a, b FROM myctl 115 | ; 116 | 117 | -- testInsertWithReturning 118 | INSERT INTO mytable (mycolumn) VALUES ('1') RETURNING id 119 | ; 120 | 121 | -- testKeywordDefaultIssue1470 122 | INSERT INTO mytable (col1, col2, col3) VALUES (?, 'sadfsd', default) 123 | ; 124 | 125 | -- testInsertOutputClause 126 | insert into dbo.employeesales(lastname,firstname,currentsales)output inserted.employeeid,inserted.lastname,inserted.firstname,inserted.currentsales,inserted.projectedsales into @mytablevar select c.lastname,c.firstname,sp.salesytd from sales.salesperson as sp inner join person.person as c on sp.businessentityid=c.businessentityid where sp.businessentityid like '2%' order by c.lastname,c.firstname 127 | ; 128 | 129 | -- testInsertOnConflictIssue1551 130 | insert into distributors(did,dname)values(5,'gizmo transglobal'),(6,'associated computing,inc')on conflict(did)do update set dname=excluded.dname 131 | ; 132 | 133 | -- testInsertOnConflictIssue1551 134 | insert into distributors(did,dname)values(7,'redline gmbh')on conflict(did)do nothing 135 | ; 136 | 137 | -- testInsertOnConflictIssue1551 138 | insert into distributors as d(did,dname)values(8,'anvil distribution')on conflict(did)do update set dname=excluded.dname||'(formerly '||d.dname||')' where d.zipcode<>'21201' 139 | ; 140 | 141 | -- testInsertOnConflictIssue1551 142 | insert into distributors(did,dname)values(9,'antwerp design')on conflict on constraint distributors_pkey do nothing 143 | ; 144 | 145 | -- testInsertOnConflictIssue1551 146 | insert into distributors(did,dname)values(10,'conrad international')on conflict(did)where is_active do nothing 147 | ; 148 | 149 | -- testNextValIssue773 150 | INSERT INTO tableA (ID, c1, c2) SELECT hibernate_sequence.nextval, c1, c2 FROM tableB 151 | ; 152 | 153 | -- testBackslashEscapingIssue827 154 | INSERT INTO my_table (my_column_1, my_column_2) VALUES ('my_value_1\\', 'my_value_2') 155 | ; 156 | 157 | -- testInsertWithSelect 158 | insert into mytable(mycolumn)with a as(select mycolumn from mytable)select mycolumn from a 159 | ; 160 | 161 | -- testInsertWithSelect 162 | insert into mytable(mycolumn)(with a as(select mycolumn from mytable)select mycolumn from a) 163 | ; 164 | 165 | -- testIssue223 166 | insert into user values(2001,'\'clark\'','kent') 167 | ; 168 | 169 | -- testNextVal 170 | INSERT INTO tracker (monitor_id, user_id, module_name, item_id, item_summary, team_id, date_modified, action, visible, id) VALUES (?, ?, ?, ?, ?, ?, to_date(?, 'YYYY-MM-DD HH24:MI:SS'), ?, ?, NEXTVAL FOR TRACKER_ID_SEQ) 171 | ; 172 | 173 | -- testOracleHint 174 | insert into mytable values(1,2,3) 175 | ; 176 | 177 | -- testInsertSelect 178 | INSERT INTO mytable (mycolumn) SELECT mycolumn FROM mytable 179 | ; 180 | 181 | -- testInsertSelect 182 | INSERT INTO mytable (mycolumn) (SELECT mycolumn FROM mytable) 183 | ; 184 | 185 | -- testKeywordPrecisionIssue363 186 | INSERT INTO test (user_id, precision) VALUES (1, '111') 187 | ; 188 | 189 | -- testDuplicateKey 190 | INSERT INTO Users0 (UserId, Key, Value) VALUES (51311, 'T_211', 18) ON DUPLICATE KEY UPDATE Value = 18 191 | ; 192 | 193 | -- insertOnConflictObjectsTest 194 | with a(a,b,c)as(select 1,2,3)insert into test select*from a on conflict(a)do nothing 195 | ; 196 | 197 | -- insertOnConflictObjectsTest 198 | with a(a,b,c)as(select 1,2,3)insert into test select*from a on conflict on constraint a do update set a=b/2,b=b/2 where a=1 199 | ; 200 | 201 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/merge/MergeTest.sql: -------------------------------------------------------------------------------- 1 | -- testInsertMergeWhere 2 | merge into test1 a using all_objects b on(a.object_id=b.object_id)when matched then update set a.status=b.status where b.status!='valid' when not matched then insert(object_id,status)values(b.object_id,b.status)where b.status!='valid' 3 | ; 4 | 5 | -- testWith 6 | with a as(select 1 id_instrument_ref),b as(select 1 id_instrument_ref)merge into cfe.instrument_ref b using a on(b.id_instrument_ref=a.id_instrument_ref)when matched then update set b.id_instrument='a' 7 | ; 8 | 9 | -- testMergeUpdateInsertOrderIssue401 10 | MERGE INTO a USING dual ON (col3 = ? AND col1 = ? AND col2 = ?) WHEN NOT MATCHED THEN INSERT (col1, col2, col3, col4) VALUES (?, ?, ?, ?) WHEN MATCHED THEN UPDATE SET col4 = col4 + ? 11 | ; 12 | 13 | -- testMergeIssue232 14 | merge into xyz using dual on(custom_id=?)when matched then update set abc=sysdate when not matched then insert(custom_id)values(?) 15 | ; 16 | 17 | -- testMergeIssue676 18 | merge into m_kc21 using(select aaa,bbb from i_kc21 where i_kc21.aaa='li_kun')temp on(temp.aaa=m_kc21.aaa)when matched then update set m_kc21.bbb=6 where enterprise_id in(0,1)when not matched then insert values(temp.aaa,temp.bbb) 19 | ; 20 | 21 | -- testOracleMergeIntoStatement 22 | merge into bonuses b using(select employee_id,salary from employee where dept_no=20)e on(b.employee_id=e.employee_id)when matched then update set b.bonus=e.salary*0.1 when not matched then insert(b.employee_id,b.bonus)values(e.employee_id,e.salary*0.05) 23 | ; 24 | 25 | -- testMergeUpdateInsertOrderIssue401_2 26 | MERGE INTO a USING dual ON (col3 = ? AND col1 = ? AND col2 = ?) WHEN MATCHED THEN UPDATE SET col4 = col4 + ? WHEN NOT MATCHED THEN INSERT (col1, col2, col3, col4) VALUES (?, ?, ?, ?) 27 | ; 28 | 29 | -- testOracleHint 30 | merge into bonuses b using(select employee_id,salary from employee where dept_no=20)e on(b.employee_id=e.employee_id)when matched then update set b.bonus=e.salary*0.1 when not matched then insert(b.employee_id,b.bonus)values(e.employee_id,e.salary*0.05) 31 | ; 32 | 33 | -- testComplexOracleMergeIntoStatement 34 | merge into destinationvalue dest using(select themonth,identifyingkey,sum(netprice)netprice,sum(netdeductionprice)netdeductionprice,max(case rownumbermain when 1 then qualityindicator else null end)qualityindicatormain,max(case rownumberdeduction when 1 then qualityindicator else null end)qualityindicatordeduction from(select pd.themonth,coalesce(pd.identifyingkey,0)identifyingkey,coalesce(case pd.isdeduction when 1 then null else convertedcalculatedvalue end,0)netprice,coalesce(case pd.isdeduction when 1 then convertedcalculatedvalue else null end,0)netdeductionprice,pd.qualityindicator,row_number()over(partition by pd.themonth,pd.identifyingkey order by coalesce(pd.qualitymonth,to_date('18991230','yyyymmdd'))desc)rownumbermain,null rownumberdeduction from pricingdata pd where pd.thingskey in(:thingskeys)and pd.themonth>=:startdate and pd.themonth<=:enddate and pd.isdeduction=0 union all select pd.themonth,coalesce(pd.identifyingkey,0)identifyingkey,coalesce(case pd.isdeduction when 1 then null else convertedcalculatedvalue end,0)netprice,coalesce(case pd.isdeduction when 1 then convertedcalculatedvalue else null end,0)netdeductionprice,pd.qualityindicator,null rownumbermain,row_number()over(partition by pd.themonth,pd.identifyingkey order by coalesce(pd.qualitymonth,to_date('18991230','yyyymmdd'))desc)rownumberdeduction from pricingdata pd where pd.thingskey in(:thingskeys)and pd.themonth>=:startdate and pd.themonth<=:enddate and pd.isdeduction<>0)group by themonth,identifyingkey)data on(dest.themonth=data.themonth and coalesce(dest.identifyingkey,0)=data.identifyingkey)when matched then update set netprice=round(data.netprice,pricedecimalscale),deductionprice=round(data.netdeductionprice,pricedecimalscale),subtotalprice=round(data.netprice+(data.netdeductionprice*dest.hasdeductions),pricedecimalscale),qualityindicator=case dest.hasdeductions when 0 then data.qualityindicatormain else case when coalesce(data.checkmonth1,to_date('18991230','yyyymmdd'))>coalesce(data.checkmonth2,to_date('18991230','yyyymmdd'))then data.qualityindicatormain else data.qualityindicatordeduction end end,recuser=:recuser,recdate=:recdate where 1=1 and isimportant=1 and coalesce(data.someflag,-1)<>coalesce(round(something,1),-1)delete where isimportant=0 or coalesce(data.someflag,-1)=coalesce(round(something,1),-1)when not matched then insert(themonth,thingskey,isdeduction,createdat)values(data.themonth,data.thingskey,data.isdeduction,sysdate) 35 | ; 36 | 37 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/replace/ReplaceTest.sql: -------------------------------------------------------------------------------- 1 | -- testProblemReplaceParseDeparse 2 | REPLACE a_table (ID, A, B) SELECT A_ID, A, B FROM b_table 3 | ; 4 | 5 | -- testMultipleValues 6 | REPLACE INTO mytable (col1, col2, col3) VALUES (1, "aaa", now()), (2, "bbb", now()) 7 | ; 8 | 9 | -- testReplaceSyntax1 10 | replace mytable set col1='as',col2=?,col3=565 11 | ; 12 | 13 | -- testReplaceSyntax2 14 | replace mytable(col1,col2,col3)values('as',?,565) 15 | ; 16 | 17 | -- testReplaceSyntax3 18 | replace mytable(col1,col2,col3)select*from mytable3 19 | ; 20 | 21 | -- testProblemMissingIntoIssue389 22 | REPLACE INTO mytable (key, data) VALUES (1, "aaa") 23 | ; 24 | 25 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/select/ClickHouseTest.sql: -------------------------------------------------------------------------------- 1 | -- testGlobalJoin 2 | select a.*,b.*from lineorder_all as a global left join supplier_all as b on a.lolinenumber=b.ssuppkey 3 | ; 4 | 5 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/select/HiveTest.sql: -------------------------------------------------------------------------------- 1 | -- testLeftSemiJoin 2 | select something from sometable left semi join othertable 3 | ; 4 | 5 | -- testLeftSemiJoin 6 | select something from sometable left semi join othertable 7 | ; 8 | 9 | -- testGroupByGroupingSets 10 | select c1,c2,c3,max(value)from sometable group by c1,c2,c3 grouping sets((c1,c2),(c1,c2,c3),()) 11 | ; 12 | 13 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/select/KSQLTest.sql: -------------------------------------------------------------------------------- 1 | -- testKSQLBeforeAfterWindowedJoin 2 | select*from table1 t1 inner join table2 t2 within(1 minute,5 minutes)on t1.id=t2.id 3 | ; 4 | 5 | -- testKSQLBeforeAfterWindowedJoin 6 | select*from table1 t1 inner join table2 t2 within(1 minute,5 minutes)on t1.id=t2.id 7 | ; 8 | 9 | -- testKSQLEmitChangesWithLimit 10 | SELECT * FROM table1 t1 GROUP BY region.id EMIT CHANGES LIMIT 2 11 | ; 12 | 13 | -- testKSQLHoppingWindows 14 | select*from table1 t1 window hopping(size 30 seconds,advance by 10 minutes)group by region.id 15 | ; 16 | 17 | -- testKSQLHoppingWindows 18 | select*from table1 t1 window hopping(size 30 seconds,advance by 10 minutes)group by region.id 19 | ; 20 | 21 | -- testKSQLEmitChanges 22 | SELECT * FROM table1 t1 GROUP BY region.id EMIT CHANGES 23 | ; 24 | 25 | -- testKSQLTumblingWindows 26 | select*from table1 t1 window tumbling(size 30 seconds)group by region.id 27 | ; 28 | 29 | -- testKSQLTumblingWindows 30 | select*from table1 t1 window tumbling(size 30 seconds)group by region.id 31 | ; 32 | 33 | -- testKSQLWindowedJoin 34 | select*from table1 t1 inner join table2 t2 within(5 hours)on t1.id=t2.id 35 | ; 36 | 37 | -- testKSQLWindowedJoin 38 | select*from table1 t1 inner join table2 t2 within(5 hours)on t1.id=t2.id 39 | ; 40 | 41 | -- testKSQLSessionWindows 42 | select*from table1 t1 window session(5 minutes)group by region.id 43 | ; 44 | 45 | -- testKSQLSessionWindows 46 | select*from table1 t1 window session(5 minutes)group by region.id 47 | ; 48 | 49 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/select/NestedBracketsPerformanceTest.sql: -------------------------------------------------------------------------------- 1 | -- testNestedCaseWhenWithBracketsIssue1162 2 | create view view_name1 as select case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else(case when wdgfld.porttype=1 then 'input port' else '0' end)end)end)end)end)end)end)end)end)end)end)end)end)end columnalias from table1 3 | ; 4 | 5 | -- doIncreaseOfParseTimeTesting 6 | select if(1=1,1,2)from mytbl 7 | ; 8 | 9 | -- doIncreaseOfParseTimeTesting 10 | select if(1=1,if(1=1,1,2),2)from mytbl 11 | ; 12 | 13 | -- doIncreaseOfParseTimeTesting 14 | select if(1=1,if(1=1,if(1=1,1,2),2),2)from mytbl 15 | ; 16 | 17 | -- doIncreaseOfParseTimeTesting 18 | select if(1=1,if(1=1,if(1=1,if(1=1,1,2),2),2),2)from mytbl 19 | ; 20 | 21 | -- doIncreaseOfParseTimeTesting 22 | select if(1=1,if(1=1,if(1=1,if(1=1,if(1=1,1,2),2),2),2),2)from mytbl 23 | ; 24 | 25 | -- doIncreaseOfParseTimeTesting 26 | select if(1=1,if(1=1,if(1=1,if(1=1,if(1=1,if(1=1,1,2),2),2),2),2),2)from mytbl 27 | ; 28 | 29 | -- doIncreaseOfParseTimeTesting 30 | select if(1=1,if(1=1,if(1=1,if(1=1,if(1=1,if(1=1,if(1=1,1,2),2),2),2),2),2),2)from mytbl 31 | ; 32 | 33 | -- doIncreaseOfParseTimeTesting 34 | select if(1=1,if(1=1,if(1=1,if(1=1,if(1=1,if(1=1,if(1=1,if(1=1,1,2),2),2),2),2),2),2),2)from mytbl 35 | ; 36 | 37 | -- testIssue1013_2 38 | SELECT * FROM ((((((((((((((((tblA)))))))))))))))) 39 | ; 40 | 41 | -- testIssue1013_3 42 | SELECT * FROM (((tblA))) 43 | ; 44 | 45 | -- testIssue1013_4 46 | SELECT * FROM (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((tblA))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) 47 | ; 48 | 49 | -- testNestedCaseWhenWithoutBracketsIssue1162 50 | create view view_name1 as select case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else case when wdgfld.porttype=1 then 'input port' else '0' end end end end end end end end end end end end end end columnalias from table1 51 | ; 52 | 53 | -- testIssue766_2 54 | SELECT concat(concat(concat('1', '2'), '3'), '4'), col1 FROM tbl t1 55 | ; 56 | 57 | -- testIssue1013 58 | SELECT ((((((((((((((((tblA)))))))))))))))) FROM mytable 59 | ; 60 | 61 | -- testIssue1103 62 | select round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(round(0,0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0),0) 63 | ; 64 | 65 | -- testIssue235 66 | select case when(case when(case when(case when(1)then 0 end)then 0 end)then 0 end)then 0 end from a 67 | ; 68 | 69 | -- testIssue766 70 | select concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat('1','2'),'3'),'4'),'5'),'6'),'7'),'8'),'9'),'10'),'11'),'12'),'13'),'14'),'15'),'16'),'17'),'18'),'19'),'20'),'21'),col1 from tbl t1 71 | ; 72 | 73 | -- testIssue856 74 | SELECT if(month(today()) = 3, sum("Table5"."Month 002"), if(month(today()) = 3, sum("Table5"."Month 002"), if(month(today()) = 3, sum("Table5"."Month 002"), if(month(today()) = 3, sum("Table5"."Month 002"), if(month(today()) = 3, sum("Table5"."Month 002"), if(month(today()) = 3, sum("Table5"."Month 002"), 0)))))) FROM mytbl 75 | ; 76 | 77 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/select/PostgresTest.sql: -------------------------------------------------------------------------------- 1 | -- testJSonExpressionIssue1696 2 | select '{"key":"value"}'::json->'key' as x 3 | ; 4 | 5 | -- testExtractFunction 6 | select extract(hour from timestamp '2001-02-16 20:38:40') 7 | ; 8 | 9 | -- testExtractFunction 10 | select extract('hour' from timestamp '2001-02-16 20:38:40') 11 | ; 12 | 13 | -- testExtractFunction 14 | select extract('hours' from timestamp '2001-02-16 20:38:40') 15 | ; 16 | 17 | -- testExtractFunctionIssue1582 18 | select t0.operatienr,case when case when(t0.vc_begintijd_operatie is null or lpad((extract('hours' from t0.vc_begintijd_operatie::timestamp))::text,2,'0')||':'||lpad(extract('minutes' from t0.vc_begintijd_operatie::timestamp)::text,2,'0')='00:00')then null else(greatest(((extract('hours' from(t0.vc_eindtijd_operatie::timestamp-t0.vc_begintijd_operatie::timestamp))*60+extract('minutes' from(t0.vc_eindtijd_operatie::timestamp-t0.vc_begintijd_operatie::timestamp)))/60)::numeric(12,2),0))*60 end=0 then null else '25. meer dan 4 uur' end as snijtijd_interval 19 | ; 20 | 21 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/select/SQLiteTest.sql: -------------------------------------------------------------------------------- 1 | -- testInsertOrReplaceUpsert 2 | insert or replace into kjoblocks values(?,?,?) 3 | ; 4 | 5 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/select/SelectXMLSerializeTest.sql: -------------------------------------------------------------------------------- 1 | -- testXmlAgg1 2 | SELECT xmlserialize(xmlagg(xmltext(COMMENT_LINE) ORDER BY COMMENT_SEQUENCE) AS varchar (1024)) FROM mytable GROUP BY COMMENT_NUMBER 3 | ; 4 | 5 | -- testXmlAgg2 6 | SELECT xmlserialize(xmlagg(xmltext(COMMENT_LINE) ORDER BY COMMENT_SEQUENCE, COMMENT_LINE) AS varchar (1024)) FROM mytable GROUP BY COMMENT_NUMBER 7 | ; 8 | 9 | -- testXmlAgg3 10 | SELECT xmlserialize(xmlagg(xmltext(COMMENT_LINE) ORDER BY COMMENT_SEQUENCE) AS varchar (1024)) 11 | ; 12 | 13 | -- testXmlAgg4 14 | SELECT xmlserialize(xmlagg(xmltext(COMMENT_LINE_PREFIX || COMMENT_LINE) ORDER BY COMMENT_SEQUENCE) AS varchar (1024)) 15 | ; 16 | 17 | -- testXmlAgg5 18 | SELECT xmlserialize(xmlagg(xmltext(CONCAT(', ', TRIM(SOME_COLUMN))) ORDER BY MY_SEQUENCE) AS varchar (1024)) 19 | ; 20 | 21 | -- testXmlAgg6 22 | SELECT xmlserialize(xmlagg(xmltext(COMMENT_LINE)) AS varchar (1024)) 23 | ; 24 | 25 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/select/WindowFunctionTest.sql: -------------------------------------------------------------------------------- 1 | -- testListAggOverIssue1652 2 | select listagg(d.col_to_agg,'/')within group(order by d.col_to_agg)over(partition by d.part_col)as my_listagg from cte_dummy_data d 3 | ; 4 | 5 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/show/ShowTablesStatementTest.sql: -------------------------------------------------------------------------------- 1 | -- showTablesInDbName 2 | SHOW FULL TABLES IN db_name 3 | ; 4 | 5 | -- showTablesWhereExpression 6 | SHOW TABLES WHERE table_name = 'FOO' 7 | ; 8 | 9 | -- showTablesLikeExpression 10 | SHOW TABLES LIKE '%FOO%' 11 | ; 12 | 13 | -- showTables 14 | SHOW TABLES 15 | ; 16 | 17 | -- showTablesModifiers 18 | SHOW EXTENDED FULL TABLES 19 | ; 20 | 21 | -- showTablesFromDbName 22 | SHOW EXTENDED TABLES FROM db_name 23 | ; 24 | 25 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/truncate/TruncateTest.sql: -------------------------------------------------------------------------------- 1 | -- testTruncateDeparse 2 | TRUNCATE TABLE foo 3 | ; 4 | 5 | -- testTruncateCascadeDeparse 6 | TRUNCATE TABLE foo CASCADE 7 | ; 8 | 9 | -- testTruncateOnlyDeparse 10 | TRUNCATE TABLE ONLY foo CASCADE 11 | ; 12 | 13 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/update/UpdateTest.sql: -------------------------------------------------------------------------------- 1 | -- testUpdateLowPriority 2 | UPDATE LOW_PRIORITY table1 A SET A.columna = 'XXX' 3 | ; 4 | 5 | -- testUpdateWithFrom 6 | UPDATE table1 SET columna = 5 FROM table1 LEFT JOIN table2 ON col1 = col2 7 | ; 8 | 9 | -- testWith 10 | with a as(select 1 id_instrument_ref),b as(select 1 id_instrument_ref)update cfe.instrument_ref set id_instrument=null where id_instrument_ref=(select id_instrument_ref from a) 11 | ; 12 | 13 | -- testUpdateMultiTable 14 | UPDATE T1, T2 SET T1.C2 = T2.C2, T2.C3 = 'UPDATED' WHERE T1.C1 = T2.C1 AND T1.C2 < 10 15 | ; 16 | 17 | -- testUpdateWithFunctions 18 | UPDATE tablename SET col = SUBSTRING(col2, 1, 2) 19 | ; 20 | 21 | -- testUpdateIssue338_1 22 | UPDATE mytable SET status = (status & 1) 23 | ; 24 | 25 | -- testUpdateIssue338_2 26 | UPDATE mytable SET status = (status + 1) 27 | ; 28 | 29 | -- testUpdateIssue962Validate 30 | UPDATE tbl_user_card SET validate = '1', identityCodeFlag = 1 WHERE id = 9150000293816 31 | ; 32 | 33 | -- testUpdateWithSelect2 34 | UPDATE mytable SET (col1, col2, col3) = (SELECT a, b, c FROM mytable2) 35 | ; 36 | 37 | -- testUpdateWithOrderByAndLimit 38 | UPDATE tablename SET col = 'thing' WHERE id = 1 ORDER BY col LIMIT 10 39 | ; 40 | 41 | -- testUpdateIgnoreModifier 42 | UPDATE IGNORE table1 A SET A.columna = 'XXX' 43 | ; 44 | 45 | -- testUpdateIgnoreModifier 46 | UPDATE table1 A SET A.columna = 'XXX' 47 | ; 48 | 49 | -- testUpdateWithSelect 50 | UPDATE NATION SET (N_NATIONKEY) = (SELECT ? FROM SYSIBM.SYSDUMMY1) 51 | ; 52 | 53 | -- testUpdateIssue508LeftShift 54 | UPDATE user SET num = 1 << 1 WHERE id = 1 55 | ; 56 | 57 | -- testUpdateIssue338 58 | UPDATE mytable SET status = (status & ~1) 59 | ; 60 | 61 | -- testUpdateIssue750 62 | update a,(select*from c)b set a.id=b.id where a.id=b.id 63 | ; 64 | 65 | -- testUpdateIssue826 66 | update message_topic inner join message_topic_config on message_topic.id=message_topic_config.topic_id set message_topic_config.enable_flag='n',message_topic_config.updated_by='test',message_topic_config.update_at='2019-07-16' where message_topic.name='test' and message_topic_config.enable_flag='y' 67 | ; 68 | 69 | -- testUpdateWithOrderBy 70 | UPDATE tablename SET col = 'thing' WHERE id = 1 ORDER BY col 71 | ; 72 | 73 | -- testUpdateWithDeparser 74 | UPDATE table1 AS A SET A.columna = 'XXX' WHERE A.cod_table = 'YYY' 75 | ; 76 | 77 | -- testUpdateMultipleModifiers 78 | UPDATE LOW_PRIORITY IGNORE table1 A SET A.columna = 'XXX' 79 | ; 80 | 81 | -- testUpdateOutputClause 82 | update humanresources.employee set vacationhours=vacationhours*1.25,modifieddate=getdate()output inserted.businessentityid,deleted.vacationhours,inserted.vacationhours,inserted.modifieddate into @mytablevar 83 | ; 84 | 85 | -- testUpdateOutputClause 86 | update production.workorder set scrapreasonid=4 output deleted.scrapreasonid,inserted.scrapreasonid,inserted.workorderid,inserted.productid,p.name into @mytestvar from production.workorder as wo inner join production.product as p on wo.productid=p.productid and wo.scrapreasonid=16 and p.productid=733 87 | ; 88 | 89 | -- testUpdateWithReturningList 90 | UPDATE tablename SET col = 'thing' WHERE id = 1 ORDER BY col LIMIT 10 RETURNING col_1, col_2, col_3 91 | ; 92 | 93 | -- testUpdateWithReturningList 94 | UPDATE tablename SET col = 'thing' WHERE id = 1 RETURNING col_1, col_2, col_3 95 | ; 96 | 97 | -- testUpdateWithReturningList 98 | UPDATE tablename SET col = 'thing' WHERE id = 1 ORDER BY col LIMIT 10 RETURNING col_1 AS Bar, col_2 AS Baz, col_3 AS Foo 99 | ; 100 | 101 | -- testUpdateWithReturningList 102 | UPDATE tablename SET col = 'thing' WHERE id = 1 RETURNING col_1 AS Bar, col_2 AS Baz, col_3 AS Foo 103 | ; 104 | 105 | -- testUpdateWithReturningList 106 | UPDATE tablename SET col = 'thing' WHERE id = 1 RETURNING ABS(col_1) AS Bar, ABS(col_2), col_3 AS Foo 107 | ; 108 | 109 | -- testOracleHint 110 | update mytable set col1='as',col2=?,col3=565 where o>=3 111 | ; 112 | 113 | -- testUpdateIssue167_SingleQuotes 114 | update tablename set name='customer 2',address='address \' ddad2',auth_key='samplekey' where id=2 115 | ; 116 | 117 | -- testUpdateWithReturningAll 118 | UPDATE tablename SET col = 'thing' WHERE id = 1 ORDER BY col LIMIT 10 RETURNING * 119 | ; 120 | 121 | -- testUpdateWithReturningAll 122 | UPDATE tablename SET col = 'thing' WHERE id = 1 RETURNING * 123 | ; 124 | 125 | -- testUpdateWithLimit 126 | UPDATE tablename SET col = 'thing' WHERE id = 1 LIMIT 10 127 | ; 128 | 129 | -- testUpdateSetsIssue1316 130 | update test set(a,b)=(select '1','2') 131 | ; 132 | 133 | -- testUpdateSetsIssue1316 134 | update test set a='1',b='2' 135 | ; 136 | 137 | -- testUpdateSetsIssue1316 138 | update test set(a,b)=('1','2') 139 | ; 140 | 141 | -- testUpdateSetsIssue1316 142 | update test set(a,b)=(values('1','2')) 143 | ; 144 | 145 | -- testUpdateSetsIssue1316 146 | update test set(a,b)=(1,(select 2)) 147 | ; 148 | 149 | -- testUpdateSetsIssue1316 150 | update prpjpaymentbill b set(b.packagecode,b.packageremark,b.agentcode)=(select p.payrefreason,p.classcode,p.riskcode from prpjcommbill p where p.policertiid='sddh200937010330006366'),b.payrefnotype='05',b.packageunit='4101170402' where b.payrefno='b370202091026000005' 151 | ; 152 | 153 | -- testUpdateVariableAssignment 154 | UPDATE transaction_id SET latest_id_wallet = (@cur_id_wallet := latest_id_wallet) + 1 155 | ; 156 | 157 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/upsert/UpsertTest.sql: -------------------------------------------------------------------------------- 1 | -- testUpsertWithSelect 2 | UPSERT INTO mytable (mycolumn) WITH a AS (SELECT mycolumn FROM mytable) SELECT mycolumn FROM a 3 | ; 4 | 5 | -- testUpsertWithSelect 6 | UPSERT INTO mytable (mycolumn) (WITH a AS (SELECT mycolumn FROM mytable) SELECT mycolumn FROM a) 7 | ; 8 | 9 | -- testHexValues2 10 | UPSERT INTO TABLE2 VALUES ('1', "DSDD", 0xEFBFBDC7AB) 11 | ; 12 | 13 | -- testHexValues3 14 | UPSERT INTO TABLE2 VALUES ('1', "DSDD", 0xabcde) 15 | ; 16 | 17 | -- testHexValues 18 | UPSERT INTO TABLE2 VALUES ('1', "DSDD", x'EFBFBDC7AB') 19 | ; 20 | 21 | -- testUpsertMultiRowValue 22 | UPSERT INTO mytable (col1, col2) VALUES (a, b), (d, e) 23 | ; 24 | 25 | -- testUpsertWithKeywords 26 | UPSERT INTO kvPair (value, key) VALUES (?, ?) 27 | ; 28 | 29 | -- testSimpleUpsert 30 | UPSERT INTO example (num, name, address, tel) VALUES (1, 'name', 'test ', '1234-1234') 31 | ; 32 | 33 | -- testUpsertHasSelect 34 | UPSERT INTO mytable (mycolumn) SELECT mycolumn FROM mytable 35 | ; 36 | 37 | -- testUpsertHasSelect 38 | UPSERT INTO mytable (mycolumn) (SELECT mycolumn FROM mytable) 39 | ; 40 | 41 | -- testDuplicateKey 42 | UPSERT INTO Users0 (UserId, Key, Value) VALUES (51311, 'T_211', 18) ON DUPLICATE KEY UPDATE Value = 18 43 | ; 44 | 45 | -------------------------------------------------------------------------------- /src/test/resources/net/sf/jsqlparser/statement/values/ValuesTest.sql: -------------------------------------------------------------------------------- 1 | -- testComplexWithQueryIssue561 2 | WITH split (word, str, hascomma) AS (VALUES ('', 'Auto,A,1234444', 1) UNION ALL SELECT substr(str, 0, CASE WHEN instr(str, ',') THEN instr(str, ',') ELSE length(str) + 1 END), ltrim(substr(str, instr(str, ',')), ','), instr(str, ',') FROM split WHERE hascomma) SELECT trim(word) FROM split WHERE word != '' 3 | ; 4 | 5 | -- testDuplicateKey 6 | VALUES (1, 2, 'test') 7 | ; 8 | 9 | --------------------------------------------------------------------------------