QueryBindings bindings, int index,
QueryContext queryContext, TypesRegistryService typesRegistryService) {
TInstance targetType = type != null ? type.getType() : null;
if (targetType == null && encoded != null) {
throw new UnknownDataTypeException(null);
}
ValueSource source;
if (encoded == null) {
Value value = new Value(targetType);
value.putNull();
bindings.setValue(index, value);
return;
}
else if (!binary) {
try {
source = new Value(MString.varchar(), new String(encoded, encoding));
}
catch (UnsupportedEncodingException ex) {
throw new UnsupportedCharsetException(encoding);
}
}
else {
try {
switch (type.getBinaryEncoding()) {
case BINARY_OCTAL_TEXT:
source = new Value(MBinary.VARBINARY.instance(false), encoded);
break;
case INT_8:
case INT_16:
case INT_32:
case INT_64: // Types.BIGINT
// Go by the length sent rather than the implied type.
source = decodeIntegerType(encoded);
break;
case FLOAT_32:
source = new Value(MApproximateNumber.FLOAT.instance(false), getDataStream(encoded).readFloat());
break;
case FLOAT_64:
source = new Value(MApproximateNumber.DOUBLE.instance(false), getDataStream(encoded).readDouble());
break;
case BOOLEAN_C:
source = new Value(AkBool.INSTANCE.instance(false), encoded[0] != 0);
break;
case TIMESTAMP_INT64_MICROS_2000_NOTZ: // Types.TIMESTAMP
source = decodeTimestampInt64Micros2000NoTZ(encoded);
break;
case UUID:
Value value = new Value(AkGUID.INSTANCE.instance(false));
value.putObject(AkGUID.bytesToUUID(encoded, 0));
source = value;
break;
// Note: these types had previous implementations, but I couldn't exercise them in tests to verify
// either with jdbc or pg8000. If you run into them, try looking at the log for this file, it most
// likely has a correct starting point
case STRING_BYTES:
case TIMESTAMP_FLOAT64_SECS_2000_NOTZ: // Types.TIMESTAMP
case DAYS_2000: // DATE
case TIME_FLOAT64_SECS_NOTZ: // TIME
case TIME_INT64_MICROS_NOTZ: // TIME
case DECIMAL_PG_NUMERIC_VAR:
default:
throw new UnknownDataTypeException(type.toString());
}
}
catch (UnsupportedEncodingException ex) {
throw new UnsupportedCharsetException(encoding);
}