From 0df7d2c41fc62a4b96bff97bb4c76ebdf7c98077 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 25 Jul 2012 23:43:39 +0200 Subject: [PATCH 14/22] 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.7.9.5