blackbeam / rust-mysql-simple

Mysql client library implemented in rust.
Apache License 2.0
658 stars 144 forks source link

All columns returned as Value::Bytes #288

Closed sathibault closed 3 years ago

sathibault commented 3 years ago

Although the Value enum has a number of variants, query results always return the data as Value::Bytes for all data types. Is there a way to get values in with the proper variant>

blackbeam commented 3 years ago

Hi. Mysql uses the Text Protocol for simple queries, this is breafly mentioned in the README (see the TextProtocol section). You have to prepare and execute a statement to get Value via binary protocol (binary protocol will give you the right variant). Please note, that mysql-type -> value-variant is a lossy mapping (this page describes the correspondence).

Also note, that from_value respects the textual representation and it may be faster to make a single query and parse a few textual rows, than to prepare and execute a statement.

sathibault commented 3 years ago

Oh, that makes sense. I will use the binary protocol. Thanks for the support.