SQL frontend over the catalog engine
1(*---------------------------------------------------------------------------
2 Copyright (c) 2026 Thomas Gazagnaire. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6(** SQLite's value-level binary operators, keyed by the AST's {!Ast.binop}.
7
8 The comparison value (with column affinity and collation), the opcode-free
9 operators (AND/OR/LIKE/GLOB/[||]/JSON), and [IN (list)] membership, over
10 {!Value_ops} and {!Func}. Shared by the tree-walker and the register VM so
11 an operator's value agrees in both. *)
12
13val compare_op :
14 ?coll:string -> Ast.binop -> Ast.value -> Ast.value -> Ast.value
15(** [compare_op op a b] is a comparison's value: NULL if either operand is NULL,
16 else [1]/[0] for the ordering under the optional collation [coll]. *)
17
18val in_eval : ?coll:string -> Ast.value -> Ast.value list -> Ast.value
19(** [in_eval v candidates] is [v IN (candidates)] as a three-valued membership:
20 an empty set is [0] (so [NOT IN ()] is [1]); a NULL [v] over a non-empty set
21 is NULL; else [1] on a match, NULL if none match but a NULL candidate is
22 present, [0] otherwise. *)
23
24val compare_with_affinity :
25 ?coll:string ->
26 a_col:bool ->
27 b_col:bool ->
28 Ast.binop ->
29 Ast.value ->
30 Ast.value ->
31 Ast.value
32(** [compare_with_affinity ~a_col ~b_col op a b] is the comparison value
33 applying SQLite's column affinity: a numeric column coerces a well-formed
34 text operand to a number ([c = '5'] matches a numeric [c]), two literals get
35 no affinity. [a_col]/[b_col] mark whether each operand is a column. *)
36
37val binop_value : Ast.binop -> Ast.value -> Ast.value -> Ast.value
38(** [binop_value op a b] is the value of an opcode-free binary operator: the
39 three-valued AND/OR, LIKE/GLOB, [||] concatenation, and the JSON accessors.
40 Arithmetic and comparison operators do not reach here. *)
41
42val in_list_value :
43 ?coll:string -> e_col:bool -> Ast.value -> Ast.value list -> Ast.value
44(** [in_list_value ~e_col v cands] is [v IN (cands)] with affinity: a numeric
45 left column [e_col] coerces each text candidate to a number, then {!in_eval}
46 decides membership. *)