4 Replies Latest reply on Sep 13, 2013 7:58 AM by pinkstondevin

    SQLStringVisitor for Inserts

    pinkstondevin

      Is it possible to use the SQLStringVisitor to handle inserts?  If inserts are like:

      "INSERT INTO table (col1, col2, col3) VALUES (val1, val2, val3)"

      , could i use the SQLStringVisitor to parse the query and get the values and columns?  The reason I ask, I can see methods for getTable, getColumns and getTableName, but does the getValueSource get the values? 

       

      Or would I be best using another language visitor like heirarchyvisitor?  I would like to be able to handle basic inserts/deletes, and the SQLStringVisitor is easy to work with on SELECT statements.

       

      Thanks!

        • 1. Re: SQLStringVisitor for Inserts
          markaddleman

          If you're trying to parse SQL, try using org.teiid.query.parser.QueryParser instead.  It returns an AST in a different object hierarchy than the AST used in translators but there are similar visitors for traversing and manipulating the parse tree.  Look at the org.teiid.query.sql package.  There's lots of good stuff in there and we use it often to programatically manipulate SQL.

           

          The class names between the two hierarchies are often the same so it can be a little confusing.

          • 2. Re: SQLStringVisitor for Inserts
            rareddy

            Only note to above comment is that you can use "org.teiid.query.sql", however it is not public api from Teiid. So, use it knowing that it may change.

            • 3. Re: SQLStringVisitor for Inserts
              shawkins

              Devin,

               

              Can you describe your scenario more fully?  Where are you handling the insert?  Is this at the translator layer such that your starting with the language object form, or somewhere else?

               

              Steve

              • 4. Re: SQLStringVisitor for Inserts
                pinkstondevin

                Steve - I am handling the insert at the translator layer, very similar to how the other translators of Teiid are setup (MongoDB, Google etc.).  I used the SQLStringVisitor to handle Select Statements, and it works well and was very easy to implement.  Looking at the Update Visitors in MongoDB and others, it looks a little more complex and was just trying to find the best route to choose for developing an update visitor.  Thank you for your quick response!

                 

                Mark/Ramesh - I am reading the org.teiid.query.parser/sql now, I didn't know that it existed it is very interesting.  I will read more and maybe choose to use that!

                 

                Thanks guys for all your input!