diff --git a/src/site/sphinx/usage.rst b/src/site/sphinx/usage.rst index 47623b174..10cd7349e 100644 --- a/src/site/sphinx/usage.rst +++ b/src/site/sphinx/usage.rst @@ -12,7 +12,7 @@ How to use it 4) Oracle Alternative Quoting is partially supported for common brackets such as ``q'{...}'``, ``q'[...]'``, ``q'(...)'`` and ``q''...''``. - 5) Supported Statement Separators are Semicolon ``\;``, ``GO``, Slash ``\/`` or 2 empty lines. + 5) Supported Statement Separators are Semicolon ``;``, ``GO``, Slash ``/`` or two empty lines ``\n\n\n``. Compile from Source Code @@ -186,6 +186,23 @@ Traverse the Java Object Tree using the Visitor Patterns: // Invoke the Statement Visitor stmt.accept(statementVisitor); +Find Table Names +============================== + +The class ``net.sf.jsqlparser.util.TablesNamesFinder`` can be used to return all Table Names from a Query or an Expression. + +.. code-block:: java + + // find in Statements + String sqlStr = "select * from A left join B on A.id=B.id and A.age = (select age from C)"; + Set tableNames = TablesNamesFinder.findTables(sqlStr); + assertThat( tableNames ).containsExactlyInAnyOrder("A", "B", "C"); + + // find in Expressions + String exprStr = "A.id=B.id and A.age = (select age from C)"; + tableNames = TablesNamesFinder.findTables(sqlStr); + assertThat( tableNames ).containsExactlyInAnyOrder("A", "B", "C"); + Build a SQL Statement ============================== diff --git a/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java b/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java index 46f31a80f..d90b9806c 100644 --- a/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java +++ b/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java @@ -489,6 +489,11 @@ public void testConnectedByRootOperator() throws JSQLParserException { @Test void testJoinSubSelect() throws JSQLParserException { String sqlStr = "select * from A left join B on A.id=B.id and A.age = (select age from C)"; - assertThat(TablesNamesFinder.findTables(sqlStr)).containsExactlyInAnyOrder("A", "B", "C"); + Set tableNames = TablesNamesFinder.findTables(sqlStr); + assertThat( tableNames ).containsExactlyInAnyOrder("A", "B", "C"); + + String exprStr = "A.id=B.id and A.age = (select age from C)"; + tableNames = TablesNamesFinder.findTables(sqlStr); + assertThat( tableNames ).containsExactlyInAnyOrder("A", "B", "C"); } }