-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
<uuid::fmt::Hyphenated as sqlx::Type<MySql>::compatible()
is wrong?
#3409
Comments
Likely related to #3387. |
Interesting, so running your example @AlphaKeks, I get
then when I point the
so #3400 fixes the second test case, but not the first. I wonder if it's something related to how you're inserting the UUID? you can reproduce by removing the
I'll look into this a bit further later, but if you get a chance before I do, let me know if that branch fixes your issue! |
so #3400 fixes the second test case ( changing it to this fixes the test case (and a case I added, which empties the table, adds a fresh row, SELECTs and compares, to make sure it isn't an issue with the insertion) impl Decode<'_, MySql> for Uuid {
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError> {
// delegate to the &[u8] type to decode from MySQL
let slice = <&[u8] as Decode<MySql>>::decode(value)?;
let bytes = String::from_utf8(Vec::from(slice))?;
// construct a Uuid from the returned bytes
Uuid::from_str(&bytes).map_err(Into::into)
}
} now, obviously this isn't ideal since it's pulling a byte slice from the DB, converting that to a @abonander is this right, does the current seems to me like we should be storing Uuids as a blob of 16 bytes, but fetching from the DB yields 36 bytes. i don't yet understand what's going on under the hood, but it does seem to be like these here's some more verbose output:
maybe this is more of the |
Here is a slightly cleaner impl Decode<'_, MySql> for Uuid {
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError> {
// delegate to the &str type to decode from MySQL
let slice = <&str as Decode<MySql>>::decode(value)?;
// construct a Uuid from the returned bytes
Uuid::from_str(slice).map_err(Into::into)
}
} |
what I still don't understand is why
|
Bug Description
I'm running MariaDB and have a table with a
UUID
column. When trying to fetch a row from this table and decoding the column intouuid::Uuid
, it complains saying it expected 16 bytes, but got 36. This sort of makes sense, as I inserted the row using a string literal of a hyphenated UUID. When I try to useuuid::fmt::Hyphenated
instead, it says the types aren't compatible. When using thequery!()
macro, it infers the type to beVec<u8>
, and decoding that as UTF-8 yields the expected string value I originally inserted. Maybe I'm just using these types incorrectly?From what I can see in
sqlx-mysql
,uuid::Uuid
expects 16 bytes, anduuid::fmt::Hyphenated
just forwards tostr
? Butstr
says it isn't compatible with anything that has aBINARY
flag set, which the returned column does in my case...Minimal Reproduction
https://github.com/AlphaKeks/sqlx-uuid-repro
What I would expect to happen is that either of the two queries succeed, but they both fail with the errors mentioned above.
Info
["macros", "mysql", "runtime-tokio-rustls", "uuid"]
rustc --version
:rustc 1.80.0 (051478957 2024-07-21)
The text was updated successfully, but these errors were encountered: