Menu

#42 BaseSelectQuery#getFromTables() and INNER JOINs

Unnassigned
open
nobody
None
9
2019-04-19
2019-04-18
No

After learning of BaseSelectQuery#getFromTables() in this comment I did some experimenting and discovered an anomaly.

Repro code:

for (Query qry : db.getQueries()) {
    System.out.printf("Query [%s]%n", qry.getName());
    System.out.println("  Tables used:");
    try {
        for (String tableName : ((BaseSelectQuery) qry).getFromTables()) {
            System.out.printf("    %s%n", tableName);
        }
    } catch (ClassCastException cce) {
        System.out.println("    (BaseSelectQuery#getFromTables is not available for this query.)");
    }
}

If a query named [InvoiceLineItems] uses an "old fashioned" WHERE-based join

SELECT Invoice.InvoiceNumber, Invoice.InvoiceDate, InvoiceDetail.LineItemNumber, InvoiceDetail.Description
FROM Invoice, InvoiceDetail
WHERE (((Invoice.InvoiceNumber)=[InvoiceDetail].[InvoiceNumber]));

then the repro code produces the following, as expected:

Query [InvoiceLineItems]
  Tables used:
    Invoice
    InvoiceDetail

However, if the saved query uses an explicit INNER JOIN

SELECT Invoice.InvoiceNumber, Invoice.InvoiceDate, InvoiceDetail.LineItemNumber, InvoiceDetail.Description
FROM Invoice INNER JOIN InvoiceDetail ON Invoice.InvoiceNumber = InvoiceDetail.InvoiceNumber;

then the repro code produces

Query [InvoiceLineItems]
  Tables used:
    Invoice INNER JOIN InvoiceDetail ON Invoice.InvoiceNumber = InvoiceDetail.InvoiceNumber

It would be nice if .getFromTables() could return just the table names in such cases.

Discussion

  • James Ahlborn

    James Ahlborn - 2019-04-18

    right, so you've stumbled upon somewhat of a disconnect as to what jackcess provides and what would be "useful" in other scenarios. jackcess is ultimately just providing a pretty "accessor" for the query data stored in the access db. as you may have noticed in your testing, things like union queries are stored almost entirely as a single string. in other words, jackcess does pretty much zero string "parsing". (i think there may be a small amount of work done to properly quote certain values). i.e. jackcess doesn't really have any understanding of access sql syntax (outside of quoting identifiers). in order to fulfill this feature request, jackcess would need to incorporate a sql parser.

     
  • Gord Thompson

    Gord Thompson - 2019-04-18

    Understood. Just posted this as a "wish list" item. I've also been investigating passing the results of Query#toSQLString() to JSqlParser with some success, although (as I mentioned in another thread) there could be some Access SQL "quirks" that a generic SQL parser may trip over.

     

    Last edit: Gord Thompson 2019-04-18
  • James Ahlborn

    James Ahlborn - 2019-04-19
    • Priority: 1 --> 9
     

Log in to post a comment.

MongoDB Logo MongoDB