Skip to content

Commit

Permalink
fixes #377
Browse files Browse the repository at this point in the history
  • Loading branch information
wumpz committed Aug 13, 2019
1 parent 27139a0 commit 9b6c46c
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ public void setup() {
@Test
public void testMultiPartTableNameWithServerNameAndDatabaseNameAndSchemaName() throws Exception {
final String statement = "SELECT columnName FROM [server-name\\server-instance].databaseName.schemaName.tableName";
assertSqlCanBeParsedAndDeparsed(statement, false,
assertSqlCanBeParsedAndDeparsed(statement, false,
parser -> parser.withSquareBracketQuotation(true));
}

@Test
public void testMultiPartTableNameWithServerNameAndDatabaseName() throws Exception {
final String statement = "SELECT columnName FROM [server-name\\server-instance].databaseName..tableName";

assertSqlCanBeParsedAndDeparsed(statement, false,
assertSqlCanBeParsedAndDeparsed(statement, false,
parser -> parser.withSquareBracketQuotation(true));
}

@Test
public void testMultiPartTableNameWithServerNameAndSchemaName() throws Exception {
final String statement = "SELECT columnName FROM [server-name\\server-instance]..schemaName.tableName";
assertSqlCanBeParsedAndDeparsed(statement, false,
assertSqlCanBeParsedAndDeparsed(statement, false,
parser -> parser.withSquareBracketQuotation(true));
}

Expand All @@ -76,7 +76,7 @@ public void testMultiPartTableNameWithServerProblem() throws Exception {
@Test
public void testMultiPartTableNameWithServerName() throws Exception {
final String statement = "SELECT columnName FROM [server-name\\server-instance]...tableName";
assertSqlCanBeParsedAndDeparsed(statement, false,
assertSqlCanBeParsedAndDeparsed(statement, false,
parser -> parser.withSquareBracketQuotation(true));
}

Expand Down Expand Up @@ -1676,14 +1676,14 @@ public void testCaseElseAddition() throws JSQLParserException {
@Test
public void testBrackets() throws JSQLParserException {
String stmt = "SELECT table_a.name AS [Test] FROM table_a";
assertSqlCanBeParsedAndDeparsed(stmt, false,
assertSqlCanBeParsedAndDeparsed(stmt, false,
parser -> parser.withSquareBracketQuotation(true));
}

@Test
public void testBrackets2() throws JSQLParserException {
String stmt = "SELECT [a] FROM t";
assertSqlCanBeParsedAndDeparsed(stmt, false,
assertSqlCanBeParsedAndDeparsed(stmt, false,
parser -> parser.withSquareBracketQuotation(true));
}

Expand Down Expand Up @@ -3085,16 +3085,17 @@ public void testKeyWorkReplaceIssue393() throws JSQLParserException {
}

/**
* Validates that a SELECT with FOR UPDATE WAIT <TIMEOUT> can be parsed and deparsed
* Validates that a SELECT with FOR UPDATE WAIT <TIMEOUT> can be parsed and
* deparsed
*/
@Test
public void testForUpdateWaitParseDeparse() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable FOR UPDATE WAIT 60");
}

/**
* Validates that a SELECT with FOR UPDATE WAIT <TIMEOUT> correctly sets a {@link Wait} with the
* correct timeout value.
* Validates that a SELECT with FOR UPDATE WAIT <TIMEOUT> correctly sets a
* {@link Wait} with the correct timeout value.
*/
@Test
public void testForUpdateWaitWithTimeout() throws JSQLParserException {
Expand Down Expand Up @@ -3480,7 +3481,7 @@ public void testFuncConditionParameter2() throws JSQLParserException {
public void testFuncConditionParameter3() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT CAST((MAX(CAST(IIF(isnumeric(license_no) = 1, license_no, 0) AS INT)) + 2) AS varchar) FROM lcps.t_license WHERE profession_id = 60 and license_type = 100 and YEAR(issue_date) % 2 = case when YEAR(issue_date) % 2 = 0 then 0 else 1 end and ISNUMERIC(license_no) = 1", true);
}

@Test
public void testSqlContainIsNullFunctionShouldBeParsed3() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT name, age FROM person WHERE NOT ISNULL(home, 'earn more money')");
Expand Down Expand Up @@ -3743,24 +3744,29 @@ public void testEmptyDoubleQuotes() throws JSQLParserException {
public void testEmptyDoubleQuotes_2() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE col = \" \"");
}

@Test
public void testInnerWithBlock() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("select 1 from (with mytable1 as (select 2 ) select 3 from mytable1 ) first", true);
}

@Test
public void testArrayIssue648() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("select * from a join b on a.id = b.id[1]", true);
}

@Test
public void testArrayIssue638() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT PAYLOAD[0] FROM MYTABLE");
}

@Test
public void testArrayIssue489() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT name[1] FROM MYTABLE");
}

@Test
public void testArrayIssue377() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("select 'yelp'::name as pktable_cat, n2.nspname as pktable_schem, c2.relname as pktable_name, a2.attname as pkcolumn_name, 'yelp'::name as fktable_cat, n1.nspname as fktable_schem, c1.relname as fktable_name, a1.attname as fkcolumn_name, i::int2 as key_seq, case ref.confupdtype when 'c' then 0::int2 when 'n' then 2::int2 when 'd' then 4::int2 when 'r' then 1::int2 else 3::int2 end as update_rule, case ref.confdeltype when 'c' then 0::int2 when 'n' then 2::int2 when 'd' then 4::int2 when 'r' then 1::int2 else 3::int2 end as delete_rule, ref.conname as fk_name, cn.conname as pk_name, case when ref.condeferrable then case when ref.condeferred then 5::int2 else 6::int2 end else 7::int2 end as deferrablity from ((((((( (select cn.oid, conrelid, conkey, confrelid, confkey, generate_series(array_lower(conkey, 1), array_upper(conkey, 1)) as i, confupdtype, confdeltype, conname, condeferrable, condeferred from pg_catalog.pg_constraint cn, pg_catalog.pg_class c, pg_catalog.pg_namespace n where contype = 'f' and conrelid = c.oid and relname = 'business' and n.oid = c.relnamespace and n.nspname = 'public' ) ref inner join pg_catalog.pg_class c1 on c1.oid = ref.conrelid) inner join pg_catalog.pg_namespace n1 on n1.oid = c1.relnamespace) inner join pg_catalog.pg_attribute a1 on a1.attrelid = c1.oid and a1.attnum = conkey[i]) inner join pg_catalog.pg_class c2 on c2.oid = ref.confrelid) inner join pg_catalog.pg_namespace n2 on n2.oid = c2.relnamespace) inner join pg_catalog.pg_attribute a2 on a2.attrelid = c2.oid and a2.attnum = confkey[i]) left outer join pg_catalog.pg_constraint cn on cn.conrelid = ref.confrelid and cn.contype = 'p') order by ref.oid, ref.i", true);
}
}

0 comments on commit 9b6c46c

Please sign in to comment.