Skip to content

Commit 84709a9

Browse files
Merge branch 'master' of github.com:JSQLParser/JSqlParser
2 parents de94651 + 7ddb7c8 commit 84709a9

5 files changed

Lines changed: 113 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ Also I would like to know about needed examples or documentation stuff.
5656

5757
## Extensions in the latest SNAPSHOT version 4.4
5858

59+
* support for **timestamp with local time zone**
60+
* improved support for quoted identifiers in casts
61+
5962
Additionally, we have fixed many errors and improved the code quality and the test coverage.
6063

6164
## Extensions of JSqlParser releases

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ TOKEN : /* Operators */
449449

450450
TOKEN : /* Date/Time with time zones */
451451
{
452-
<DT_ZONE: <K_DATETIMELITERAL> (<WHITESPACE>)* ("(" <S_LONG> ")")? (<WHITESPACE>)* (<K_WITH> | <K_WITHOUT>) (<WHITESPACE>)+ "TIME" (<WHITESPACE>)+ <K_ZONE>>
452+
<DT_ZONE: <K_DATETIMELITERAL> (<WHITESPACE>)* ("(" <S_LONG> ")")? (<WHITESPACE>)* (<K_WITH> | <K_WITHOUT>) ((<WHITESPACE>)+ <K_LOCAL>)? (<WHITESPACE>)+ "TIME" (<WHITESPACE>)+ <K_ZONE>>
453453
}
454454

455455
TOKEN : /* Numeric Constants */
@@ -1641,7 +1641,7 @@ String RelObjectNameWithoutValue() :
16411641
| tk=<K_ALGORITHM> | tk=<K_AT>
16421642
| tk=<K_BYTE> | tk=<K_CHAR> | tk=<K_CHANGE> | tk=<K_CHARACTER>
16431643
| tk=<K_CAST> | tk =<K_TRY_CAST> | tk=<K_COMMENT> | tk=<K_COSTS> | tk=<K_DISABLE> | tk=<K_DESC>
1644-
| tk=<K_DO> | tk=<K_EXTRACT> | tk=<K_FILTER> | tk=<K_FIRST> | tk=<K_FOLLOWING> | tk=<K_JSON>
1644+
| tk=<K_DO> | tk=<K_DEFAULT> | tk=<K_EXTRACT> | tk=<K_FILTER> | tk=<K_FIRST> | tk=<K_FOLLOWING> | tk=<K_JSON>
16451645
| tk=<K_LAST> | tk=<K_LEADING> | tk=<K_MATERIALIZED> | tk=<K_NULLS> | tk=<K_PARTITION> | tk=<K_RANGE>
16461646
| tk=<K_ROW> | tk=<K_ROWS> | tk=<K_SIBLINGS> | tk=<K_XML>
16471647
| tk=<K_COLUMN> | tk=<K_REPLACE> | tk=<K_TRUNCATE> | tk=<K_KEY>
@@ -4393,7 +4393,7 @@ Expression CaseWhenExpression() #CaseWhenExpression:
43934393
}
43944394
{
43954395
<K_CASE> { caseCounter++; }
4396-
[ switchExp=Condition() ]
4396+
[ switchExp=Expression() ]
43974397
( clause=WhenThenSearchCondition() { whenClauses.add(clause); } )+
43984398
[<K_ELSE> (LOOKAHEAD( ["("] CaseWhenExpression() [")"] ( <K_WHEN> | <K_ELSE> | <K_END> ) ) ["("] elseExp=CaseWhenExpression() [")" { ((CaseExpression) elseExp).setUsingBrackets(true); } ]
43994399
| elseExp=Expression()
@@ -5104,7 +5104,7 @@ ColDataType ColDataType():
51045104
| tk=<K_DOUBLE> [LOOKAHEAD(2) tk2=<K_PRECISION>] { colDataType.setDataType(tk.image + (tk2!=null?" " + tk2.image:"")); }
51055105
| ( tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER> | tk=<K_DATETIMELITERAL> | tk=<K_DATE_LITERAL> | tk=<K_XML> | tk=<K_INTERVAL>
51065106
| tk=<DT_ZONE> | tk=<K_CHAR> | tk=<K_SET> | tk=<K_BINARY> | tk=<K_JSON> )
5107-
[ "." tk2=<S_IDENTIFIER> ]
5107+
[ "." (tk2=<S_IDENTIFIER> | tk2=<S_QUOTED_IDENTIFIER>) ]
51085108
{ if (tk2!=null) colDataType.setDataType(tk.image + "." + tk2.image); else colDataType.setDataType(tk.image); }
51095109
| tk=<K_UNSIGNED> [LOOKAHEAD(2) tk2=<S_IDENTIFIER>]
51105110
{ if (tk2!=null) colDataType.setDataType(tk.image + " " + tk2.image); else colDataType.setDataType(tk.image); }
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2022 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.expression;
11+
12+
import net.sf.jsqlparser.JSQLParserException;
13+
import net.sf.jsqlparser.test.TestUtils;
14+
import org.junit.jupiter.api.Test;
15+
16+
/**
17+
* @author Mathieu Goeminne
18+
*/
19+
public class CaseExpressionTest {
20+
@Test
21+
public void testSimpleCase() throws JSQLParserException {
22+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN true THEN 1 ELSE 2 END", true);
23+
}
24+
25+
@Test
26+
public void testCaseBinaryAndWhen() throws JSQLParserException {
27+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN true & false THEN 1 ELSE 2 END", true);
28+
}
29+
30+
@Test
31+
public void testCaseBinaryOrWhen() throws JSQLParserException {
32+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN true | false THEN 1 ELSE 2 END", true);
33+
}
34+
35+
@Test
36+
public void testCaseExclamationWhen() throws JSQLParserException {
37+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN !true THEN 1 ELSE 2 END", true);
38+
}
39+
40+
@Test
41+
public void testCaseNotWhen() throws JSQLParserException {
42+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN NOT true THEN 1 ELSE 2 END", true);
43+
}
44+
45+
@Test
46+
public void testCaseAndWhen() throws JSQLParserException {
47+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN true AND false THEN 1 ELSE 2 END", true);
48+
}
49+
50+
@Test
51+
public void testCaseOrWhen() throws JSQLParserException {
52+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN true OR false THEN 1 ELSE 2 END", true);
53+
}
54+
55+
@Test
56+
public void testCaseExclamationSwitch() throws JSQLParserException {
57+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE !true WHEN true THEN 1 ELSE 2 END", true);
58+
}
59+
60+
@Test
61+
public void testCaseNotSwitch() throws JSQLParserException {
62+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE NOT true WHEN true THEN 1 ELSE 2 END", true);
63+
}
64+
65+
@Test
66+
public void testCaseBinaryAndSwitch() throws JSQLParserException {
67+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true & false WHEN true THEN 1 ELSE 2 END", true);
68+
}
69+
70+
@Test
71+
public void testCaseBinaryOrSwitch() throws JSQLParserException {
72+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true | false WHEN true THEN 1 ELSE 2 END", true);
73+
}
74+
75+
@Test
76+
public void testCaseAndSwitch() throws JSQLParserException {
77+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true AND false WHEN true THEN 1 ELSE 2 END", true);
78+
}
79+
80+
@Test
81+
public void testCaseOrSwitch() throws JSQLParserException {
82+
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true OR false WHEN true THEN 1 ELSE 2 END", true);
83+
}
84+
}

src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,16 @@ public void testParseStatementIssue1250() throws Exception {
253253
Statement result = CCJSqlParserUtil.parse("Select test.* from (Select * from sch.PERSON_TABLE // root test\n) as test");
254254
assertEquals("SELECT test.* FROM (SELECT * FROM sch.PERSON_TABLE) AS test", result.toString());
255255
}
256+
257+
@Test
258+
public void testCondExpressionIssue1482() throws JSQLParserException {
259+
Expression expr = CCJSqlParserUtil.parseCondExpression("test_table_enum.f1_enum IN ('TEST2'::test.test_enum)", false);
260+
assertEquals("test_table_enum.f1_enum IN ('TEST2'::test.test_enum)", expr.toString());
261+
}
262+
263+
@Test
264+
public void testCondExpressionIssue1482_2() throws JSQLParserException {
265+
Expression expr = CCJSqlParserUtil.parseCondExpression("test_table_enum.f1_enum IN ('TEST2'::test.\"test_enum\")", false);
266+
assertEquals("test_table_enum.f1_enum IN ('TEST2'::test.\"test_enum\")", expr.toString());
267+
}
256268
}

src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5032,4 +5032,14 @@ public void testWithIsolation() throws JSQLParserException {
50325032
assertEquals("Cs", isolation);
50335033
assertSqlCanBeParsedAndDeparsed(statement);
50345034
}
5035+
5036+
@Test
5037+
public void testKeywordDefaultIssue1470() throws JSQLParserException {
5038+
assertSqlCanBeParsedAndDeparsed("INSERT INTO mytable (col1, col2, col3) VALUES (?, 'sadfsd', default)");
5039+
}
5040+
5041+
@Test
5042+
public void testLoclTimezone1471() throws JSQLParserException {
5043+
assertSqlCanBeParsedAndDeparsed("SELECT TO_CHAR(CAST(SYSDATE AS TIMESTAMP WITH LOCAL TIME ZONE), 'HH:MI:SS AM TZD') FROM DUAL");
5044+
}
50355045
}

0 commit comments

Comments
 (0)