vapor / mysql-nio

🐬 Non-blocking, event-driven Swift client for MySQL.
MIT License
91 stars 26 forks source link

SimpleQuery vs Query with Date and UUID columns ? #70

Open Phil89a opened 2 years ago

Phil89a commented 2 years ago

Just wondering - if there is a difference in the way Date and UUID columns are handled between SimpleQuery and Query ?

If I run exactly the same SQL code in both, the SimpleQuery fails when trying to read a returned Date column; whereas Query reads the column fine.

Likewise, SimpleQuery correctly returns a UUID column, but Query fails to read the UUID and it has to be read as a .string.

Any ideas?

gwynne commented 1 year ago

Apologies for the extremely late response to this issue 😕.

The problem is due to SimpleQuery using the old text-based protocol which sends values as part of the query itself and returns rows using the text resultset protocol, whereas Query uses the prepared statement binary protocol. MySQLNIO's current implementation only has Date decoding support for the binary protocol. While the UUID support does ostensibly support both protocols, the text protocol happens to be identical for UUIDs and strings, while the binary protocol entirely differs; there is no native UUID support in MySQL, and it ends up stored as either VARCHAR or VARBINARY. If a UUID was originally stored as a string, it has to be read back as one, and the current implementation can't tell the difference.

The MySQLNIO rewrite I've had in progress for roughly three or four ages of the universe at this point (#73) will robustly handle these situations.