[CONJ-743] Signed byte value wrong serialization for text protocol Created: 2019-10-31  Updated: 2019-10-31  Resolved: 2019-10-31

Status: Closed
Project: MariaDB Connector/J
Component/s: protocol
Affects Version/s: 2.4.4
Fix Version/s: 2.5.2

Type: Bug Priority: Major
Reporter: Ostap Demkovych Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

mariadb connectorj 2.4.4, mariadb 10.2.19, java 8



 Description   

I have a client prepared statement for query "select timestampadd(HOUR, ?, '2019-10-10')"
and set parameter as java Byte value '-6'.
In result, a mariadb 10.2.19 executes next query "select timestampadd(HOUR, 0xFA, '2019-10-10')"
Result of query is wrong because it has set wrong value for the parameter.

I've debugged it a bit and see that org.mariadb.jdbc.internal.com.send.parameters.ByteParameter.java uses hex for text protocol. It seems that code is wrong and should rather be similar to IntParameter.java class code.



 Comments   
Comment by Diego Dupin [ 2019-10-31 ]

Using prepareStatement.setInt(x,y) in replacement of prepareStatement.setByte(x,y) would be more accurate for your example, but you're right about driver behaviour:

  • Java byte can be in the -128 to 127 range, so sending 0xfa in place of -6 will result in wrong data
  • mysql connector same behavior.
  • will take less byte in socket.
Generated at Thu Feb 08 03:17:59 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.