Skip to content

Commit

Permalink
sqlite: remove support for u64
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode committed Feb 4, 2021
1 parent a23013e commit 2fd26b5
Showing 1 changed file with 0 additions and 24 deletions.
24 changes: 0 additions & 24 deletions sqlx-core/src/sqlite/types/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,3 @@ impl<'r> Decode<'r, Sqlite> for u32 {
Ok(value.int64().try_into()?)
}
}

impl Type<Sqlite> for u64 {
fn type_info() -> SqliteTypeInfo {
SqliteTypeInfo(DataType::Int64)
}

fn compatible(ty: &SqliteTypeInfo) -> bool {
matches!(ty.0, DataType::Int | DataType::Int64)
}
}

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));

IsNull::No
}
}

impl<'r> Decode<'r, Sqlite> for u64 {
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError> {
Ok(value.int64().try_into()?)
}
}

8 comments on commit 2fd26b5

@annadostoevskaya
Copy link

Choose a reason for hiding this comment

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

why?

@abonander
Copy link
Collaborator

Choose a reason for hiding this comment

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

@annadostoevskaya supporting u64 here is a footgun because we can't encode or decode the full range of values. The fact that SQLite accepts UNSIGNED BIG INT as a type is just sort of a lie.

@annadostoevskaya
Copy link

@annadostoevskaya annadostoevskaya commented on 2fd26b5 Feb 5, 2022

Choose a reason for hiding this comment

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

@annadostoevskaya supporting u64 here is a footgun because we can't encode or decode the full range of values. The fact that SQLite accepts UNSIGNED BIG INT as a type is just sort of a lie.

Sorry, but I don't understand.
What exactly is the problem?

Can't we do this:
2^64-1 as 0b1111...1 and convert it to 0xff...ff, and then write to database.
It's really have problem?

@abonander
Copy link
Collaborator

Choose a reason for hiding this comment

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

The database would see that value as -1 so trying to do arithmetic or comparison with the value in SQL would be problematic. Addition and subtraction might be fine as that's how two's complement works, but everything else would be wrong: multiplication, division, sorting, conversion to other numeric types, etc.

@annadostoevskaya
Copy link

Choose a reason for hiding this comment

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

The database would see that value as -1 so trying to do arithmetic or comparison with the value in SQL would be problematic. Addition and subtraction might be fine as that's how two's complement works, but everything else would be wrong: multiplication, division, sorting, conversion to other numeric types, etc.

And we can't write the database in such a way that it can interpret the value correctly?

@abonander
Copy link
Collaborator

Choose a reason for hiding this comment

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

SQLite handles all integers as signed values, so no. The smaller types work because they can be cast to a wider type, but SQLite doesn't support anything wider than 64 bit.

Sure we could shove it in a BLOB column but that has the same problems and more.

@annadostoevskaya
Copy link

Choose a reason for hiding this comment

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

SQLite handles all integers as signed values, so no. The smaller types work because they can be cast to a wider type, but SQLite doesn't support anything wider than 64 bit.

Sure we could shove it in a BLOB column but that has the same problems and more.

Ok. So this is a SQLite implementation issue. Thank you for the clarification.

@annadostoevskaya
Copy link

Choose a reason for hiding this comment

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

SQLite handles all integers as signed values, so no. The smaller types work because they can be cast to a wider type, but SQLite doesn't support anything wider than 64 bit.

Sure we could shove it in a BLOB column but that has the same problems and more.

Sorry, today i remember about this dialog and I realized my mistake
i just wanna say thanks, again

Please sign in to comment.