From 06242515a50e2e413b7958ae09acf3aa1381de68 Mon Sep 17 00:00:00 2001 From: "Petter A. Urkedal" Date: Sun, 18 Apr 2021 17:13:03 +0200 Subject: [PATCH] Fix option recognition in PostgreSQL driver and add test. --- CHANGES.md | 5 +++++ lib-driver/caqti_driver_mariadb.ml | 2 +- tests/test_sql.ml | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 85526927..8c04f95a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/lib-driver/caqti_driver_mariadb.ml b/lib-driver/caqti_driver_mariadb.ml index 8861eb55..0feb48be 100644 --- a/lib-driver/caqti_driver_mariadb.ml +++ b/lib-driver/caqti_driver_mariadb.ml @@ -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) diff --git a/tests/test_sql.ml b/tests/test_sql.ml index 62770331..b96610db 100644 --- a/tests/test_sql.ml +++ b/tests/test_sql.ml @@ -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 _ -> @@ -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 =