Something went wrong. Try again.
SQL frontend over the catalog engine
Something went wrong. Try again.
12345678910111213141516171819202122232425262728(* The typed reads of a row, as sqlite3_column_* answer them. *)
module Row = Sql.Rowmodule V = Catalog.Value
let int64_of v = let n = ref 0L in Row.with_values [ v ] (fun row -> n := Row.int64 row 0); !n
(* sqlite3_column_int64 reads through sqlite3VdbeIntValue: a real by doubleToInt64 (vdbemem.c), which holds it to the int64 range, and text by sqlite3Atoi64, its leading integer, as CAST(x AS INTEGER) reads them. A NULL reads as 0. With sqlite3 3.54.1:
$ sqlite3 :memory: "SELECT CAST(1e300 AS INTEGER), CAST(-1e300 AS INTEGER), CAST(-2.9 AS INTEGER), CAST('1e3' AS INTEGER)" 9223372036854775807|-9223372036854775808|-2|1 *)let test_int64 () = let case what want v = Alcotest.(check int64) what want (int64_of v) in case "1e300" Int64.max_int (V.Float 1e300); case "-1e300" Int64.min_int (V.Float (-1e300)); case "-2.9" (-2L) (V.Float (-2.9)); case "'1e3'" 1L (V.Text "1e3"); case "NULL" 0L V.Null
let suite = ("row", [ Alcotest.test_case "int64" `Quick test_int64 ])