Skip to content

Commit

Permalink
Fix option recognition in PostgreSQL driver and add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
paurkedal committed Apr 18, 2021
1 parent 74317cd commit 0624251
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v1.5.1 - 2021-04-18

- Fix option recognition in PostgreSQL driver (GPR#67 mefyl).
- Fix option recognition in MariaDB driver and add test (Petter A. Urkedal).

## v1.5.0 - 2021-04-11

- Request the full UTF-8 character for the MariaDB connection.
Expand Down
2 changes: 1 addition & 1 deletion lib-driver/caqti_driver_mariadb.ml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ module Connect_functor (System : Caqti_driver_sig.System_unix) = struct
| Caqti_type.Option t ->
let j = i + Caqti_type.length t in
let rec null_only k =
k = j || Mdb.Field.null_value row.(k) && null_only (i + 1) in
k = j || Mdb.Field.null_value row.(k) && null_only (k + 1) in
if null_only i then Ok (j, None) else
(match decode_row ~uri row i t with
| Ok (j, y) -> Ok (j, Some y)
Expand Down
19 changes: 18 additions & 1 deletion tests/test_sql.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ module Q = struct
| `Sqlite -> "SELECT CAST(? AS blob)"
| _ -> failwith "Unimplemented."

let select_compound_option =
(tup2 (option int) (option int) -->
tup3 int (option (tup3 (option int) (option int) (option int))) int)
@@ fun _ ->
"SELECT -1, $1 + 1, $2 + 1, $1 + 1, -2"

let abc = enum ~encode:string_of_abc ~decode:abc_of_string "abc"

let create_type_abc = (unit -->! unit) @@ fun _ ->
Expand Down Expand Up @@ -351,7 +357,18 @@ struct
test_times tfs
in
test_times [0.0; -1.2e-5; 1.23e-3; -1.001; 1.23e2; -1.23e5]
end
end >>= fun () ->

(* Prepared: compound option *)
let check x y z =
Db.find Q.select_compound_option (x, y) >>= Sys.or_fail
>|= fun (a, b, c) ->
assert (a = -1 && b = z && c = -2);
in
check None None None >>= fun () ->
check None (Some 3) (Some (None, Some 4, None)) >>= fun () ->
check (Some 7) None (Some (Some 8, None, Some 8)) >>= fun () ->
check (Some 7) (Some 3) (Some (Some 8, Some 4, Some 8))

let test_enum (module Db : Caqti_sys.CONNECTION) =
let with_type_abc f =
Expand Down

0 comments on commit 0624251

Please sign in to comment.