Skip to content

Commit

Permalink
Oracle Alternative Quoting (#1722)
Browse files Browse the repository at this point in the history
* Fixes #1684: Support CREATE MATERIALIZED VIEW with AUTO REFRESH

Support parsing create view statements in Redshift with AUTO REFRESH
option.

* Reduce cyclomatic complexity in CreateView.toString

Extract adding the force option into a dedicated method resulting in the
cyclomatic complexity reduction of the CreateView.toString method.

* Enhanced Keywords

Add Keywords and document, which keywords are allowed for what purpose

* Fix incorrect tests

* Define Reserved Keywords explicitly
Derive All Keywords from Grammar directly
Generate production for Object Names (semi-) automatically
Add parametrized Keyword Tests

* Fix test resources

* Adjust Gradle to JUnit 5

Parallel Test execution
Gradle Caching
Explicitly request for latest JavaCC 7.0.10

* Do not mark SpeedTest for concurrent execution

* Remove unused imports

* Adjust Gradle to JUnit 5

Parallel Test execution
Gradle Caching
Explicitly request for latest JavaCC 7.0.10

* Do not mark SpeedTest for concurrent execution

* Remove unused imports

* Sphinx Documentation

Update the MANTICORE Sphinx Theme, but ignore it in GIT
Add the content to the Sphinx sites
Add a Gradle function to derive Stable and Snapshot version from GIT Tags
Add a Gradle GIT change task
Add a Gradle sphinx task
Add a special Test case for illustrating the use of JSQLParser

* doc: request for `Conventional Commit` messages

* feat: make important Classes Serializable

Implement Serializable for persisting via ObjectOutputStream

* chore: Make Serializable

* doc: Better integration of the RR diagrams

- apply neutral Sphinx theme
- insert the RR diagrams into the sphinx sources
- better documentation on Gradle dependencies
- link GitHub repository

* Merge

* feat: Oracle Alternative Quoting

- add support for Oracle Alternative Quoting e.g. `q'(...)'`
- fixes #1718
- add a Logo and FavIcon to the Website
- document recent changes on Quoting/Escaping
- add an example on building SQL from Java
- rework the README.md, promote the Website
- add Spotless Formatter, using Google Java Style (with Tab=4 Spaces)

* style: Appease PMD/Codacy

* doc: fix the issue template

- fix the issue template
- fix the -SNAPSHOT version number

* Update issue templates

* Update issue templates

* feat: Support more Statement Separators

- `GO`
- Slash `/`
- Two empty lines

---------

Co-authored-by: zaza <tzarna@gmail.com>
  • Loading branch information
manticore-projects and zaza authored Feb 7, 2023
1 parent 2ced7de commit e71e57d
Show file tree
Hide file tree
Showing 26 changed files with 5,739 additions and 2,340 deletions.
25 changes: 19 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
---
name: SQL Parser Error
name: @ SQL Parser Error
about: Create a report to help us improve
title: 'JSQLParser Version : RDBMS : failing feature description'
title: '[BUG] JSQLParser Version : RDBMS : failing feature description'
labels: 'Parser Error', 'Feature Request', 'Documentation', 'Java API', 'RDBMS support'
assignees: ''

---

**Failing SQL Feature**
<!--
Note: Please search to see if an issue already exists for the bug you encountered.
-->

### Failing SQL Feature:
<!--
- Brief description of the failing SQL feature
- Example: `WITH ROLLUP` can't be parsed
-->

**SQL Example**
### SQL Example:
<!--
- Simplified Query Example, focusing on the failing feature
```sql
-- Replace with your ACTUAL example
select 1
from dual
```
-->

**Software Information**
### Software Information:
<!--
- JSqlParser version
- Database (e. g. Oracle, MS SQL Server, H2, PostgreSQL, IBM DB2 )
-->

**Tips**
### Tips:
<!--
Please write in English and avoid Screenshots (as we can't copy and paste content from it).
[Try your example online with the latest JSQLParser](http://217.160.215.75:8080/jsqlformatter/demo.html) and share the link in the error report.
Do provide Links or References to the specific Grammar and Syntax you are trying to use.
-->
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Feature request
about: Suggest an unsupported Statement or Expression
title: "[FEATURE] missing feature description"
labels: ''
assignees: ''

---

### Grammar or Syntax Description
- Brief description of the failing SQL feature and the EBNF
- Example: `WITH ROLLUP` clause is not supported yet

### SQL Example
- Simplified Query Example, focusing on the failing feature
```sql
-- Replace with your ACTUAL example
select 1
from dual
```
- Please don't send screen shots
### Additional context
The used JSQLParser Version (please test the latest SNAPSHOT version before submitting).
State the applicable RDBMS and version
Links to the reference documentation
### Tips:
<!--
Please write in English and avoid Screenshots (as we can't copy and paste content from it).
-->
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/sql-parser-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: SQL Parser Error
about: Report a Parser Error
title: "[BUG] JSQLParser Version : RDBMS : failing feature description"
labels: ''
assignees: ''

---

Always check against the **Latest SNAPSHOT of JSQLParser** and the [Syntax Diagram](https://jsqlparser.github.io/JSqlParser/syntax.html)

### Failing SQL Feature:
- Brief description of the failing SQL feature
- Example: `WITH ROLLUP` can't be parsed

### SQL Example:
- Simplified Query Example, focusing on the failing feature
```sql
-- Replace with your ACTUAL example
select 1
from dual
```

### Software Information:
- JSqlParser version
- Database (e. g. Oracle, MS SQL Server, H2, PostgreSQL, IBM DB2 )

### Tips:
Please write in English and avoid Screenshots (as we can't copy and paste content from it).
[Try your example online with the latest JSQLParser](http://217.160.215.75:8080/jsqlformatter/demo.html) and share the link in the error report.
Do provide Links or References to the specific Grammar and Syntax you are trying to use.
152 changes: 44 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# JSqlParser
# [JSqlParser (4.5 Stable or 4.6 Snapshot)](https://jsqlparser.github.io/JSqlParser) <img src="src/site/sphinx/_images/logo-no-background.svg" alt="drawing" width="200" align="right"/>

![Build Status](https://github.com/JSQLParser/JSqlParser/actions/workflows/maven.yml/badge.svg)

Expand All @@ -9,127 +9,63 @@

[![Gitter](https://badges.gitter.im/JSQLParser/JSqlParser.svg)](https://gitter.im/JSQLParser/JSqlParser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

Look here for more information and examples: https://github.com/JSQLParser/JSqlParser/wiki.

## License

JSqlParser is dual licensed under **LGPL V2.1** or **Apache Software License, Version 2.0**.

## Discussion

Please provide feedback on:

* API changes: extend visitor with return values (https://github.com/JSQLParser/JSqlParser/issues/901)

## News
* Released version **4.5** of JSqlParser
* The array parsing is the default behaviour. Square bracket quotation has to be enabled using
a parser flag (**CCJSqlParser.withSquareBracketQuotation**).
* due to an API change the version will be 3.0
* JSqlParser uses now Java 8 at the minimum

More news can be found here: https://github.com/JSQLParser/JSqlParser/wiki/News.

## Alternatives to JSqlParser?
[**General SQL Parser**](http://www.sqlparser.com/features/introduce.php?utm_source=github-jsqlparser&utm_medium=text-general) looks pretty good, with extended SQL syntax (like PL/SQL and T-SQL) and java + .NET APIs. The tool is commercial (license available online), with a free download option.

## JSqlParser

JSqlParser is a SQL statement parser. It translates SQLs in a traversable hierarchy of Java classes. JSqlParser is not limited to one database but provides support for a lot of specials of Oracle, SqlServer, MySQL, PostgreSQL ... To name some, it has support for Oracles join syntax using (+), PostgreSQLs cast syntax using ::, relational operators like != and so on.

## Support
If you need help using JSqlParser feel free to file an issue or contact me.

## Contributions
To help JSqlParser's development you are encouraged to provide
* feedback
* bugreports
* pull requests for new features
* improvement requests
* fund new features or sponsor JSqlParser ([**Sponsor**](https://www.paypal.me/wumpz))

**Please write in English, since it's the language most of the dev team knows.**
## Summary

Any requests for examples or any particular documentation will be most welcome.
Please visit the [WebSite](https://jsqlparser.github.io/JSqlParser). **JSqlParser** is a RDBMS agnostic SQL statement parser. It translates SQL statements into a traversable hierarchy of Java classes (see [Samples](https://jsqlparser.github.io/JSqlParser/usage.html#parse-a-sql-statements)):

## Extensions in the latest SNAPSHOT version 4.6

* support for named windows in window expressions: `SELECT sum(c) OVER winName FROM mytable WINDOW winName AS (PARTITION BY pcol)`
```sql
SELECT 1 FROM dual WHERE a = b
```

Additionally, we have fixed many errors and improved the code quality and the test coverage.
```text
SQL Text
└─Statements: net.sf.jsqlparser.statement.select.Select
└─selectBody: net.sf.jsqlparser.statement.select.PlainSelect
├─selectItems -> Collection<SelectExpressionItem>
│ └─selectItems: net.sf.jsqlparser.statement.select.SelectExpressionItem
│ └─LongValue: 1
├─Table: dual
└─where: net.sf.jsqlparser.expression.operators.relational.EqualsTo
├─Column: a
└─Column: b
```

## Extensions of JSqlParser releases
```java
Statement statement = CCJSqlParserUtil.parse(sqlStr);
if (statement instanceof Select) {
Select select = (Select) statement;
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();

* [Release Notes](https://github.com/JSQLParser/JSqlParser/releases)
* Modifications before GitHub's release tagging are listed in the [Older Releases](https://github.com/JSQLParser/JSqlParser/wiki/Older-Releases) page.
SelectExpressionItem selectExpressionItem =
(SelectExpressionItem) plainSelect.getSelectItems().get(0);

## Building from the sources
Table table = (Table) plainSelect.getFromItem();

As the project is a Maven project, building is rather simple by running:
```shell
mvn package
EqualsTo equalsTo = (EqualsTo) plainSelect.getWhere();
Column a = (Column) equalsTo.getLeftExpression();
Column b = (Column) equalsTo.getRightExpression();
}
```

Since 4.2, alternatively Gradle can be used
```shell
gradle build
```

The project requires the following to build:
- Maven (or Gradle)
- JDK 8 or later. The JAR will target JDK 8, but the version of the maven-compiler-plugin that JSqlParser uses requires JDK 8+
## [Supported Grammar and Syntax](https://jsqlparser.github.io/JSqlParser/syntax.html)

This will produce the jsqlparser-VERSION.jar file in the `target/` directory (`build/libs/jsqlparser-VERSION.jar` in case of Gradle).
**JSqlParser** aims to support the SQL standard as well as all major RDBMS. Any missing syntax or features can be added on demand.

**To build this project without using Maven or Gradle, one has to build the parser by JavaCC using the CLI options it provides.**
| RDBMS | Statements |
|------------------------------------|-----------------------------------------|
| Oracle<br>MS SQL Server and Sybase<br>PostgreSQL<br>MySQL and MariaDB<br>DB2<br>H2 and HSQLDB and Derby<br>SQLite| `SELECT`<br>`INSERT`, `UPDATE`, `UPSERT`, `MERGE`<br>`DELETE`, `TRUNCATE TABLE`<br>`CREATE ...`, `ALTER ....`, `DROP ...`<br>`WITH ...` |

## Debugging through problems

Refer to the [Visualize Parsing](https://github.com/JSQLParser/JSqlParser/wiki/Examples-of-SQL-parsing#visualize-parsing) section to learn how to run the parser in debug mode.
**JSqlParser** can also be used to create SQL Statements from Java Code with a fluent API (see [Samples](https://jsqlparser.github.io/JSqlParser/usage.html#build-a-sql-statements)).

## Source Code conventions
## [Documentation](https://jsqlparser.github.io/JSqlParser)

Recently a checkstyle process was integrated into the build process. JSqlParser follows the sun java format convention. There are no TABs allowed. Use spaces.
### [Samples](https://jsqlparser.github.io/JSqlParser/usage.html#parse-a-sql-statements)
### [Build Instructions](https://jsqlparser.github.io/JSqlParser/usage.html)
### [Contribution](https://jsqlparser.github.io/JSqlParser/contribution.html)
### [Change Log](https://jsqlparser.github.io/JSqlParser/changelog.html#latest-changes-since-jsqlparser-version)
### [Issues](https://github.com/JSQLParser/JSqlParser/issues)

```java
public void setUsingSelect(SubSelect usingSelect) {
this.usingSelect = usingSelect;
if (this.usingSelect != null) {
this.usingSelect.setUseBrackets(false);
}
}
```

This is a valid piece of source code:
* blocks without braces are not allowed
* after control statements (if, while, for) a whitespace is expected
* the opening brace should be in the same line as the control statement

## Maven Repository

JSQLParser is deployed at Sonatype open source maven repository.
Starting from now I will deploy there. The first snapshot version there will be 0.8.5-SNAPSHOT.
To use it this is the repository configuration:

```xml
<repositories>
<repository>
<id>jsqlparser-snapshots</id>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
```
These repository releases will be synchronised to Maven Central. Snapshots remain at Sonatype.

And this is the dependency declaration in your pom:
```xml
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>4.5</version>
</dependency>
```
## License

**JSqlParser** is dual licensed under **LGPL V2.1** or **Apache Software License, Version 2.0**.
Loading

0 comments on commit e71e57d

Please sign in to comment.