Something went wrong. Try again.
SQLite file format and SQL engine in pure OCaml
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556open Cmdliner
(* The rows of the check, as sqlite3 prints them: "ok", or the page row behind its banner and one row per index or row finding. *)let check ~quick ~max_errors db = Common.user_error ~db @@ fun () -> Eio_main.run @@ fun env -> Eio.Switch.run @@ fun sw -> Common.with_db env ~sw ~create:false ~read_only:true db @@ fun t -> let pragma = if quick then "quick_check" else "integrity_check" in let rows = Sqlite.Raw.query t (Fmt.str "PRAGMA %s(%d)" pragma max_errors) ~params:[] in List.iter List_mode.print rows; rows = [ [ Sqlite.Text "ok" ] ]
let run () db quick max_errors = if not (check ~quick ~max_errors db) then exit 1
let cmd = let quick = Arg.( value & flag & info [ "quick" ] ~doc: "Run $(b,PRAGMA quick_check): compare each index's entry count \ with its table's rows instead of looking every row up.") in let max_errors = Arg.( value & opt int 100 & info [ "max-errors" ] ~docv:"N" ~doc: "Stop after $(docv) findings, as $(b,PRAGMA integrity_check(N)) \ does; $(b,0) or less means 100.") in let info = Cmd.info "check" ~doc:"Check a database's integrity." ~man: [ `S Manpage.s_description; `P "Run $(b,PRAGMA integrity_check) on a database, read-only, and \ print what it reports in sqlite3's words: $(b,ok), or every page \ no b-tree or freelist reaches, every page two structures share, a \ freelist whose length disagrees with the header, keys out of \ order, and every index that disagrees with its table."; `P "Exits 1 when the report is not $(b,ok)."; `S Manpage.s_examples; `P "$(iname) mydb.db"; `P "$(iname) --quick --max-errors=10 mydb.db"; ] in Cmd.v info Term.(const run $ Common.logging $ Common.db_arg $ quick $ max_errors)