Skip to content

JSON in prepared statement broken #1173

Open

Description

@matt1986hias

Attempting to insert a JSON object as a prepared statement value for a JSON-type column fails with:
Error: Incorrect arguments to mysqld_stmt_execute

let obj = { "abc": 123 }; db.execute("INSERT INTO table VALUES (?)", [obj]);

The problem appears to be using Types.JSON in toParameter() in execute.js. According to types.js the Types.JSON constant was taken from a mysql 5.5 header mysql_com.h where it might have been defined at some point, but mysql 8.0 doesn't have it anymore. The only place I can find 0xF5 as a JSON indicator is binary_log_types.h, which I think is completely unrelated.
It seems there is no specific JSON parameter type (anymore), see C API reference.

When I change it to Types.STRING it works. Perhaps this is what it should be?

Activity

  1. sidorares commented on Jun 23, 2020

    @sidorares
    Owner

    When I change it to Types.STRING it works.

    Would this be a valid query with your schema: INSERT INTO table VALUES ('{ "abc": 123 }') ?

  2. matt1986hias commented on Jun 23, 2020

    @matt1986hias
    Author

    When I put it directly into the query without going through a prepared statement substitution it works, yes.

  3. sidorares commented on Jun 23, 2020

    @sidorares
    Owner

    We can probably change it to Types.STRING. Over the wire it's sent as string anyway, but parameters values list is prefixed by parameters description list that includes the outgoing type (server will coerce to schema type after receiving, afaik the type in the outgoing packet is used to tell server how to deserialise.) This is where we currently sending 0xF5 for JSON, and maybe we should send 0xfe / STRING

    Would you be able to help fixing this @dergutehirte ? This includes checking how it's currently covered with unit tests and running fix against at least mysql 5.7 and 8 ( and adding unit test if it's missing )

  4. matt1986hias commented on Jun 23, 2020

    @matt1986hias
    Author

    Sorry not at the moment. I'll check back when I have less workload and if it's still open I fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions