Skip to content

Commit 6face6d

Browse files
authored
Merge pull request #258 from tatchi/fix-nullability-explicit-null-column
add test to show wring nullability inference
2 parents 098c91c + 92e8d37 commit 6face6d

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/gen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ let is_param_nullable param =
242242

243243
let is_attr_nullable attr =
244244
let open Sql in
245-
attr.domain.nullability = Nullable || Constraints.mem Null attr.extra (* constraints should not be needed *)
245+
attr.domain.nullability = Nullable
246246

247247
type value = { vname : string; vtyp : string; nullable : bool; }
248248

test/cram/test.t

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,6 +3424,53 @@ Test IS NOT NULL type refinement:
34243424
end (* module List *)
34253425
end (* module Sqlgg *)
34263426
3427+
Test IS NOT NULL type refinement with explicit NULL column:
3428+
$ sqlgg -gen caml -no-header -dialect=mysql - <<'EOF' 2>&1
3429+
> CREATE TABLE test (id INT, str TEXT, name TEXT NULL);
3430+
> SELECT str, name FROM test WHERE name IS NOT NULL;
3431+
> EOF
3432+
module Sqlgg (T : Sqlgg_traits.M) = struct
3433+
3434+
module IO = Sqlgg_io.Blocking
3435+
3436+
let create_test db =
3437+
T.execute db ("CREATE TABLE test (id INT, str TEXT, name TEXT NULL)") T.no_params
3438+
3439+
let select_1 db callback =
3440+
let invoke_callback stmt =
3441+
callback
3442+
~str:(T.get_column_Text_nullable stmt 0)
3443+
~name:(T.get_column_Text stmt 1)
3444+
in
3445+
T.select db ("SELECT str, name FROM test WHERE name IS NOT NULL") T.no_params invoke_callback
3446+
3447+
module Fold = struct
3448+
let select_1 db callback acc =
3449+
let invoke_callback stmt =
3450+
callback
3451+
~str:(T.get_column_Text_nullable stmt 0)
3452+
~name:(T.get_column_Text stmt 1)
3453+
in
3454+
let r_acc = ref acc in
3455+
IO.(>>=) (T.select db ("SELECT str, name FROM test WHERE name IS NOT NULL") T.no_params (fun x -> r_acc := invoke_callback x !r_acc))
3456+
(fun () -> IO.return !r_acc)
3457+
3458+
end (* module Fold *)
3459+
3460+
module List = struct
3461+
let select_1 db callback =
3462+
let invoke_callback stmt =
3463+
callback
3464+
~str:(T.get_column_Text_nullable stmt 0)
3465+
~name:(T.get_column_Text stmt 1)
3466+
in
3467+
let r_acc = ref [] in
3468+
IO.(>>=) (T.select db ("SELECT str, name FROM test WHERE name IS NOT NULL") T.no_params (fun x -> r_acc := invoke_callback x :: !r_acc))
3469+
(fun () -> IO.return (List.rev !r_acc))
3470+
3471+
end (* module List *)
3472+
end (* module Sqlgg *)
3473+
34273474
Test IS NOT NULL type refinement with IS NULL:
34283475
$ sqlgg -gen caml -no-header -dialect=mysql - <<'EOF' 2>&1
34293476
> CREATE TABLE test (id INT, str TEXT, name TEXT);

0 commit comments

Comments
 (0)