From 339c887b1ea456335995930e289e4047d5e7ff43 Mon Sep 17 00:00:00 2001 From: bernd Date: Sat, 30 Jul 2011 20:00:05 +0200 Subject: [PATCH 06/12] Support providing null parameters to QueryTool.update() for cases when the query parameter is NULLable --- eodsql/src/net/lemnik/eodsql/QuickQueryUtil.java | 24 ++++++++++++++------- 1 files changed, 16 insertions(+), 8 deletions(-) diff --git a/eodsql/src/net/lemnik/eodsql/QuickQueryUtil.java b/eodsql/src/net/lemnik/eodsql/QuickQueryUtil.java index 1a7c57b..188f43b 100644 --- a/eodsql/src/net/lemnik/eodsql/QuickQueryUtil.java +++ b/eodsql/src/net/lemnik/eodsql/QuickQueryUtil.java @@ -129,7 +129,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; @@ -166,14 +170,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.6