简体   繁体   中英

MySQL. How to send long data to mysql-server?

I'm currently developing my NodeJS based MySQL client. Please, don't ask why, it's just the way I do stuff.

So far it works pretty well, but I really puzzled with the way of sending big amounts of data to prepared statements.

If I try to send all the data with stmt_execute command, it, obviously, states that package is too long. MySQL protocol documentation proposes using COM_STMT_SEND_LONG_DATA for such cases, but there is almost none of information on how to use it properly, only the package description.

https://dev.mysql.com/doc/internals/en/com-stmt-send-long-data.html

While those are packets to be sent before STMT_EXECUTE, I'm sending long data with SID 00, 01 and then execute packet with SID 02. Server doesn't like it, complaining about "Got packets out of order". Well, then I tried to use SID 00 for all of the packets, and server takes it.

But there is another problem. If I send it as long data, should I exclude it from execute packet? Or should I replace it with some placeholder? After value has been excluded from STMT_EXECUTE packet, server complains that "Incorrect arguments to mysqld_stmt_execute".

I tried to look into source code of some other mysql clients, but have got no luck.

Official nodejs/mysql client, for example, doesn't support prepared statements at all.

Can anyone help with it somehow?

In some hours I'll try to upload my source code, if it will make a difference.

It feels like I found a solution... sort of.

After all long data packets are sent I should send an execute command with empty value for required parameter, not just exclude it from list. It will join all previously sent packets and append empty value in the end of the result.

Sounds a little bit junkie, but it works, as far as I see (though tried on 16 byte message, split by 5 bytes).

This is my current solution. I've made a function to send long data, splitting it into packets. https://github.com/MadBrozzeR/mysql/blob/master/operations/sendLongData.js

So far it feels like the best (and the only) solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM