Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.0-JSR-5
-
Fix Version/s: 1.5.2
-
Component/s: groovy-jdk, SQL processing
-
Labels:None
-
Environment:Mac OSX on Intel, Java 1.5.0_06
-
Number of attachments :
Description
getParameters(GString) is incorrectly stripping null values out.
This causes asSql(GString,params) to fail to replace null GString variables with empty strings.
example:
def x = null
def y = 1
sql.execute("""
insert into TABLE (X_COL, Y_COL)
values (${x},${y})
Produces sql of
insert into TABLE(X_COL, Y_COL) values (?,)
The trailing variable is completely missing due to getParameters stripping nulls.
All functions who call getParameters pass the returned list to asSql who checks for null to know if it should use "?" or "null" for that variable.
asSql was also missing an iter.remove() when processing a null value from the GString. If it isn't removed, setParameters() will choke as it will set one too many parameters (due to the ? not existing on the prepared statement)
I'm attaching a patch against head that fixes this.
Attachments
Issue Links
| This issue duplicates: | ||||
| GROOVY-2146 | Can't insert null values into database |
|
|
|
My first few lines in the description didn't exactly make sense.
asSql is expected to replace null object values in the GString with "null" (to avoid issues with databases not liking setObject(idx,null)), when it does this, it is supposed to remove the object from the param list so the prepared statement will have the correct number of args set to match the "?"