groovy
  1. groovy
  2. GROOVY-4540

Sql.execute() doesn't handle multiple SQL statements.

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Blocker Blocker
    • Resolution: Not A Bug
    • Affects Version/s: 1.7.5
    • Fix Version/s: None
    • Component/s: SQL processing
    • Labels:
      None
    • Environment:
      Windows, mysql
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      When you pass two consequtive statements to Sql.execute(), it throws an exception.

      See http://stackoverflow.com/questions/4286483/running-multiple-sql-statements-from-groovy

        Activity

        Hide
        Ron Gross added a comment -

        I submitted a fix to Stack Overflow, please check it out.

        Show
        Ron Gross added a comment - I submitted a fix to Stack Overflow, please check it out.
        Hide
        blackdrag blackdrag added a comment -

        thank you for looking into this, but would it be possible to attach a patch to this issue instead?

        Show
        blackdrag blackdrag added a comment - thank you for looking into this, but would it be possible to attach a patch to this issue instead?
        Hide
        Paul King added a comment -

        Groovy's Sql class generally only supports what the underlying JDBC api provides. Performing multiple statements is not generally supported but some drivers like the MySql one should support that as a configuration option. Try something like (adapt for your environment):

        def props = [user: 'myuser', password: 'mypassword', allowMultiQueries: 'true'] as Properties
        def url = 'jdbc:mysql://127.0.0.1:3306/mydatabase'
        def driver = 'com.mysql.jdbc.Driver'
        def sql = Sql.newInstance(url, props, driver)
        

        I am less keen on the fix on Stack Overflow for the general case. It would work in most cases but would need some additional work to support for instance semicolon values inside strings stored in the database.

        Show
        Paul King added a comment - Groovy's Sql class generally only supports what the underlying JDBC api provides. Performing multiple statements is not generally supported but some drivers like the MySql one should support that as a configuration option. Try something like (adapt for your environment): def props = [user: 'myuser', password: 'mypassword', allowMultiQueries: ' true '] as Properties def url = 'jdbc:mysql: //127.0.0.1:3306/mydatabase' def driver = 'com.mysql.jdbc.Driver' def sql = Sql.newInstance(url, props, driver) I am less keen on the fix on Stack Overflow for the general case. It would work in most cases but would need some additional work to support for instance semicolon values inside strings stored in the database.
        Hide
        Ron Gross added a comment -

        Thanks, I updated the information on Stack Overflow to reflect this.

        Show
        Ron Gross added a comment - Thanks, I updated the information on Stack Overflow to reflect this.
        Hide
        Paul King added a comment -

        Leaving as not supported unless the underlying JDBC driver supports the feature.

        Show
        Paul King added a comment - Leaving as not supported unless the underlying JDBC driver supports the feature.

          People

          • Assignee:
            Unassigned
            Reporter:
            Ron Gross
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: