Skip to content

Commit e1e2686

Browse files
committed
Initial commit
0 parents  commit e1e2686

File tree

12 files changed

+1433
-0
lines changed

12 files changed

+1433
-0
lines changed

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.rebar3
2+
_*
3+
.eunit
4+
*.o
5+
*.beam
6+
*.plt
7+
*.swp
8+
*.swo
9+
.erlang.cookie
10+
ebin
11+
log
12+
erl_crash.dump
13+
.rebar
14+
logs
15+
_build
16+
.idea
17+
*.iml
18+
rebar3.crashdump
19+
*~

LICENSE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Copyright (c) 2019-2021 Maxim Fedorov <[email protected]>
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
* Neither the name of the copyright holder nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
19+
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20+
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
26+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# sqlite
2+
sqlite3 NIF implementation.
3+
4+
## Not implemented
5+
* Types mapping
6+
* Thread safety of "connection" and "statement" objects
7+
* Yielding and dirty NIFs
8+
* Online Backup support
9+
* Snapshot support
10+
* Commit and Rollback hooks support
11+
* Memory leaks tests
12+
13+
## Build
14+
-----
15+
16+
$ rebar3 compile
17+
18+
## Erlang to sqlite data type mapping
19+
Following primitive types in Erlang are mapped to corresponding sqlite types:
20+
* binary() <-> sqlite3 blob
21+
* string() <-> sqlite3 text
22+
* integer() <-> integer
23+
* float() <-> float
24+
* undefined <-> null
25+
26+
## TODO
27+
Before 1.0 release, following features must be explored:
28+
* memory allocators done through BEAM (for accounting purposes)
29+
* directories (data and temp directory settings)
30+
* mutex methods (for lock counting purposes)
31+
* better testing for extended error information (not just badarg)
32+
33+
## Failing to load
34+
35+
If the NIF fails with "Library load-call unsuccessful":
36+
* -1 sqlite3 was not built with thread safety turned on
37+
* -2 connection resource creation was unsuccessful
38+
* -3 statement resource creation failed

c_src/Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Based on c_src.mk from erlang.mk by Loic Hoguin <[email protected]>
2+
3+
CURDIR := $(shell pwd)
4+
BASEDIR := $(abspath $(CURDIR)/..)
5+
6+
PROJECT ?= $(notdir $(BASEDIR))
7+
PROJECT := $(strip $(PROJECT))
8+
9+
ERTS_INCLUDE_DIR ?= $(shell erl -noshell -eval "io:format(\"~ts/erts-~ts/include/\", [code:root_dir(), erlang:system_info(version)])." -s init stop)
10+
ERL_INTERFACE_INCLUDE_DIR ?= $(shell erl -noshell -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, include)])." -s init stop)
11+
ERL_INTERFACE_LIB_DIR ?= $(shell erl -noshell -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, lib)])." -s init stop)
12+
13+
C_SRC_DIR = $(CURDIR)
14+
C_SRC_OUTPUT ?= $(CURDIR)/../priv/$(PROJECT).so
15+
16+
# System type and C compiler/flags.
17+
18+
UNAME_SYS := $(shell uname -s)
19+
ifeq ($(UNAME_SYS), Darwin)
20+
CC ?= cc
21+
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
22+
CXXFLAGS ?= -O3 -finline-functions -Wall
23+
LDFLAGS ?= -flat_namespace -undefined suppress
24+
else ifeq ($(UNAME_SYS), FreeBSD)
25+
CC ?= cc
26+
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
27+
CXXFLAGS ?= -O3 -finline-functions -Wall
28+
else ifeq ($(UNAME_SYS), Linux)
29+
CC ?= gcc
30+
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
31+
CXXFLAGS ?= -O3 -finline-functions -Wall
32+
endif
33+
34+
CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
35+
CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
36+
37+
LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lei -lsqlite3
38+
LDFLAGS += -shared
39+
40+
# Verbosity.
41+
42+
c_verbose_0 = @echo " C " $(?F);
43+
c_verbose = $(c_verbose_$(V))
44+
45+
cpp_verbose_0 = @echo " CPP " $(?F);
46+
cpp_verbose = $(cpp_verbose_$(V))
47+
48+
link_verbose_0 = @echo " LD " $(@F);
49+
link_verbose = $(link_verbose_$(V))
50+
51+
SOURCES := $(shell find $(C_SRC_DIR) -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.cpp" \))
52+
OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
53+
54+
COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
55+
COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
56+
57+
$(C_SRC_OUTPUT): $(OBJECTS)
58+
@mkdir -p $(BASEDIR)/priv/
59+
$(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT)
60+
61+
%.o: %.c
62+
$(COMPILE_C) $(OUTPUT_OPTION) $<
63+
64+
%.o: %.cc
65+
$(COMPILE_CPP) $(OUTPUT_OPTION) $<
66+
67+
%.o: %.C
68+
$(COMPILE_CPP) $(OUTPUT_OPTION) $<
69+
70+
%.o: %.cpp
71+
$(COMPILE_CPP) $(OUTPUT_OPTION) $<
72+
73+
clean:
74+
@rm -f $(C_SRC_OUTPUT) $(OBJECTS)

0 commit comments

Comments
 (0)