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

Handling unsigned integer types from MySQL #1181

Closed
davechallis opened this issue Sep 21, 2017 · 4 comments
Closed

Handling unsigned integer types from MySQL #1181

davechallis opened this issue Sep 21, 2017 · 4 comments

Comments

@davechallis
Copy link

I've got a lot of MySQL tables with unsigned integer types (e.g. id INT(10) UNSIGNED).

I'm struggling to run queries against these with Diesel when their values exceed the positive i32 max value.

E.g. using:

extern crate diesel;
#[macro_use] extern crate diesel_codegen;

use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
use diesel::expression::sql;
use diesel::types::Integer;

#[derive(PartialEq, Debug, Queryable)]
struct Thing {
    id: i32
}

fn main() {
    let url = "mysql://user:pass@localhost/test"
    let conn = MysqlConnection::establish(&url).unwrap();

    let query = sql::<Integer>("SELECT 4000000000");
    query.load::<Thing>(&conn);
}

results in a runtime error:

Err(DeserializationError(StringError("Numeric overflow/underflow occurred")))

which is expected, as it overflows i32, but is an acceptable u32 value.

Changing my struct to:

struct Thing {
    id: u32
}

instead results in a compiler error:

the trait `diesel::types::FromSqlRow<diesel::types::Integer, _>` is not implemented for `(u32,)

Is this just unsupported by Diesel, or is there a different approach I should be taking for dealing with MySQL's unsigned integers?

@killercup
Copy link
Member

#912 reverted #782 because of u16, but maybe the other additions were valid?

@sgrif
Copy link
Member

sgrif commented Sep 21, 2017

IIRC I was just straight up incorrect in #912, and we just need a PR that updates the code to not conflict with the latest master

@sgrif sgrif added this to the 1.2 milestone Jan 17, 2018
@sgrif
Copy link
Member

sgrif commented Jan 17, 2018

Adding this to the milestone. The solution is literally just rebasing an old PR. The longer we wait, the harder that will be.

@joshleeb
Copy link
Contributor

joshleeb commented Feb 17, 2018

I'd like to take this one on as a first issue 😄

I attempted to rebase #782 with git, but I think it'll be easier to reapply it manually instead.

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

No branches or pull requests

4 participants