From f83193c7d623f92c7d7d4a0675ee76d58a588550 Mon Sep 17 00:00:00 2001 From: bernd Date: Thu, 4 Aug 2011 02:11:38 +0200 Subject: [PATCH 11/16] 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 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.6