Skip to content

Commit

Permalink
[hack] bare bones sqlite wrapper for use in OCaml code
Browse files Browse the repository at this point in the history
Summary:
simple library that statically allocates a few dbs and prepared statements
up to a hardcoded maximum

it can be used to bind and extract ints and strings from sqlite.

Reviewed By: dabek

Differential Revision: D8325025

fbshipit-source-id: 37312532ab5f3da69e559d739bf13e2c1f275b02
  • Loading branch information
Greg Nisbet authored and facebook-github-bot committed Jun 10, 2018
1 parent 29cf3b4 commit fa0ec71
Show file tree
Hide file tree
Showing 2 changed files with 537 additions and 0 deletions.
62 changes: 62 additions & 0 deletions hack/heap/dumbsqlite.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
type sqlerr = int

type sqlerr_t = { sqlerr : sqlerr }

type classified_error =
| SqliteOk
| Row
| Done
| SqliteErr of int
| WrapperErr of int

let classify_sqlerr {sqlerr} =
match sqlerr with
| 0 -> SqliteOk
| 100 -> Row
| 101 -> Done
| _ -> (
if sqlerr > 0 then SqliteErr sqlerr
else WrapperErr sqlerr
)

external caml_dumb_sqlite_open : int -> string -> bool -> sqlerr = "caml_dumb_sqlite_open"
let caml_dumb_sqlite_open ~index ~path ~readonly =
{sqlerr = caml_dumb_sqlite_open index path readonly}

external caml_dumb_sqlite_close : int -> sqlerr = "caml_dumb_sqlite_close"
let caml_dumb_sqlite_close ~index =
{sqlerr = caml_dumb_sqlite_close index}

external caml_dumb_sqlite_prepare : int -> int -> string -> sqlerr = "caml_dumb_sqlite_prepare"
let caml_dumb_sqlite_prepare ~index ~s_index ~sql =
{sqlerr = caml_dumb_sqlite_prepare index s_index sql}

external caml_dumb_sqlite_reset : int -> sqlerr = "caml_dumb_sqlite_reset"
let caml_dumb_sqlite_reset ~s_index =
{sqlerr = caml_dumb_sqlite_reset s_index}

external caml_dumb_sqlite_step : int -> sqlerr = "caml_dumb_sqlite_step"
let caml_dumb_sqlite_step ~s_index =
{sqlerr = caml_dumb_sqlite_step s_index}

external caml_dumb_sqlite_finalize : int -> sqlerr = "caml_dumb_sqlite_finalize"
let caml_dumb_sqlite_finalize ~s_index =
{sqlerr = caml_dumb_sqlite_finalize s_index}

external caml_dumb_sqlite_bind_int64 : int -> int -> Int64.t -> sqlerr = "caml_dumb_sqlite_bind_int64"
let caml_dumb_sqlite_bind_int64 ~s_index ~param ~value =
{sqlerr = caml_dumb_sqlite_bind_int64 s_index param value}

external caml_dumb_sqlite_bind_text : int -> int -> string -> sqlerr = "caml_dumb_sqlite_bind_text"
let caml_dumb_sqlite_bind_text ~s_index ~param ~value =
{sqlerr = caml_dumb_sqlite_bind_text s_index param value}

external caml_dumb_sqlite_column_int64 : int -> int -> (sqlerr * Int64.t) = "caml_dumb_sqlite_column_int64"
let caml_dumb_sqlite_column_int64 ~s_index ~column =
let (sqlerr, res) = caml_dumb_sqlite_column_int64 s_index column in
({sqlerr = sqlerr}, res)

external caml_dumb_sqlite_column_text : int -> int -> (sqlerr * string) = "caml_dumb_sqlite_column_text"
let caml_dumb_sqlite_column_text ~s_index ~column =
let (sqlerr, res) = caml_dumb_sqlite_column_text s_index column in
({sqlerr = sqlerr}, res)
Loading

0 comments on commit fa0ec71

Please sign in to comment.