|
1 |
| -# JSqlParser |
| 1 | +# [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"/> |
2 | 2 |
|
3 | 3 | 
|
4 | 4 |
|
|
9 | 9 |
|
10 | 10 | [](https://gitter.im/JSQLParser/JSqlParser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
11 | 11 |
|
12 |
| -Look here for more information and examples: https://github.com/JSQLParser/JSqlParser/wiki. |
13 |
| - |
14 |
| -## License |
15 |
| - |
16 |
| -JSqlParser is dual licensed under **LGPL V2.1** or **Apache Software License, Version 2.0**. |
17 |
| - |
18 |
| -## Discussion |
19 |
| - |
20 |
| -Please provide feedback on: |
21 |
| - |
22 |
| -* API changes: extend visitor with return values (https://github.com/JSQLParser/JSqlParser/issues/901) |
23 |
| - |
24 |
| -## News |
25 |
| -* Released version **4.5** of JSqlParser |
26 |
| -* The array parsing is the default behaviour. Square bracket quotation has to be enabled using |
27 |
| - a parser flag (**CCJSqlParser.withSquareBracketQuotation**). |
28 |
| -* due to an API change the version will be 3.0 |
29 |
| -* JSqlParser uses now Java 8 at the minimum |
30 |
| - |
31 |
| -More news can be found here: https://github.com/JSQLParser/JSqlParser/wiki/News. |
32 |
| - |
33 |
| -## Alternatives to JSqlParser? |
34 |
| -[**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. |
35 |
| - |
36 |
| -## JSqlParser |
37 |
| - |
38 |
| -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. |
39 |
| - |
40 |
| -## Support |
41 |
| -If you need help using JSqlParser feel free to file an issue or contact me. |
42 |
| - |
43 |
| -## Contributions |
44 |
| -To help JSqlParser's development you are encouraged to provide |
45 |
| -* feedback |
46 |
| -* bugreports |
47 |
| -* pull requests for new features |
48 |
| -* improvement requests |
49 |
| -* fund new features or sponsor JSqlParser ([**Sponsor**](https://www.paypal.me/wumpz)) |
50 |
| - |
51 |
| -**Please write in English, since it's the language most of the dev team knows.** |
| 12 | +## Summary |
52 | 13 |
|
53 |
| -Any requests for examples or any particular documentation will be most welcome. |
| 14 | +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)): |
54 | 15 |
|
55 |
| -## Extensions in the latest SNAPSHOT version 4.6 |
56 |
| - |
57 |
| -* support for named windows in window expressions: `SELECT sum(c) OVER winName FROM mytable WINDOW winName AS (PARTITION BY pcol)` |
| 16 | +```sql |
| 17 | +SELECT 1 FROM dual WHERE a = b |
| 18 | +``` |
58 | 19 |
|
59 |
| -Additionally, we have fixed many errors and improved the code quality and the test coverage. |
| 20 | +```text |
| 21 | + SQL Text |
| 22 | + └─Statements: net.sf.jsqlparser.statement.select.Select |
| 23 | + └─selectBody: net.sf.jsqlparser.statement.select.PlainSelect |
| 24 | + ├─selectItems -> Collection<SelectExpressionItem> |
| 25 | + │ └─selectItems: net.sf.jsqlparser.statement.select.SelectExpressionItem |
| 26 | + │ └─LongValue: 1 |
| 27 | + ├─Table: dual |
| 28 | + └─where: net.sf.jsqlparser.expression.operators.relational.EqualsTo |
| 29 | + ├─Column: a |
| 30 | + └─Column: b |
| 31 | +``` |
60 | 32 |
|
61 |
| -## Extensions of JSqlParser releases |
| 33 | +```java |
| 34 | +Statement statement = CCJSqlParserUtil.parse(sqlStr); |
| 35 | +if (statement instanceof Select) { |
| 36 | + Select select = (Select) statement; |
| 37 | + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); |
62 | 38 |
|
63 |
| -* [Release Notes](https://github.com/JSQLParser/JSqlParser/releases) |
64 |
| -* Modifications before GitHub's release tagging are listed in the [Older Releases](https://github.com/JSQLParser/JSqlParser/wiki/Older-Releases) page. |
| 39 | + SelectExpressionItem selectExpressionItem = |
| 40 | + (SelectExpressionItem) plainSelect.getSelectItems().get(0); |
65 | 41 |
|
66 |
| -## Building from the sources |
| 42 | + Table table = (Table) plainSelect.getFromItem(); |
67 | 43 |
|
68 |
| -As the project is a Maven project, building is rather simple by running: |
69 |
| -```shell |
70 |
| -mvn package |
| 44 | + EqualsTo equalsTo = (EqualsTo) plainSelect.getWhere(); |
| 45 | + Column a = (Column) equalsTo.getLeftExpression(); |
| 46 | + Column b = (Column) equalsTo.getRightExpression(); |
| 47 | +} |
71 | 48 | ```
|
72 | 49 |
|
73 |
| -Since 4.2, alternatively Gradle can be used |
74 |
| -```shell |
75 |
| -gradle build |
76 |
| -``` |
77 |
| - |
78 |
| -The project requires the following to build: |
79 |
| -- Maven (or Gradle) |
80 |
| -- JDK 8 or later. The JAR will target JDK 8, but the version of the maven-compiler-plugin that JSqlParser uses requires JDK 8+ |
| 50 | +## [Supported Grammar and Syntax](https://jsqlparser.github.io/JSqlParser/syntax.html) |
81 | 51 |
|
82 |
| -This will produce the jsqlparser-VERSION.jar file in the `target/` directory (`build/libs/jsqlparser-VERSION.jar` in case of Gradle). |
| 52 | +**JSqlParser** aims to support the SQL standard as well as all major RDBMS. Any missing syntax or features can be added on demand. |
83 | 53 |
|
84 |
| -**To build this project without using Maven or Gradle, one has to build the parser by JavaCC using the CLI options it provides.** |
| 54 | +| RDBMS | Statements | |
| 55 | +|------------------------------------|-----------------------------------------| |
| 56 | +| 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 ...` | |
85 | 57 |
|
86 |
| -## Debugging through problems |
87 | 58 |
|
88 |
| -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. |
| 59 | +**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)). |
89 | 60 |
|
90 |
| -## Source Code conventions |
| 61 | +## [Documentation](https://jsqlparser.github.io/JSqlParser) |
91 | 62 |
|
92 |
| -Recently a checkstyle process was integrated into the build process. JSqlParser follows the sun java format convention. There are no TABs allowed. Use spaces. |
| 63 | +### [Samples](https://jsqlparser.github.io/JSqlParser/usage.html#parse-a-sql-statements) |
| 64 | +### [Build Instructions](https://jsqlparser.github.io/JSqlParser/usage.html) |
| 65 | +### [Contribution](https://jsqlparser.github.io/JSqlParser/contribution.html) |
| 66 | +### [Change Log](https://jsqlparser.github.io/JSqlParser/changelog.html#latest-changes-since-jsqlparser-version) |
| 67 | +### [Issues](https://github.com/JSQLParser/JSqlParser/issues) |
93 | 68 |
|
94 |
| -```java |
95 |
| -public void setUsingSelect(SubSelect usingSelect) { |
96 |
| - this.usingSelect = usingSelect; |
97 |
| - if (this.usingSelect != null) { |
98 |
| - this.usingSelect.setUseBrackets(false); |
99 |
| - } |
100 |
| -} |
101 |
| -``` |
102 |
| - |
103 |
| -This is a valid piece of source code: |
104 |
| -* blocks without braces are not allowed |
105 |
| -* after control statements (if, while, for) a whitespace is expected |
106 |
| -* the opening brace should be in the same line as the control statement |
107 |
| - |
108 |
| -## Maven Repository |
109 |
| - |
110 |
| -JSQLParser is deployed at Sonatype open source maven repository. |
111 |
| -Starting from now I will deploy there. The first snapshot version there will be 0.8.5-SNAPSHOT. |
112 |
| -To use it this is the repository configuration: |
113 |
| - |
114 |
| -```xml |
115 |
| -<repositories> |
116 |
| - <repository> |
117 |
| - <id>jsqlparser-snapshots</id> |
118 |
| - <snapshots> |
119 |
| - <enabled>true</enabled> |
120 |
| - </snapshots> |
121 |
| - <url>https://oss.sonatype.org/content/groups/public/</url> |
122 |
| - </repository> |
123 |
| -</repositories> |
124 |
| -``` |
125 |
| -These repository releases will be synchronised to Maven Central. Snapshots remain at Sonatype. |
126 |
| - |
127 |
| -And this is the dependency declaration in your pom: |
128 |
| -```xml |
129 |
| -<dependency> |
130 |
| - <groupId>com.github.jsqlparser</groupId> |
131 |
| - <artifactId>jsqlparser</artifactId> |
132 |
| - <version>4.5</version> |
133 |
| -</dependency> |
134 |
| -``` |
| 69 | +## License |
135 | 70 |
|
| 71 | +**JSqlParser** is dual licensed under **LGPL V2.1** or **Apache Software License, Version 2.0**. |
0 commit comments