Menu

Getting the columns associated to each table

2008-12-15
2012-12-07
  • Nobody/Anonymous

    Hi everyone!..

    First of all I have to say that I've been using the JSqlParser for a while and i think that is a great development

    What I need to do, and the reason I'm asking for some help, is to obtain the columns associated to each of the tables in a given query including those for subqueries.

    For example columns C1, C2 and C3 belongs to the table T1; meanwhile C2 and C4 belongs to the table T2 in a given query statement.

    I have to say that the query can be very complex including joins, subqueries, alias names, etc.

    Any ideas on how can i solve this?

    Greetings

     
    • Leonardo Francalanci

      If your query ALWAYS uses table names in columns list, like:

      select a.COLA, b.COLB from a, b

      then it could be done; but usually you can have:

      select COLA, COLB from a, b

      Which says nothing about which columns belong to which tables...

       
    • Nobody/Anonymous

      That's exactly my problem!

      I'm parsing the queries generated by other developers and of course, they are not standard.

      Anyway, I'm following the basic logic of JSqlParser and using a HashMap structure to keep track of the table and its columns. This works for almost all the cases.

      I think that for this special case, it can be solved by looking at the tables structure directly in the database and assign the corresponding columns. (Only if the database access is available, of course).

      Greetings

       

Log in to post a comment.