Skip to content

Commit

Permalink
0000021: SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanes committed Dec 7, 2012
1 parent a429495 commit f73a929
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
Expand Up @@ -30,9 +30,9 @@ public SqliteDdlBuilder() {
databaseInfo.addNativeTypeMapping(Types.STRUCT, "BINARY", Types.BINARY);
databaseInfo.addNativeTypeMapping(Types.DATALINK, "BINARY", Types.BINARY);

databaseInfo.addNativeTypeMapping(Types.TIMESTAMP, "VARCHAR", Types.VARCHAR);
databaseInfo.addNativeTypeMapping(Types.TIME, "VARCHAR", Types.VARCHAR);
databaseInfo.addNativeTypeMapping(Types.DATE, "VARCHAR", Types.VARCHAR);
databaseInfo.addNativeTypeMapping(Types.TIMESTAMP, "TIMESTAMP",Types.TIMESTAMP);
databaseInfo.addNativeTypeMapping(Types.TIME, "TIME", Types.TIME);
databaseInfo.addNativeTypeMapping(Types.DATE, "DATE", Types.DATE);

databaseInfo.addNativeTypeMapping(Types.BIT, "INTEGER", Types.INTEGER);
databaseInfo.addNativeTypeMapping(Types.TINYINT, "INTEGER", Types.INTEGER);
Expand Down
Expand Up @@ -129,6 +129,14 @@ public String toJdbcType(String colType) {
colType = TypeMap.FLOAT;
} else if (colType.startsWith("DOUBLE")) {
colType = TypeMap.DOUBLE;
} else if (colType.startsWith("DECIMAL")) {
colType = TypeMap.DECIMAL;
} else if (colType.startsWith("DATE")) {
colType = TypeMap.DATE;
} else if (colType.startsWith("TIMESTAMP")) {
colType = TypeMap.TIMESTAMP;
} else if (colType.startsWith("TIME")) {
colType = TypeMap.TIME;
} else {
colType = TypeMap.VARCHAR;
}
Expand Down
@@ -1,16 +1,19 @@
package org.jumpmind.db.platform.sqlite;

import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.sql.DataSource;

import org.apache.commons.lang.time.DateUtils;
import org.jumpmind.db.platform.DatabaseInfo;
import org.jumpmind.db.sql.JdbcSqlTemplate;
import org.jumpmind.db.sql.SqlTemplateSettings;
Expand All @@ -22,7 +25,7 @@

public class SqliteJdbcSqlTemplate extends JdbcSqlTemplate {

private DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
private DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");

public SqliteJdbcSqlTemplate(DataSource dataSource, SqlTemplateSettings settings, SymmetricLobHandler lobHandler,
DatabaseInfo databaseInfo) {
Expand Down Expand Up @@ -75,11 +78,20 @@ public void setValues(PreparedStatement ps, Object[] args, int[] argTypes,
lobHandler.getLobCreator().setBlobAsBytes(ps, i, arg.toString().getBytes());
} else if (argType == Types.CLOB && lobHandler != null) {
lobHandler.getLobCreator().setClobAsString(ps, i, (String) arg);
} else if (arg!=null && argType == Types.DATE && arg instanceof Date) {
Date clone = (Date) (((Date) arg).clone());
arg = dateTimeFormat.format(DateUtils.truncate(clone,Calendar.DATE));
args[i-1] = arg;
StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg);
} else if (arg!=null && (arg instanceof Date || arg instanceof Timestamp)) {
arg = dateTimeFormat.format(arg);
args[i-1] = arg;
StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg);
} else {
if (arg instanceof BigDecimal) {
arg = ((BigDecimal) arg).doubleValue();
args[i-1] = arg;
}
StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg);
}
}
Expand Down
Expand Up @@ -39,7 +39,7 @@
public final class FormatUtils {

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" };
Expand Down

0 comments on commit f73a929

Please sign in to comment.