Skip to content

Commit

Permalink
0000021: SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanes committed Dec 3, 2012
1 parent 57e0e8d commit fe4fceb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Expand Up @@ -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");
Expand Down
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit fe4fceb

Please sign in to comment.