Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MySQL] Parameters of type Binary must match the size of the type defined for the table #922

Closed
DavideD opened this issue Mar 23, 2021 · 3 comments
Assignees
Labels

Comments

@DavideD
Copy link
Contributor

DavideD commented Mar 23, 2021

It seems a bug because the same query works for all the other databases.
If the table defines a column of type Binary(255) but the query uses a Binary(16), it won't find the row.

It happens in Vert.x 3.9.6 and 4.0.2

  @Test
  public void testBinaryAsParameter(TestContext ctx) {
    // The column is defined as binary(5)
    byte[] b = new byte[2];
    new Random().nextBytes( b);
    Buffer buffer = Buffer.buffer( b );
    MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
      conn.preparedQuery("INSERT INTO datatype (`Binary`, id) VALUES (?,?)").execute( Tuple.of( buffer, 678 ), ctx.asyncAssertSuccess( updateResult -> {
        conn.preparedQuery("SELECT `Binary` FROM datatype WHERE `Binary` = ?").execute( Tuple.of( buffer ), ctx.asyncAssertSuccess( result -> {
          ctx.assertEquals(1, result.size());
          Row row = result.iterator().next();
          ctx.assertEquals( buffer, row.getValue( 0 ) );
          conn.close();
        }));
      }));
    }));
  }

The commit with the change to add the test on the main branch is here: DavideD@1abdfe8

@BillyYccc
Copy link
Member

The BINARY data type value stored in the MySQL database is right padded with zero bytes to the specific length, you will get the same result if you are using jdbc. So you have to pad the param array by yourself in the code to make it correct.

@BillyYccc BillyYccc added question and removed bug Something isn't working labels Mar 24, 2021
@DavideD
Copy link
Contributor Author

DavideD commented Mar 24, 2021

you will get the same result if you are using jdbc

This seemed to work when I tested it with JDBC. But I will double check.

@DavideD
Copy link
Contributor Author

DavideD commented Mar 24, 2021

This seemed to work when I tested it with JDBC. But I will double check.

I was wrong, it doesn't work with JDBC. Uff...ok, thanks

@DavideD DavideD closed this as completed Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants