From 62123e577ee5d4066d53f8ad7e5ac3d2eb190430 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Wed, 18 Nov 2026 20:24:52 +0100 Subject: Securized the queries in the database with a dedicated type for the Identifiers --- test/identifier.ml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/identifier.ml (limited to 'test/identifier.ml') diff --git a/test/identifier.ml b/test/identifier.ml new file mode 100644 index 0000000..322f459 --- /dev/null +++ b/test/identifier.ml @@ -0,0 +1,42 @@ +let name = __FILE__ + +let description = + "Check the [Model.Identifier] module: validation of the names given as \ + arguments, their quoted SQL form, the predefined columns and the composite \ + names" + +let speclist () = [] + +type t = string list + +let pp : Format.formatter -> t -> unit = + Format.pp_print_list ~pp_sep:Format.pp_print_newline Format.pp_print_string + +(** A valid name is printed in its quoted SQL form, an invalid one is + reported *) +let check : string -> string = + fun s -> + match Model.Identifier.of_string_opt s with + | Some id -> Model.Identifier.quote id + | None -> "invalid: \"" ^ s ^ "\"" + +let exec : string list -> t = + fun args -> + (* The anonymous arguments are collected in reverse order by the test + harness *) + match List.rev args with + | "check" :: names -> List.map check names + | "predefined" :: [] -> + [ + "id = " ^ Model.Identifier.quote Model.Identifier.id; + "parent = " ^ Model.Identifier.quote Model.Identifier.parent; + "target = " ^ Model.Identifier.quote Model.Identifier.target; + ] + | "dot" :: [ a; b ] -> + [ + Model.Identifier.quote + (Model.Identifier.dot + (Model.Identifier.of_string a) + (Model.Identifier.of_string b)); + ] + | _ -> failwith "Invalid arguments" -- cgit v1.2.3