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

Comparison between Nullable SqlType could crash the code #153

Open
kamoii opened this issue Oct 31, 2020 · 0 comments
Open

Comparison between Nullable SqlType could crash the code #153

kamoii opened this issue Oct 31, 2020 · 0 comments

Comments

@kamoii
Copy link

kamoii commented Oct 31, 2020

Comparison operators, like (.==), accepts aribtrary SqlType value.

(.==) :: (Same s t, SqlType a) => Col s a -> Col t a -> Col s Bool

Since Maybe Int is also an SqlTpye, the following code type checks.
But one of the operand is NULL, the result will be NULL, making the code crash.

test :: IO Bool
test = withSQLite "test.sqlite" $ do
    [b] <- query $ pure $ just (4 :: Col s Int) .== literal Nothing
    pure b

Using Nullable module's operator (?==) will get the proper result type Col s (Maybe Bool).
But the need to correctly use (.==) and (?==) is error-prone.

First thing that comes to my mind, is to add type IsNullable a :: 'Bool to SqlType type class.
SqlType (Maybe a) instance will be the only instance to have IsNullable (Maybe a) = 'True, and other instances will have False.Then we could wrap Bool with Maybe when SqlType is IsNullable.

kamoii pushed a commit to kamoii/nelda that referenced this issue Oct 31, 2020
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

No branches or pull requests

1 participant