in src/main/protocol-impl/java/com/mysql/cj/protocol/a/SqlTimeValueEncoder.java [48:99]
public String getString(BindValue binding) {
if (binding.isNull()) {
return "null";
}
Time x = adjustTime((Time) binding.getValue());
switch (binding.getMysqlType()) {
case DATE:
Date d = new java.sql.Date(x.getTime());
return binding.getCalendar() != null ? TimeUtil.getSimpleDateFormat("''yyyy-MM-dd''", binding.getCalendar()).format(d)
: TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd''", this.serverSession.getDefaultTimeZone()).format(d);
case TIME:
case CHAR:
case VARCHAR:
case TINYTEXT:
case TEXT:
case MEDIUMTEXT:
case LONGTEXT:
String formatStr = this.serverSession.getCapabilities().serverSupportsFracSecs() && this.sendFractionalSeconds.getValue()
&& this.sendFractionalSecondsForTime.getValue() && TimeUtil.hasFractionalSeconds(x) ? "''HH:mm:ss.SSS''" : "''HH:mm:ss''";
return binding.getCalendar() != null ? TimeUtil.getSimpleDateFormat(formatStr, binding.getCalendar()).format(x)
: TimeUtil.getSimpleDateFormat(this.tdf, formatStr, this.serverSession.getDefaultTimeZone()).format(x);
case DATETIME:
case TIMESTAMP:
java.sql.Timestamp ts = new java.sql.Timestamp(x.getTime());
if (!this.sendFractionalSecondsForTime.getValue()) {
ts = TimeUtil.truncateFractionalSeconds(ts);
}
StringBuilder sb = new StringBuilder();
sb.append(binding.getCalendar() != null ? TimeUtil.getSimpleDateFormat("''yyyy-MM-dd HH:mm:ss", binding.getCalendar()).format(x)
: TimeUtil.getSimpleDateFormat(null, "''yyyy-MM-dd HH:mm:ss", this.serverSession.getDefaultTimeZone()).format(x));
if (this.serverSession.getCapabilities().serverSupportsFracSecs() && ts.getNanos() > 0) {
sb.append('.');
sb.append(TimeUtil.formatNanos(ts.getNanos(), 6));
}
sb.append('\'');
return sb.toString();
case YEAR:
Calendar cal = Calendar.getInstance();
cal.setTime((java.util.Date) binding.getValue());
return String.valueOf(cal.get(Calendar.YEAR));
default:
throw ExceptionFactory.createException(WrongArgumentException.class,
Messages.getString("PreparedStatement.67", new Object[] { binding.getValue().getClass().getName(), binding.getMysqlType().toString() }),
this.exceptionInterceptor);
}
}