Something went wrong. Try again.
SQL frontend over the catalog engine
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051(* sqlite3's rules over registers, which the register VM runs by. *)
module Register = Catalog.Registermodule Sem = Sql.Sqlite3_semantics
let reg set v = let m = Register.v () in set m v; m
let big = reg Register.set_int64let real = reg Register.set_reallet text = reg Register.set_text
(* Wide integers order exactly, including against a float. Widening 2^63-1 to a double rounds it up to 2^63, so a naive float comparison would call 2^63-1 and 2.0^63 equal; the exact intFloatCompare keeps 2^63-1 strictly below 2^63. *)let test_bigint_compare () = Alcotest.(check int) "2^63-1 > 2^63-2" 1 (Sem.compare (big 9223372036854775807L) (big 9223372036854775806L)); Alcotest.(check int) "2^63-1 < 2.0^63 exactly" (-1) (Sem.compare (big 9223372036854775807L) (real 0x1p63))
(* A filter's truth is the register cast to NUMERIC, true unless that is zero (lang_expr.html sec.14), so text is true only when it leads with a non-zero number. sqlite3 3.54.1:
SELECT '5x' IS TRUE, 'abc' IS TRUE, '' IS TRUE, '0' IS TRUE, 0.5 IS TRUE -> 1|0|0|0|1 *)let test_truth () = let truth what expected m = Alcotest.(check bool) what expected (Sem.truth m) in truth "'5x' leads with 5" true (text "5x"); truth "'abc' leads with no number" false (text "abc"); truth "'' is no number" false (text ""); truth "'0' is zero" false (text "0"); truth "0.5 is not zero" true (real 0.5); truth "NULL passes no filter" false (Register.v ())
let suite = ( "sqlite3_semantics", [ Alcotest.test_case "wide integers compare exactly" `Quick test_bigint_compare; Alcotest.test_case "a filter's truth" `Quick test_truth; ] )