From fe4fceb7635ad4207214c5f5cee93e4c945f2c3a Mon Sep 17 00:00:00 2001 From: eegeek Date: Mon, 3 Dec 2012 16:33:30 +0000 Subject: [PATCH] 0000021: SQLite --- .../main/java/org/jumpmind/db/sql/SqlConstants.java | 4 ++-- .../db/platform/sqlite/SqliteJdbcSqlTemplate.java | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlConstants.java b/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlConstants.java index f3764eb705..7561103075 100644 --- a/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlConstants.java +++ b/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlConstants.java @@ -6,10 +6,10 @@ abstract public class SqlConstants { public static final String[] TIMESTAMP_PATTERNS = { "yyyy-MM-dd HH:mm:ss.S", - "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-dd" }; + "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm", "yyyy-MM-dd" }; public static final String[] TIME_PATTERNS = { "HH:mm:ss.S", "HH:mm:ss", - "yyyy-MM-dd HH:mm:ss.S", "yyyy-MM-dd HH:mm:ss" }; + "yyyy-MM-dd HH:mm:ss.S", "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss" }; public static final FastDateFormat JDBC_TIMESTAMP_FORMATTER = FastDateFormat .getInstance("yyyy-MM-dd hh:mm:ss.SSS"); diff --git a/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/sqlite/SqliteJdbcSqlTemplate.java b/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/sqlite/SqliteJdbcSqlTemplate.java index 6419295876..f02c874feb 100644 --- a/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/sqlite/SqliteJdbcSqlTemplate.java +++ b/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/sqlite/SqliteJdbcSqlTemplate.java @@ -24,7 +24,7 @@ public class SqliteJdbcSqlTemplate extends JdbcSqlTemplate { private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); private DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); - private DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); public SqliteJdbcSqlTemplate(DataSource dataSource, SqlTemplateSettings settings, SymmetricLobHandler lobHandler, DatabaseInfo databaseInfo) { @@ -78,18 +78,17 @@ public void setValues(PreparedStatement ps, Object[] args, int[] argTypes, for (int i = 1; i <= args.length; i++) { Object arg = args[i - 1]; int argType = argTypes != null && argTypes.length >= i ? argTypes[i - 1] : SqlTypeValue.TYPE_UNKNOWN; + + if (argType == Types.BLOB && lobHandler != null && arg instanceof byte[]) { lobHandler.getLobCreator().setBlobAsBytes(ps, i, (byte[]) arg); } else if (argType == Types.BLOB && lobHandler != null && arg instanceof String) { lobHandler.getLobCreator().setBlobAsBytes(ps, i, arg.toString().getBytes()); } else if (argType == Types.CLOB && lobHandler != null) { lobHandler.getLobCreator().setClobAsString(ps, i, (String) arg); - } else if (argType == Types.DATE && arg!=null ) { - StatementCreatorUtils.setParameterValue(ps, i, Types.VARCHAR, dateFormat.format(arg)); - } else if (argType == Types.TIME && arg!=null ) { - StatementCreatorUtils.setParameterValue(ps, i, Types.VARCHAR, timeFormat.format(arg)); - } else if (argType == Types.TIMESTAMP && arg!=null ) { - StatementCreatorUtils.setParameterValue(ps, i, Types.VARCHAR, dateTimeFormat.format(arg)); + } else if (arg!=null && (arg instanceof Date || arg instanceof Timestamp)) { + arg = args[i-1] = dateTimeFormat.format(arg); + StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg); } else { StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg); }