Skip to content

Commit 15ff843

Browse files
Assorted fixes (#1646)
* fix: add missing public Getter Add public Getter for `updateSets` Fixes #1630 * fix: Assorted Fixes SelectExpressionItem with Function and Complex Parameters Tables with Oracle DB Links Make Table Name Parts accessible Fixes #1644 Fixes #1643 * fix: Revert correct test case
1 parent 34502d0 commit 15ff843

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

1414
group = 'com.github.jsqlparser'
15-
version = '4.5-SNAPSHOT'
15+
version = '4.6-SNAPSHOT'
1616
description = 'JSQLParser library'
1717
java.sourceCompatibility = JavaVersion.VERSION_1_8
1818

@@ -43,6 +43,7 @@ dependencies {
4343

4444
// https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter
4545
testImplementation 'org.mockito:mockito-junit-jupiter:4.+'
46+
testImplementation 'org.junit.jupiter:junit-jupiter-params:+'
4647

4748
// enforce latest version of JavaCC
4849
javacc 'net.java.dev.javacc:javacc:7.0.12'

src/main/java/net/sf/jsqlparser/schema/Table.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,25 @@ public void setSchemaName(String schemaName) {
103103
}
104104

105105
public String getName() {
106-
return getIndex(NAME_IDX);
106+
String name = getIndex(NAME_IDX);
107+
if (name!=null && name.contains("@")) {
108+
int pos = name.lastIndexOf('@');
109+
if (pos>0) {
110+
name = name.substring(0, pos );
111+
}
112+
}
113+
return name;
114+
}
115+
116+
public String getDBLinkName() {
117+
String name = getIndex(NAME_IDX);
118+
if (name!=null && name.contains("@")) {
119+
int pos = name.lastIndexOf('@');
120+
if (pos>0 && name.length()>1) {
121+
name = name.substring(pos+1);
122+
}
123+
}
124+
return name;
107125
}
108126

109127
public Table withName(String name) {
@@ -241,4 +259,8 @@ public Table withSqlServerHints(SQLServerHints sqlServerHints) {
241259
this.setSqlServerHints(sqlServerHints);
242260
return this;
243261
}
262+
263+
public List<String> getNameParts() {
264+
return partItems;
265+
}
244266
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3735,7 +3735,8 @@ Expression ComparisonItem() :
37353735
LOOKAHEAD(3) retval=AnyComparisonExpression()
37363736
| LOOKAHEAD(ValueListExpression()) retval=ValueListExpression()
37373737
| LOOKAHEAD(3) retval=SimpleExpression()
3738-
| retval=RowConstructor()
3738+
| LOOKAHEAD(3) retval=RowConstructor()
3739+
| retval=PrimaryExpression()
37393740
)
37403741

37413742
{

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import static org.assertj.core.api.Assertions.assertThat;
4747
import static org.junit.jupiter.api.Assertions.assertEquals;
4848
import static org.junit.jupiter.api.Assertions.assertFalse;
49+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4950
import static org.junit.jupiter.api.Assertions.assertNotNull;
5051
import static org.junit.jupiter.api.Assertions.assertNull;
5152
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -5243,4 +5244,25 @@ public void testNamedWindowDefinitionIssue1581_2() throws JSQLParserException {
52435244
public void testTimestamptzDateTimeLiteral() throws JSQLParserException {
52445245
assertSqlCanBeParsedAndDeparsed("SELECT * FROM table WHERE x >= TIMESTAMPTZ '2021-07-05 00:00:00+00'");
52455246
}
5247+
5248+
5249+
@Test
5250+
public void testFunctionComplexExpressionParametersIssue1644() throws JSQLParserException {
5251+
assertSqlCanBeParsedAndDeparsed("SELECT test(1=1, 'a', 'b')", true);
5252+
assertSqlCanBeParsedAndDeparsed("SELECT if(instr('avc','a')=0, 'avc', 'aaa')", true);
5253+
}
5254+
5255+
@Test
5256+
public void testOracleDBLink() throws JSQLParserException {
5257+
String sqlStr = "SELECT * from tablename@dblink";
5258+
assertSqlCanBeParsedAndDeparsed(sqlStr, true);
5259+
5260+
Select select = (Select) CCJSqlParserUtil.parse(sqlStr);
5261+
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
5262+
Table table = (Table) plainSelect.getFromItem();
5263+
5264+
assertNotEquals("tablename@dblink", table.getName());
5265+
assertEquals("tablename", table.getName());
5266+
assertEquals("dblink", table.getDBLinkName());
5267+
}
52465268
}

0 commit comments

Comments
 (0)