-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hack] bare bones sqlite wrapper for use in OCaml code
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
1 parent
29cf3b4
commit fa0ec71
Showing
2 changed files
with
537 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.