You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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 )
Activity
sidorares commentedon Jun 23, 2020
Would this be a valid query with your schema:
INSERT INTO table VALUES ('{ "abc": 123 }')?matt1986hias commentedon Jun 23, 2020
When I put it directly into the query without going through a prepared statement substitution it works, yes.
sidorares commentedon Jun 23, 2020
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 / STRINGWould 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 )
matt1986hias commentedon Jun 23, 2020
Sorry not at the moment. I'll check back when I have less workload and if it's still open I fix it.
feat: typed parameters, and adopt integer types the server reports
feat: typed parameters, and adopt integer types the server reports (#…