in src/main/protocol-impl/java/com/mysql/cj/protocol/a/SqlTimeValueEncoder.java [102:165]
public void encodeAsBinary(Message msg, BindValue binding) {
NativePacketPayload intoPacket = (NativePacketPayload) msg;
Calendar calendar = binding.getCalendar();
switch (binding.getMysqlType()) {
case DATE:
if (calendar == null) {
calendar = Calendar.getInstance(this.serverSession.getDefaultTimeZone(), Locale.US);
}
calendar.setTime((java.util.Date) binding.getValue());
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
writeDate(msg, InternalDate.from(calendar));
return;
case DATETIME:
case TIMESTAMP:
java.sql.Timestamp ts = new java.sql.Timestamp(((java.sql.Time) binding.getValue()).getTime());
if (!this.serverSession.getCapabilities().serverSupportsFracSecs() || !this.sendFractionalSeconds.getValue()
|| !this.sendFractionalSecondsForTime.getValue()) {
ts = TimeUtil.truncateFractionalSeconds(ts);
}
if (calendar == null) {
calendar = Calendar.getInstance(this.serverSession.getDefaultTimeZone(), Locale.US);
}
calendar.setTime(ts);
writeDateTime(msg, InternalTimestamp.from(calendar, ts.getNanos()));
return;
case YEAR:
Calendar cal = Calendar.getInstance();
cal.setTime((java.util.Date) binding.getValue());
intoPacket.writeInteger(IntegerDataType.INT4, cal.get(Calendar.YEAR));
return;
case TIME:
Time x = adjustTime((Time) binding.getValue());
if (calendar == null) {
calendar = Calendar.getInstance(this.serverSession.getDefaultTimeZone(), Locale.US);
}
calendar.setTime(x);
writeTime(msg, InternalTime.from(calendar, (int) TimeUnit.MILLISECONDS.toNanos(calendar.get(Calendar.MILLISECOND))));
return;
case CHAR:
case VARCHAR:
case TINYTEXT:
case TEXT:
case MEDIUMTEXT:
case LONGTEXT:
x = adjustTime((Time) binding.getValue());
String formatStr = this.serverSession.getCapabilities().serverSupportsFracSecs() && this.sendFractionalSeconds.getValue()
&& this.sendFractionalSecondsForTime.getValue() && TimeUtil.hasFractionalSeconds(x) ? "HH:mm:ss.SSS" : "HH:mm:ss";
intoPacket.writeBytes(StringSelfDataType.STRING_LENENC,
StringUtils.getBytes(
binding.getCalendar() != null ? TimeUtil.getSimpleDateFormat(formatStr, binding.getCalendar()).format(x)
: TimeUtil.getSimpleDateFormat(this.tdf, formatStr, this.serverSession.getDefaultTimeZone()).format(x),
this.charEncoding.getValue()));
return;
default:
throw ExceptionFactory.createException(WrongArgumentException.class,
Messages.getString("PreparedStatement.67", new Object[] { binding.getValue().getClass().getName(), binding.getMysqlType().toString() }),
this.exceptionInterceptor);
}
}