groovy

Can't insert null values into database

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0, 1.1-beta-3
  • Fix Version/s: 1.5.2
  • Component/s: SQL processing
  • Labels:
    None
  • Environment:
    CYGWIN_NT-5.1 <censored> 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
    Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode)
  • Testcase included:
    yes
  • Number of attachments :
    1

Description

groovy failed to insert a null ( a.k . Undefined ) value into database using GString.

See source of attached testcase

Testcase return:
testNullInsert(InsertNullIntoDBTest)java.sql.SQLException: Unexpected token: ) in statement [INSERT INTO COUNTRY (country,currency) VALUES (?,)]

Issue Links

Activity

Hide
Andreas Rudolf added a comment -

I checked this again against Version 1.5 of groovy.
Testcase still failed

Show
Andreas Rudolf added a comment - I checked this again against Version 1.5 of groovy. Testcase still failed
Hide
Paul King added a comment -

Improvements have been made which should fix this problem but the test suite is fairly minimal in this area - please test as much as you can.

Show
Paul King added a comment - Improvements have been made which should fix this problem but the test suite is fairly minimal in this area - please test as much as you can.
Hide
Phil Walker added a comment -

The test script InsertNullIntoDBTest.groovy does not fail running under GroovyGroovy 1.5.3 JVM : 1.6.0_03-b05 (Ubuntu Linux).

However, the following slight variation does fail:

db.execute "INSERT INTO COUNTRY (country,currency) VALUES (?,?)",[it.key,it.value]

with the following output:

US USD
DE EUR
GB null
Caught: org.postgresql.util.PSQLException: No value specified for parameter 2.
at InsertNullIntoDBTest$_run_closure1.doCall(InsertNullIntoDBTest.groovy:19)
at InsertNullIntoDBTest.run(InsertNullIntoDBTest.groovy:17)
at InsertNullIntoDBTest.main(InsertNullIntoDBTest.groovy)

Show
Phil Walker added a comment - The test script InsertNullIntoDBTest.groovy does not fail running under GroovyGroovy 1.5.3 JVM : 1.6.0_03-b05 (Ubuntu Linux). However, the following slight variation does fail: db.execute "INSERT INTO COUNTRY (country,currency) VALUES (?,?)",[it.key,it.value] with the following output: US USD DE EUR GB null Caught: org.postgresql.util.PSQLException: No value specified for parameter 2. at InsertNullIntoDBTest$_run_closure1.doCall(InsertNullIntoDBTest.groovy:19) at InsertNullIntoDBTest.run(InsertNullIntoDBTest.groovy:17) at InsertNullIntoDBTest.main(InsertNullIntoDBTest.groovy)
Hide
Paul King added a comment - - edited

You might need to provide more info. This script:

Map countryMap = ['US' : 'USD', 'DE' : 'EUR', 'GB' : null]

countryMap.each{
    println it.key + " " + it.value
    db.execute "INSERT INTO COUNTRY (country,currency) VALUES (?,?)", [it.key, it.value]
}

works for me on 1.5.4 using hsql.

Show
Paul King added a comment - - edited You might need to provide more info. This script:
Map countryMap = ['US' : 'USD', 'DE' : 'EUR', 'GB' : null]

countryMap.each{
    println it.key + " " + it.value
    db.execute "INSERT INTO COUNTRY (country,currency) VALUES (?,?)", [it.key, it.value]
}
works for me on 1.5.4 using hsql.
Hide
Paul King added a comment -

This seems related to GROOVY-2585 perhaps it was only working on HSQL and would fail on other databases. Leaving this issue closed but follow the other issue for further progress.

Show
Paul King added a comment - This seems related to GROOVY-2585 perhaps it was only working on HSQL and would fail on other databases. Leaving this issue closed but follow the other issue for further progress.
Hide
Paul King added a comment -

close off release 1.5.4

Show
Paul King added a comment - close off release 1.5.4

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: