Skip to content

Commit

Permalink
Cookbook Ezsqlite - typo and rewriting (#2119)
Browse files Browse the repository at this point in the history
Co-authored-by: Frédéric LOYER <frederic.loyer@club-internet.fr>
  • Loading branch information
2 people authored and sabine committed Mar 28, 2024
1 parent 68a834d commit abc4d90
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions data/cookbook/database/ezsqlite/00-ezsqlite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ packages:
libraries:
- ezsqlite
discussion: |
- **Understanding `Ezsqlite`:** The `Ezsqlite` libraies proposes a set of function which permits the usage of a SQLite3 database. They are described in the [`Ezsqlite` library documentation](https://github.com/zshipko/ocaml-ezsqlite/blob/master/lib/ezsqlite.mli). It uses exection for error handling.
- **Understanding `Ezsqlite`:** The `Ezsqlite` libraies proposes a set of function which permits the usage of a SQLite3 database. They are described in the [`Ezsqlite` library documentation](https://github.com/zshipko/ocaml-ezsqlite/blob/master/lib/ezsqlite.mli). It uses exception for error handling.
- **Alternative Libraries:** `sqlite3` is an other SQLite library. The `gensqlite` is a preprocessor for `sqlite3`. `sqlexpr` is another SQLite library which comes with a PPX preprocessor. `caqti` is a portable interface which supports SQLite3, MariaDB and PostgreSQL. It may be used with the `ppx_rapper` preprocessor.
---

(* Use the `ezsqlite` library, which permits the use of a SQLite3 database. Before any use, the database much be opened. The `load` creates the database is it doesn't exist: *)
let db = Ezsqlite.load "personal.sqlite"

(* Table creation. First, the creation statement is prepared, then it is executed. The `run_ign` function is used when no values are returned by the query. *)
(* Table creation. The `run_ign` function is used when no values are returned by the query. *)
let () =
Ezsqlite.run_ign db
"CREATE TABLE personal (name VARCHAR, firstname VARCHAR, age INTEGER)"
()

(* Row insertions. The row insertion needs to bind values to the statement. Each ":id" in the query will be replaced by binded values during the execution. It is recommended to have constant query strings and use bindings to deal with variable values, especially with values from an unstrusted source. *)
(* Row insertions. First, the statement is prepared (parsed, compiled), then each ":id" is bound to actual values. Then the query is executed. It is recommended to have constant query strings and use bindings to deal with variable values, especially with values from an unstrusted source. *)
type person = { name:string; firstname:string; age:int }

let persons = [ {name="Dupont"; firstname="Jacques"; age=36};
Expand All @@ -36,7 +36,7 @@ let () =
":age", Ezsqlite.Value.Integer (Int64.of_int r.age)];
Ezsqlite.exec stmt)

(* Selection of rows. The `iter` function can execute a query while executing a given function for each row. The `text`, `blob`, `int64`, `int`, `double` functions can be used to get the values returned by the query. `column` `Value.is_null` functions can be used if we have to check the nullity (NULL SQL value) of some value. *)
(* Selection of rows. The `iter` function can execute a query while executing a given function for each row. The `text`, `blob`, `int64`, `int`, `double` functions can be used to get the values returned by the query. `column` and `Value.is_null` functions can be used if we have to check the nullity (NULL SQL value) of some values. *)
let () =
let stmt = Ezsqlite.prepare db
"SELECT name, firstname, age from personal" in
Expand Down

0 comments on commit abc4d90

Please sign in to comment.