mirromutth/r2dbc-mysql

Boolean bind variable is echoed back as ByteBuffer

lukaseder opened this issue · 0 comments

Consider this example snippet

System.out.println(
Flux.from(cf.create())
    .flatMap(c -> Mono.from(c.createStatement("select ?p1, true").bind(0, true).execute()))
    .flatMap(it -> it.map((r, m) -> r.get(0) + ":" + r.get(1)))
    .blockFirst()
);

It prints:

java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]:1

While the boolean literal true is echoed back correctly as the value 1, the bind variable is turned into a ByteBuffer instead. The following snippet attempts to create a vew from the two bind variables

System.out.println(
Flux.from(cf.create())
    .flatMap(c -> Mono.from(c.createStatement("create view v (x, y) as select ?p1, true").bind(0, true).execute()))
    .flatMap(it -> it.getRowsUpdated())
    .blockFirst()
);

As can be verified with this query:

drop view v;
select column_name, data_type
from information_schema.columns
where table_name = 'v';

It appears that the driver sends boolean bind values as ByteBuffer:

|COLUMN_NAME|DATA_TYPE|
|-----------|---------|
|x          |varbinary|
|y          |int      |

Which is incorrect. MySQL doesn't have BOOLEAN types. They're just aliases for TINYINT, so a numeric value should be sent in BooleanCodec:
https://dev.mysql.com/doc/refman/8.0/en/other-vendor-data-types.html