use of com.mysql.cj.exceptions.DataReadException in project aws-mysql-jdbc by awslabs.
the class XProtocolDecoder method decodeDatetime.
@Override
public <T> T decodeDatetime(byte[] bytes, int offset, int length, int scale, ValueFactory<T> vf) {
try {
CodedInputStream inputStream = CodedInputStream.newInstance(bytes, offset, length);
int year = (int) inputStream.readUInt64();
int month = (int) inputStream.readUInt64();
int day = (int) inputStream.readUInt64();
// do we have a time too?
if (inputStream.getBytesUntilLimit() > 0) {
int hours = 0;
int minutes = 0;
int seconds = 0;
int nanos = 0;
if (!inputStream.isAtEnd()) {
hours = (int) inputStream.readInt64();
if (!inputStream.isAtEnd()) {
minutes = (int) inputStream.readInt64();
if (!inputStream.isAtEnd()) {
seconds = (int) inputStream.readInt64();
if (!inputStream.isAtEnd()) {
nanos = 1000 * (int) inputStream.readInt64();
}
}
}
}
return vf.createFromDatetime(new InternalTimestamp(year, month, day, hours, minutes, seconds, nanos, scale));
}
return vf.createFromDate(new InternalDate(year, month, day));
} catch (IOException e) {
throw new DataReadException(e);
}
}
use of com.mysql.cj.exceptions.DataReadException in project aws-mysql-jdbc by awslabs.
the class XProtocolDecoder method decodeTime.
@Override
public <T> T decodeTime(byte[] bytes, int offset, int length, int scale, ValueFactory<T> vf) {
try {
CodedInputStream inputStream = CodedInputStream.newInstance(bytes, offset, length);
boolean negative = inputStream.readRawByte() > 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
int nanos = 0;
if (!inputStream.isAtEnd()) {
hours = (int) inputStream.readInt64();
if (!inputStream.isAtEnd()) {
minutes = (int) inputStream.readInt64();
if (!inputStream.isAtEnd()) {
seconds = (int) inputStream.readInt64();
if (!inputStream.isAtEnd()) {
nanos = 1000 * (int) inputStream.readInt64();
}
}
}
}
return vf.createFromTime(new InternalTime(negative ? -1 * hours : hours, minutes, seconds, nanos, scale));
} catch (IOException e) {
throw new DataReadException(e);
}
}
use of com.mysql.cj.exceptions.DataReadException in project aws-mysql-jdbc by awslabs.
the class XProtocolDecoder method decodeByteArray.
@Override
public <T> T decodeByteArray(byte[] bytes, int offset, int length, Field f, ValueFactory<T> vf) {
try {
CodedInputStream inputStream = CodedInputStream.newInstance(bytes, offset, length);
// c.f. Streaming_command_delegate::get_string()
int size = inputStream.getBytesUntilLimit();
// for null terminator
size--;
return vf.createFromBytes(inputStream.readRawBytes(size), 0, size, f);
} catch (IOException e) {
throw new DataReadException(e);
}
}
use of com.mysql.cj.exceptions.DataReadException in project aws-mysql-jdbc by awslabs.
the class MysqlBinaryValueDecoder method decodeDate.
public <T> T decodeDate(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
if (length == 0) {
return vf.createFromDate(new InternalDate());
} else if (length != NativeConstants.BIN_LEN_DATE) {
throw new DataReadException(Messages.getString("ResultSet.InvalidLengthForType", new Object[] { length, "DATE" }));
}
int year = (bytes[offset] & 0xff) | ((bytes[offset + 1] & 0xff) << 8);
int month = bytes[offset + 2];
int day = bytes[offset + 3];
return vf.createFromDate(new InternalDate(year, month, day));
}
use of com.mysql.cj.exceptions.DataReadException in project aws-mysql-jdbc by awslabs.
the class MysqlBinaryValueDecoder method decodeDatetime.
public <T> T decodeDatetime(byte[] bytes, int offset, int length, int scale, ValueFactory<T> vf) {
if (length == 0) {
return vf.createFromTimestamp(new InternalTimestamp());
} else if (length != NativeConstants.BIN_LEN_DATE && length != NativeConstants.BIN_LEN_TIMESTAMP_WITH_MICROS && length != NativeConstants.BIN_LEN_TIMESTAMP_NO_FRAC) {
// the value can be any of these lengths (check protocol docs)
throw new DataReadException(Messages.getString("ResultSet.InvalidLengthForType", new Object[] { length, "TIMESTAMP" }));
}
int year = 0;
int month = 0;
int day = 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
int nanos = 0;
year = (bytes[offset + 0] & 0xff) | ((bytes[offset + 1] & 0xff) << 8);
month = bytes[offset + 2];
day = bytes[offset + 3];
if (length > NativeConstants.BIN_LEN_DATE) {
hours = bytes[offset + 4];
minutes = bytes[offset + 5];
seconds = bytes[offset + 6];
}
if (length > NativeConstants.BIN_LEN_TIMESTAMP_NO_FRAC) {
// MySQL PS protocol uses microseconds
nanos = 1000 * ((bytes[offset + 7] & 0xff) | ((bytes[offset + 8] & 0xff) << 8) | ((bytes[offset + 9] & 0xff) << 16) | ((bytes[offset + 10] & 0xff) << 24));
}
return vf.createFromDatetime(new InternalTimestamp(year, month, day, hours, minutes, seconds, nanos, scale));
}
Aggregations