[FEATURE] Utility to find table names corresponding with SelectItems #1874
Replies: 6 comments 1 reply
-
Greetings. Its not possible with JSQLParser alone since the SQL itself does not provide enough information. You will always need a combination of the AST and MetaData. MetaData of Oracle and MS SQL Server ARE sufficient (I do use that myself a lot). So from the |
Beta Was this translation helpful? Give feedback.
-
That is not correct. You will get precise Column definitions for each table, as well as indices or primary keys or references. |
Beta Was this translation helpful? Give feedback.
-
Let me clarify. Sql Server and Oracle drivers fail to handle: ResultSetMetaData#getTableName(int colIndex) This is a known limitation with those drivers. |
Beta Was this translation helpful? Give feedback.
-
Yes, I mentioned that this request is more on the semantic side of the equation. I think it can be done with just table metadata and only column names corresponding with tables. This is primarily because column names must either be qualified or be non-ambiguous wrt target tables. |
Beta Was this translation helpful? Give feedback.
-
But you can get all Tables with Columns for a given schema. |
Beta Was this translation helpful? Give feedback.
-
Not in our scope because it relies on JDBC drivers and connection information and RDBMS specific stuff (like types). |
Beta Was this translation helpful? Give feedback.
-
For instance, I want something like this:
I want a
findTable(SelectItem<?> selectItem, Function<String, Set<String>> tableMatcher)
method wheretableMatcher
provides the parser with a lookup for tables having a specified column name. For my case I can supply this via JDBC. Note,selectItem
must be a column defined in a table or the all-columns expression, otherwise the method returns null.I know this type of utility is more on the semantics side of the equation, but I feel like this parser could begin to provide these kinds of services. Even better, build a resolver/backend based on JDBC where not only table names, but also data types etc. could be attached to the AST. Just a thought, considering most of the time a specific DBMS is in context when using this parser.
Btw, I need this utility as a backup for JDBC drivers that don't support ResultSetMetaData#getTableName(int columnIndex) properly; Server and Oracle don't provide table names corresponding with columns.
I'll probably begin writing this utility myself, but would appreciate feedback if you have any. Would be awesome to hear something similar is available!
Beta Was this translation helpful? Give feedback.
All reactions