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

feat: implement unsigned int support for sqlite #919

Merged
merged 1 commit into from
Jan 14, 2021

Conversation

dignifiedquire
Copy link
Contributor

No description provided.

@mehcode mehcode merged commit b02c6c5 into launchbadge:master Jan 14, 2021
@mehcode
Copy link
Member

mehcode commented Jan 14, 2021

Thank you ❤️


impl<'q> Encode<'q, Sqlite> for u64 {
fn encode_by_ref(&self, args: &mut Vec<SqliteArgumentValue<'q>>) -> IsNull {
args.push(SqliteArgumentValue::Int64(*self as i64));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in data loss for u64 larger than std::i64::MAX.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be try_into() but Encode is not fallible (yet).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dignifiedquire Does your use case need u64 ? It might be safer to remove this one until we have a fallible Encode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, you are right. I am fine not having u64 supported for the moment, so likely better to remove this.

@dignifiedquire
Copy link
Contributor Author

@mehcode there is still an issue with this code I am afraid, but I am not sure where it is coming from (sorry for not mentioning earlier here)

Caused by:
    0: error occurred while decoding column 2: mismatched types; Rust type `deltachat::contact::Origin` (as SQL type `INTEGER`) is not compatible with SQL type `INTEGER`
    1: mismatched types; Rust type `deltachat::contact::Origin` (as SQL type `INTEGER`) is not compatible with SQL type `INTEGER`', src/qr.rs:523:23
n

happens when I try to use this with

#[derive(sqlx::Type)]
#[repr(u32)]
enum Origin {
  Foo = 1,
  Bar = 2,
  // ... 
}

mehcode added a commit that referenced this pull request Feb 4, 2021
@dignifiedquire
Copy link
Contributor Author

@mehcode any ideas on the above?

@w4
Copy link

w4 commented Feb 15, 2021

@dignifiedquire I ran into that one recently, try using a signed integer instead ie. #[repr(i32)], not sure why this is the way it is but the workaround works for my scenario at least.

@mehcode
Copy link
Member

mehcode commented Feb 15, 2021

Thanks for pinging me. I'll look into this.

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

Successfully merging this pull request may close these issues.

4 participants