Skip to content

Commit 671c311

Browse files
committedJun 3, 2012
Add Sqlite_str module
Implements the REGEX SQL operator using OCaml's Str module for regexps.
1 parent 0bcbc15 commit 671c311

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed
 

‎Makefile

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
include config.make
22

3+
SRC_ML = sqlite3.ml sqlite3_big.ml sqlite3_str.ml
4+
SRC_C = ocaml-sqlite3.c ocaml-sqlite3-big.c
5+
6+
OBJ = $(SRC_ML:%.ml=%.cmo) $(SRC_ML:%.ml=%.cmx) $(SRC_C:%.c=%.o)
7+
38
CPPFLAGS += $(SQLITE_CFLAGS)
49

510
lib : sqlite3.cma
611

7-
sqlite3.cma : sqlite3.cmo sqlite3.cmx sqlite3_big.cmo sqlite3_big.cmx ocaml-sqlite3.o ocaml-sqlite3-big.o
12+
sqlite3.cma : $(OBJ)
813
ifeq ($(STATIC), yes)
914
$(OCAMLMKLIB) -v -custom -o sqlite3 -oc mlsqlite3 -cclib "$(SQLITE_LIBS)" $^
1015
else
@@ -16,6 +21,9 @@ sqlite3.cmx : sqlite3.cmi
1621
sqlite3_big.cmo : sqlite3_big.cmi
1722
sqlite3_big.cmx : sqlite3_big.cmi
1823
sqlite3_big.cmi : sqlite3.cmi
24+
sqlite3_str.cmo : sqlite3_str.cmi
25+
sqlite3_str.cmx : sqlite3_str.cmi
26+
sqlite3_str.cmi : sqlite3.cmi
1927

2028
ocaml-sqlite3.o : ocaml-sqlite3.h
2129
ocaml-sqlite3-big.o : ocaml-sqlite3.h
@@ -32,8 +40,8 @@ ocaml-sqlite3-big.o : ocaml-sqlite3.h
3240
META : META.in
3341
sed 's/@VERSION@/$(VERSION)/' $< > $@
3442

35-
INSTALL_FILES = META sqlite3.{cmi,mli,cmx} sqlite3_big.{cmi,mli,cmx} sqlite3.{cma,cmxa,a} libmlsqlite3.a $(if $(STATIC),,dllmlsqlite3.so)
36-
DIST_FILES = README META META.in Makefile ocaml-sqlite3.c ocaml-sqlite3-big.c ocaml-sqlite3.h sqlite3.ml sqlite3.mli sqlite3_big.ml sqlite3_big.mli configure configure.ac acinclude.m4 aclocal.m4 config.h.in config.make.in doc
43+
INSTALL_FILES = META sqlite3{,_big,_str}.{cmi,mli,cmx} sqlite3.{cma,cmxa,a} ocaml-sqlite3.h libmlsqlite3.a $(if $(STATIC),,dllmlsqlite3.so)
44+
DIST_FILES = README META META.in Makefile ocaml-sqlite3.h $(SRC_C) $(SRC_ML) $(SRC_ML:%.ml=%.mli) configure configure.ac acinclude.m4 aclocal.m4 config.h.in config.make.in doc
3745

3846
dist : ../$(TARNAME)-$(VERSION).tar.gz
3947
../$(TARNAME)-$(VERSION).tar.gz : $(DIST_FILES)
@@ -43,9 +51,9 @@ dist : ../$(TARNAME)-$(VERSION).tar.gz
4351
tar zcvf $(TARNAME)-$(VERSION).tar.gz $(addprefix $(TARNAME)-$(VERSION)/,$(DIST_FILES)) ; \
4452
mv $(TARNAME)-$(VERSION) $$dir
4553

46-
doc : sqlite3_big.cmi sqlite3.cmi
54+
doc : sqlite3.cmi sqlite3_big.cmi sqlite3_str.cmi
4755
mkdir -p doc
48-
ocamldoc -v -html -d doc -t "$(NAME) $(VERSION)" sqlite3.mli sqlite3_big.mli
56+
ocamldoc -v -html -d doc -t "$(NAME) $(VERSION)" sqlite3.mli sqlite3_big.mli sqlite_str.mli
4957

5058
install : lib META
5159
$(OCAMLFIND) install $(TARNAME) $(INSTALL_FILES)

‎sqlite3_str.ml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
let sql_value_of_bool b =
3+
if b then `INT 1 else `INT 0
4+
5+
let sqlite_regexp arg_p arg_t =
6+
let p = Sqlite3.value_text arg_p in
7+
let t = Sqlite3.value_text arg_t in
8+
sql_value_of_bool
9+
(Str.string_match
10+
(Str.regexp p) t 0)
11+
12+
let register db =
13+
Sqlite3.create_fun_2 db "regexp" sqlite_regexp
14+
15+
let unregister db =
16+
Sqlite3.delete_function db "regexp"

‎sqlite3_str.mli

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(** Implement the [REGEXP] SQL operator using OCaml [Str] module *)
2+
3+
val register : Sqlite3.db -> unit
4+
val unregister : Sqlite3.db -> unit

0 commit comments

Comments
 (0)