Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSSQL: TinyInt Decodes/Encodes to wrong datatype #2073

Closed
zibebe opened this issue Aug 27, 2022 · 2 comments
Closed

MSSQL: TinyInt Decodes/Encodes to wrong datatype #2073

zibebe opened this issue Aug 27, 2022 · 2 comments
Labels

Comments

@zibebe
Copy link
Contributor

zibebe commented Aug 27, 2022

Bug Description

According to Microsofts definition a TinyInt is a value between 0..255 so it must be a u8. Current implementation uses i8 for this.
https://docs.microsoft.com/de-de/sql/t-sql/data-types/int-bigint-smallint-and-tinyint-transact-sql?view=sql-server-ver15

Minimal Reproduction

Does not Work because 133 does not fit into an i8

#[derive(sqlx::Type)]
#[repr(i8)]
pub enum Quality {
    Good = 0,
    Bad = 1,
    Doubtful = 16,
    InitialValue = 133,
}

Must be:

#[derive(sqlx::Type)]
#[repr(u8)]
pub enum Quality {
    Good = 0,
    Bad = 1,
    Doubtful = 16,
    InitialValue = 133,
}

But Produces:

the trait bound `u8: sqlx::Decode<'_, _>` is not satisfied
the following other types implement trait `sqlx::Decode<'r, DB>`:
  f32
  f64
  i16
  i32
  i64
  i8

Info

  • SQLx version: v0.6.1
  • SQLx features enabled: "mssql", "runtime-tokio-rusttls"
  • Database server and version: Microsoft SQL Server 15.0.2000
  • Operating system: macOS 12.5.1
  • rustc --version: rustc 1.63.0 (4b91a6ea7 2022-08-08)
@zibebe zibebe added the bug label Aug 27, 2022
@abonander
Copy link
Collaborator

Yeah, simple mixup. MySQL's TINYINT type is signed and all the rest of MSSQL's integer types are signed, so it's an easy mistake to make.

@abonander
Copy link
Collaborator

Closed by #2074

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants