Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2585

Can not insert nulls into the table using Sql.execute

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.4
    • 1.5.5, 1.6-beta-1
    • SQL processing
    • None
    • Windows XP

    Description

      Running this script:

      import groovy.sql.Sql
      
      Sql sql = Sql.newInstance("jdbc:oracle:oci:@???, "???", "???", "oracle.jdbc.driver.OracleDriver")
      
      sql.execute "CREATE TABLE TEST (A INT, B INT)"
      
      sql.execute " insert into test (A,B) values (?,?)",         [10, 20]     // works OK
      sql.execute " insert into test (A,B) values (?,?)",         [10, null]  // fails
      

      Results in:

      Caught: java.sql.SQLException: ORA-01008: not all variables bound
      	at test.run(test.groovy:11)
      	at test.main(test.groovy)
      

      AFAIK, th problem lies with the following code (groovy.sql.Sql.java: 1390)

                  if (value != null) {
                      setObject(statement, i++, value);
      

      I think it should be

                  if (value != null) {
                      setObject(statement, i++, value);
                else
                       statement.setNull(i, in.getType());
      

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              pganelin Pavel Ganelin
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: