@@ -415,7 +415,7 @@ public void testGetTableListForMergeUsingQuery() throws Exception {
415415 assertEquals ("employees" , (String ) tableList .get (0 ));
416416 assertEquals ("hr_records" , (String ) tableList .get (1 ));
417417 }
418-
418+
419419 @ Test
420420 public void testUpsertValues () throws Exception {
421421 String sql = "UPSERT INTO MY_TABLE1 (a) VALUES (5)" ;
@@ -427,7 +427,7 @@ public void testUpsertValues() throws Exception {
427427 assertEquals (1 , tableList .size ());
428428 assertTrue (tableList .contains ("MY_TABLE1" ));
429429 }
430-
430+
431431 @ Test
432432 public void testUpsertSelect () throws Exception {
433433 String sql = "UPSERT INTO mytable (mycolumn) SELECT mycolumn FROM mytable2" ;
@@ -440,5 +440,34 @@ public void testUpsertSelect() throws Exception {
440440 assertTrue (tableList .contains ("mytable" ));
441441 assertTrue (tableList .contains ("mytable2" ));
442442 }
443-
443+
444+ @ Test
445+ public void testCaseWhenSubSelect () throws JSQLParserException {
446+ String sql = "select case (select count(*) from mytable2) when 1 then 0 else -1 end" ;
447+ Statement stmt = CCJSqlParserUtil .parse (sql );
448+ TablesNamesFinder tablesNamesFinder = new TablesNamesFinder ();
449+ List <String > tableList = tablesNamesFinder .getTableList (stmt );
450+ assertEquals (1 , tableList .size ());
451+ assertTrue (tableList .contains ("mytable2" ));
452+ }
453+
454+ @ Test
455+ public void testCaseWhenSubSelect2 () throws JSQLParserException {
456+ String sql = "select case when (select count(*) from mytable2) = 1 then 0 else -1 end" ;
457+ Statement stmt = CCJSqlParserUtil .parse (sql );
458+ TablesNamesFinder tablesNamesFinder = new TablesNamesFinder ();
459+ List <String > tableList = tablesNamesFinder .getTableList (stmt );
460+ assertEquals (1 , tableList .size ());
461+ assertTrue (tableList .contains ("mytable2" ));
462+ }
463+
464+ @ Test
465+ public void testCaseWhenSubSelect3 () throws JSQLParserException {
466+ String sql = "select case when 1 = 2 then 0 else (select count(*) from mytable2) end" ;
467+ Statement stmt = CCJSqlParserUtil .parse (sql );
468+ TablesNamesFinder tablesNamesFinder = new TablesNamesFinder ();
469+ List <String > tableList = tablesNamesFinder .getTableList (stmt );
470+ assertEquals (1 , tableList .size ());
471+ assertTrue (tableList .contains ("mytable2" ));
472+ }
444473}
0 commit comments