Merge pull request #28 from project-fifo/master

rebar3 and SmartOS compatibility
This commit is contained in:
Maas-Maarten Zeeman
2015-10-25 15:10:11 +01:00
6 changed files with 109 additions and 91 deletions

1
.gitignore vendored
View File

@@ -7,3 +7,4 @@ priv
*.o
*~
_build
c_src/*.d

View File

@@ -4,8 +4,18 @@
{"darwin", "DRV_LDFLAGS",
"-flat_namespace -undefined suppress $ERL_LDFLAGS"},
{"solaris", "CFLAGS",
"-std=c99"},
{"CFLAGS", "$CFLAGS -DSQLITE_THREADSAFE=1 -DSQLITE_USE_URI -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS"}
]}.
{port_specs, [
{"priv/esqlite3_nif.so", ["c_src/esqlite3_nif.c", "c_src/queue.c", "c_src/sqlite3.c"]}
]}.
{plugins, [pc]}.
{provider_hooks,
[{post,
[{compile, {pc, compile}},
{clean, {pc, clean}}]}]}.

1
rebar.lock Normal file
View File

@@ -0,0 +1 @@
[].

View File

@@ -1,7 +1,7 @@
{application, esqlite,
[
{description, "sqlite nif interface"},
{vsn, "1"},
{vsn, "0.1.1"},
{modules, [esqlite3, esqlite3_nif]},
{registered, []},
{applications, [

View File

@@ -172,18 +172,25 @@ fetchone(Statement) ->
end.
%%
-spec fetchall(statement()) -> list(tuple()).
-spec fetchall(statement()) ->
list(tuple()) |
{error, term()}.
fetchall(Statement) ->
case try_step(Statement, 0) of
'$done' ->
[];
{error, _} = E -> E;
{row, Row} ->
[Row | fetchall(Statement)]
case fetchall(Statement) of
{error, _} = E -> E;
Rest -> [Row | Rest]
end
end.
%% Try the step, when the database is busy,
-spec try_step(statement(), non_neg_integer()) -> term().
-spec try_step(statement(), non_neg_integer()) ->
'$done' |
term().
try_step(_Statement, Tries) when Tries > 5 ->
throw(too_many_tries);
try_step(Statement, Tries) ->
@@ -267,6 +274,7 @@ step(Stmt) ->
%% @doc
%%
%% @spec step(prepared_statement(), timeout()) -> tuple()
-spec step(term(), timeout()) -> tuple() | '$busy' | '$done'.
step(Stmt, Timeout) ->
Ref = make_ref(),
ok = esqlite3_nif:step(Stmt, Ref, self()),

View File

@@ -34,7 +34,7 @@
column_names/3,
column_types/3,
close/3
]).
]).
-on_load(init/0).
@@ -50,7 +50,7 @@ init() ->
%%
%% @spec start() -> {ok, connection()} | {error, msg()}
start() ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc Open the specified sqlite3 database.
%%
@@ -58,8 +58,9 @@ start() ->
%% ok immediately. When the database is opened
%%
%% @spec open(connection(), reference(), pid(), string()) -> ok | {error, message()}
open(_Db, _Ref, _Dest, _Filename) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc Exec the query.
%%
@@ -71,7 +72,7 @@ open(_Db, _Ref, _Dest, _Filename) ->
%%
%% @spec exec(connection(), Ref::reference(), Dest::pid(), string()) -> ok | {error, message()}
exec(_Db, _Ref, _Dest, _Sql) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc Get the number of affected rows of last statement
%%
@@ -79,62 +80,59 @@ exec(_Db, _Ref, _Dest, _Sql) ->
%% with answer() integer | {error, reason()}
%%
changes(_Db, _Ref, _Dest) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc
%%
%% @spec prepare(connection(), reference(), pid(), string()) -> ok | {error, message()}
prepare(_Db, _Ref, _Dest, _Sql) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc
%%
%% @spec step(statement(), reference(), pid()) -> ok | {error, message()}
step(_Stmt, _Ref, _Dest) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc
%%
%% @spec reset(statement(), reference(), pid()) -> ok | {error, message()}
reset(_Stmt, _Ref, _Dest) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc
%%
%%
finalize(_Stmt, _Ref, _Dest) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc Bind parameters to a prepared statement.
%%
%% @spec bind(statement(), reference(), pid(), []) -> ok | {error, message()}
bind(_Stmt, _Ref, _Dest, _Args) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc Retrieve the column names of the prepared statement
%%
%% @spec column_names(statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
column_names(_Stmt, _Ref, _Dest) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc Retrieve the column types of the prepared statement
%%
%% @spec column_types(statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
column_types(_Stmt, _Ref, _Dest) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc Close the connection.
%%
%% @spec close(connection(), reference(), pid()) -> ok | {error, message()}
close(_Db, _Ref, _Dest) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).
%% @doc Insert record
%%
%% @spec insert(connection(), Ref::reference(), Dest::pid(), string()) -> {ok, integer()} | {error, message()}
insert(_Db, _Ref, _Dest, _Sql) ->
exit(nif_library_not_loaded).
erlang:nif_error(nif_library_not_loaded).