-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Rust type core::option::Option<alloc::string::String>
is not compatible with SQL type NULL
#2416
Comments
The fix is probably to add |
@abonander is there a workaround for now? I tried to override the types and that yielded the same error as wwell ( Happy to test the fix you proposed too. |
FWIW I tried this and it doesn't resolve the issue. |
I ran into the same issue for |
I have an idea, this wont solve the issue but it is a possible workaround. You should do a manual You should call |
Also it is needed to change Edit: It is already implemented in this code |
I have been researching about the issue, and I think it should be is this https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/any/row.rs#L49-L67 |
okay i have found the issue,
This fix does not work because type Info for AnyTypeInfo is bug for NULL type , because |
impl TypeInfo for AnyTypeInfo {
fn is_null(&self) -> bool {
self.kind == Null
}
fn name(&self) -> &str {
use AnyTypeInfoKind::*;
match self.kind {
Bool => "BOOLEAN",
SmallInt => "SMALLINT",
Integer => "INTEGER",
BigInt => "BIGINT",
Real => "REAL",
Double => "DOUBLE",
Text => "TEXT",
Blob => "BLOB",
Null => "NULL",
}
}
} and impl<T: Type<DB>, DB: Database> Type<DB> for Option<T> {
fn type_info() -> DB::TypeInfo {
<T as Type<DB>>::type_info()
}
fn compatible(ty: &DB::TypeInfo) -> bool {
ty.is_null() || <T as Type<DB>>::compatible(ty)
}
} should solve the issue. |
After fixing this i got this issue,
|
The new issue is fixed changing https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/any/value.rs#L71-L97 fn is_null(&self) -> bool {
matches!(self.kind, AnyValueKind::Null)
} |
Also is broken this one https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/any/value.rs#L99-L125 |
Bug Description
When using the
AnyConnection
driver to access an SQLite DB, I am unable to read rows with NULL values. It appears sqlx parses the column type asNULL
.Example:
Minimal Reproduction
A small code snippet or a link to a Github repo or Gist, with instructions on reproducing the bug.
Test to reproduce the problem:
Running the test yields:
Info
rustc --version
: rustc 1.67.1 (d5a82bbd2 2023-02-07)The text was updated successfully, but these errors were encountered: