Skip to content

Commit 9ad7bca

Browse files
committed
Cleaned up new open flag implementation
1 parent c0aa6ce commit 9ad7bca

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

src/sqlite3.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,12 @@ module Cache = struct
156156
end
157157

158158
external db_open :
159-
mode : Mode.t -> uri : bool -> memory : bool -> mutex : Mut.t -> cache : Cache.t ->
160-
?vfs : string -> string -> db = "caml_sqlite3_open_bytecode" "caml_sqlite3_open_native"
159+
mode : Mode.t -> uri : bool -> memory : bool ->
160+
mutex : Mut.t -> cache : Cache.t ->
161+
?vfs : string -> string -> db
162+
= "caml_sqlite3_open_bc" "caml_sqlite3_open"
161163

162-
let db_open ?mode ?(uri=false) ?(memory=false) ?mutex ?cache ?vfs name =
164+
let db_open ?mode ?(uri = false) ?(memory = false) ?mutex ?cache ?vfs name =
163165
let mode = Mode.lift mode in
164166
let mutex = Mut.lift mutex in
165167
let cache = Cache.lift cache in

src/sqlite3.mli

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ val db_open :
166166
?vfs : string ->
167167
string ->
168168
db
169-
(** [db_open ?mode ?mutex ?cache ?vfs filename] opens the database file
170-
[filename], and returns a database handle.
169+
(** [db_open ?mode ?uri ?memory ?mutex ?cache ?vfs filename] opens the
170+
database file [filename], and returns a database handle.
171171
172172
Special filenames: ":memory:" and "" open an in-memory or temporary
173173
database respectively.
@@ -179,7 +179,7 @@ val db_open :
179179
non-default value. The database is opened read-only if [`READONLY] is
180180
passed as mode. The database file will not be created if it is missing and
181181
[`NO_CREATE] is set. The [uri] parameter enables URI filename
182-
interepretation and corresponds to [SQLITE_OPEN_URI] in the SQLite3 API.
182+
interpretation and corresponds to [SQLITE_OPEN_URI] in the SQLite3 API.
183183
The [memory] parameter opens an in-memory database and corresponds to
184184
[SQLITE_OPEN_MEMORY] in the SQLite3 API. [mutex] determines how the
185185
database is accessed. The mutex parameters [`NO] and [`FULL] correspond to

src/sqlite3_stubs.c

+18-12
Original file line numberDiff line numberDiff line change
@@ -378,20 +378,17 @@ static struct custom_operations db_wrap_ops = {
378378
};
379379

380380
#ifdef SQLITE_HAS_OPEN_V2
381-
static inline int get_open_flags(value v_mode, value v_uri, value v_memory, value v_mutex, value v_cache)
381+
static inline int get_open_flags(
382+
value v_mode, value v_uri, value v_memory, value v_mutex, value v_cache)
382383
{
383384
int flags;
384385
switch (Int_val(v_mode)) {
385386
case 0 : flags = (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); break;
386387
case 1 : flags = SQLITE_OPEN_READWRITE; break;
387388
default : flags = SQLITE_OPEN_READONLY; break;
388389
}
389-
if (Bool_val(v_uri)) {
390-
flags |= SQLITE_OPEN_URI;
391-
}
392-
if (Bool_val(v_memory)) {
393-
flags |= SQLITE_OPEN_MEMORY;
394-
}
390+
if (Bool_val(v_uri)) flags |= SQLITE_OPEN_URI;
391+
if (Bool_val(v_memory)) flags |= SQLITE_OPEN_MEMORY;
395392
switch (Int_val(v_mutex)) {
396393
case 0 : break;
397394
#ifdef SQLITE_HAS_OPEN_MUTEX_PARAMS
@@ -418,8 +415,9 @@ static inline int get_open_flags(value v_mode, value v_uri, value v_memory, valu
418415
}
419416
#endif
420417

421-
CAMLprim value caml_sqlite3_open_native(
422-
value v_mode, value v_uri, value v_memory, value v_mutex, value v_cache, value v_vfs_opt, value v_file)
418+
CAMLprim value caml_sqlite3_open(
419+
value v_mode, value v_uri, value v_memory,
420+
value v_mutex, value v_cache, value v_vfs_opt, value v_file)
423421
{
424422
sqlite3 *db;
425423
int res;
@@ -439,7 +437,13 @@ CAMLprim value caml_sqlite3_open_native(
439437
memcpy(vfs, String_val(v_vfs), vfs_len);
440438
}
441439
#else
442-
if (Int_val(v_mode) || Bool_val(v_uri) || Bool_val(v_memory) || Int_val(v_mutex) || Int_val(v_cache))
440+
if (
441+
Int_val(v_mode) ||
442+
Bool_val(v_uri) ||
443+
Bool_val(v_memory) ||
444+
Int_val(v_mutex) ||
445+
Int_val(v_cache)
446+
)
443447
caml_failwith("SQLite3 version < 3.5 does not support open flags");
444448
if (v_vfs_opt != Val_None)
445449
caml_failwith("SQLite3 version < 3.5 does not support VFS modules");
@@ -482,9 +486,11 @@ CAMLprim value caml_sqlite3_open_native(
482486
}
483487
}
484488

485-
CAMLprim value caml_sqlite3_open_bytecode(value *argv, int argn)
489+
CAMLprim value caml_sqlite3_open_bc(value *argv, int argn)
486490
{
487-
return caml_sqlite3_open_native(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
491+
return
492+
caml_sqlite3_open(
493+
argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
488494
}
489495

490496
CAMLprim value caml_sqlite3_close(value v_db)

0 commit comments

Comments
 (0)