diff options
author | James Moger <james.moger@gitblit.com> | 2015-04-16 19:11:57 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2015-04-16 19:11:57 -0400 |
commit | 5f71b4c044a382b89bd05577ef6fed86ed593c31 (patch) | |
tree | d335edd5be2dc0e0ad12db103cb2b86394bf6a28 /src/main/java/com/iciql | |
parent | e4952b2465ae4167e24d416b4fc4f6996e2fe229 (diff) | |
download | iciql-5f71b4c044a382b89bd05577ef6fed86ed593c31.tar.gz iciql-5f71b4c044a382b89bd05577ef6fed86ed593c31.zip |
Allow SQLite the chance to deserialize DateTime objects
Diffstat (limited to 'src/main/java/com/iciql')
-rw-r--r-- | src/main/java/com/iciql/SQLDialectSQLite.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main/java/com/iciql/SQLDialectSQLite.java b/src/main/java/com/iciql/SQLDialectSQLite.java index 4234e9f..4777234 100644 --- a/src/main/java/com/iciql/SQLDialectSQLite.java +++ b/src/main/java/com/iciql/SQLDialectSQLite.java @@ -16,6 +16,13 @@ package com.iciql;
+import java.sql.Date;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+
+import com.iciql.Iciql.DataTypeAdapter;
import com.iciql.TableDefinition.FieldDefinition;
import com.iciql.TableDefinition.IndexDefinition;
import com.iciql.util.IciqlLogger;
@@ -135,4 +142,42 @@ public class SQLDialectSQLite extends SQLDialectDefault { stat.setSQL(buff.toString());
}
+ @Override
+ public Object deserialize(ResultSet rs, int columnIndex, Class<?> targetType, Class<? extends DataTypeAdapter<?>> typeAdapter) {
+ try {
+ return super.deserialize(rs, columnIndex, targetType, typeAdapter);
+ } catch (IciqlException e) {
+ if (typeAdapter == null && e.getMessage().startsWith("Can not convert")) {
+ try {
+ // give the SQLite JDBC driver an opportunity to deserialize DateTime objects
+ if (Timestamp.class.equals(targetType)) {
+ return rs.getTimestamp(columnIndex);
+ } else if (Time.class.equals(targetType)) {
+ return rs.getTime(columnIndex);
+ } else if (Date.class.equals(targetType)) {
+ return rs.getDate(columnIndex);
+ } else if (java.util.Date.class.equals(targetType)) {
+ Timestamp timestamp = rs.getTimestamp(columnIndex);
+ return new java.util.Date(timestamp.getTime());
+ }
+ } catch (SQLException x) {
+ throw new IciqlException(x, "Can not convert the value at column {0} to {1}",
+ columnIndex, targetType.getName());
+ }
+ }
+
+ // rethrow e
+ throw e;
+ }
+ }
+
+ @Override
+ public String prepareStringParameter(Object o) {
+ if (o instanceof Boolean) {
+ // SQLite does not have an explicit BOOLEAN type
+ Boolean bool = (Boolean) o;
+ return bool ? "1" : "0";
+ }
+ return super.prepareStringParameter(o);
+ }
}
\ No newline at end of file |