Skip to content

Commit

Permalink
Assorted fixes (#1646)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
manticore-projects authored Oct 16, 2022
1 parent 34502d0 commit 15ff843
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

group = 'com.github.jsqlparser'
version = '4.5-SNAPSHOT'
version = '4.6-SNAPSHOT'
description = 'JSQLParser library'
java.sourceCompatibility = JavaVersion.VERSION_1_8

Expand Down Expand Up @@ -43,6 +43,7 @@ dependencies {

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

// enforce latest version of JavaCC
javacc 'net.java.dev.javacc:javacc:7.0.12'
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/net/sf/jsqlparser/schema/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,25 @@ public void setSchemaName(String schemaName) {
}

public String getName() {
return getIndex(NAME_IDX);
String name = getIndex(NAME_IDX);
if (name!=null && name.contains("@")) {
int pos = name.lastIndexOf('@');
if (pos>0) {
name = name.substring(0, pos );
}
}
return name;
}

public String getDBLinkName() {
String name = getIndex(NAME_IDX);
if (name!=null && name.contains("@")) {
int pos = name.lastIndexOf('@');
if (pos>0 && name.length()>1) {
name = name.substring(pos+1);
}
}
return name;
}

public Table withName(String name) {
Expand Down Expand Up @@ -241,4 +259,8 @@ public Table withSqlServerHints(SQLServerHints sqlServerHints) {
this.setSqlServerHints(sqlServerHints);
return this;
}

public List<String> getNameParts() {
return partItems;
}
}
3 changes: 2 additions & 1 deletion src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -3735,7 +3735,8 @@ Expression ComparisonItem() :
LOOKAHEAD(3) retval=AnyComparisonExpression()
| LOOKAHEAD(ValueListExpression()) retval=ValueListExpression()
| LOOKAHEAD(3) retval=SimpleExpression()
| retval=RowConstructor()
| LOOKAHEAD(3) retval=RowConstructor()
| retval=PrimaryExpression()
)

{
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -5243,4 +5244,25 @@ public void testNamedWindowDefinitionIssue1581_2() throws JSQLParserException {
public void testTimestamptzDateTimeLiteral() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT * FROM table WHERE x >= TIMESTAMPTZ '2021-07-05 00:00:00+00'");
}


@Test
public void testFunctionComplexExpressionParametersIssue1644() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT test(1=1, 'a', 'b')", true);
assertSqlCanBeParsedAndDeparsed("SELECT if(instr('avc','a')=0, 'avc', 'aaa')", true);
}

@Test
public void testOracleDBLink() throws JSQLParserException {
String sqlStr = "SELECT * from tablename@dblink";
assertSqlCanBeParsedAndDeparsed(sqlStr, true);

Select select = (Select) CCJSqlParserUtil.parse(sqlStr);
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
Table table = (Table) plainSelect.getFromItem();

assertNotEquals("tablename@dblink", table.getName());
assertEquals("tablename", table.getName());
assertEquals("dblink", table.getDBLinkName());
}
}

0 comments on commit 15ff843

Please sign in to comment.