From 6bfe1f0666a0abd91a6c214d5573fff600dacf5b Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 14 Nov 2012 21:24:31 +0100 Subject: [PATCH 14/25] Support providing null parameters to QueryTool.update() for cases when the query parameter is NULLable. --- eodsql/src/net/lemnik/eodsql/QuickQueryUtil.java | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/eodsql/src/net/lemnik/eodsql/QuickQueryUtil.java b/eodsql/src/net/lemnik/eodsql/QuickQueryUtil.java index 0bdc77d..763a56d 100644 --- a/eodsql/src/net/lemnik/eodsql/QuickQueryUtil.java +++ b/eodsql/src/net/lemnik/eodsql/QuickQueryUtil.java @@ -130,7 +130,11 @@ class QuickQueryUtil { final Class[] parameterTypes = new Class[parameterCount]; for(int i = 0; i < parameterCount; i++) { - parameterTypes[i] = parameters[i].getClass(); + if (parameters[i] == null) { + parameterTypes[i] = null; + } else { + parameterTypes[i] = parameters[i].getClass(); + } } return parameterTypes; @@ -167,14 +171,18 @@ class QuickQueryUtil { for(int i = 0; i < parameterCount; i++) { final Class type = eodquery.getParameterType(i); - @SuppressWarnings("unchecked") - final TypeMapper mapper = mappers.get(type); - - if(mapper != null) { - mapper.set(statement, i + 1, eodquery.getParameter(context, i)); + if (type == null) { + statement.setNull(i + 1, statement.getParameterMetaData().getParameterType(i + 1)); } else { - throw new InvalidQueryException( - "No TypeMapper found for " + type); + @SuppressWarnings("unchecked") + final TypeMapper mapper = mappers.get(type); + + if(mapper != null) { + mapper.set(statement, i + 1, eodquery.getParameter(context, i)); + } else { + throw new InvalidQueryException( + "No TypeMapper found for " + type); + } } } } -- 1.8.0