Merge pull request #28 from project-fifo/master
rebar3 and SmartOS compatibility
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@ priv
|
||||
*.o
|
||||
*~
|
||||
_build
|
||||
c_src/*.d
|
||||
|
||||
10
rebar.config
10
rebar.config
@@ -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
1
rebar.lock
Normal file
@@ -0,0 +1 @@
|
||||
[].
|
||||
@@ -1,7 +1,7 @@
|
||||
{application, esqlite,
|
||||
[
|
||||
{description, "sqlite nif interface"},
|
||||
{vsn, "1"},
|
||||
{vsn, "0.1.1"},
|
||||
{modules, [esqlite3, esqlite3_nif]},
|
||||
{registered, []},
|
||||
{applications, [
|
||||
|
||||
@@ -47,14 +47,14 @@
|
||||
%% @doc Opens a sqlite3 database mentioned in Filename.
|
||||
%%
|
||||
-spec open(FileName) -> {ok, connection()} | {error, _} when
|
||||
FileName :: string().
|
||||
FileName :: string().
|
||||
open(Filename) ->
|
||||
open(Filename, ?DEFAULT_TIMEOUT).
|
||||
|
||||
%% @doc Open a database connection
|
||||
%%
|
||||
-spec open(Filename, timeout()) -> {ok, connection()} | {error, _} when
|
||||
Filename :: string().
|
||||
Filename :: string().
|
||||
open(Filename, Timeout) ->
|
||||
{ok, Connection} = esqlite3_nif:start(),
|
||||
|
||||
@@ -92,10 +92,10 @@ q(Sql, Args, Connection) ->
|
||||
|
||||
%% @doc
|
||||
-spec map(F, sql(), connection()) -> list(Type) when
|
||||
F :: fun((Row) -> Type) | fun((ColumnNames, Row) -> Type),
|
||||
Row :: tuple(),
|
||||
ColumnNames :: tuple(),
|
||||
Type :: any().
|
||||
F :: fun((Row) -> Type) | fun((ColumnNames, Row) -> Type),
|
||||
Row :: tuple(),
|
||||
ColumnNames :: tuple(),
|
||||
Type :: any().
|
||||
map(F, Sql, Connection) ->
|
||||
case prepare(Sql, Connection) of
|
||||
{ok, Statement} ->
|
||||
@@ -106,9 +106,9 @@ map(F, Sql, Connection) ->
|
||||
|
||||
%% @doc
|
||||
-spec foreach(F, sql(), connection()) -> ok when
|
||||
F :: fun((Row) -> any()) | fun((ColumnNames, Row) -> any()),
|
||||
Row :: tuple(),
|
||||
ColumnNames :: tuple().
|
||||
F :: fun((Row) -> any()) | fun((ColumnNames, Row) -> any()),
|
||||
Row :: tuple(),
|
||||
ColumnNames :: tuple().
|
||||
foreach(F, Sql, Connection) ->
|
||||
case prepare(Sql, Connection) of
|
||||
{ok, Statement} ->
|
||||
@@ -119,9 +119,9 @@ foreach(F, Sql, Connection) ->
|
||||
|
||||
%%
|
||||
-spec foreach_s(F, statement()) -> ok when
|
||||
F :: fun((Row) -> any()) | fun((ColumnNames, Row) -> any()),
|
||||
Row :: tuple(),
|
||||
ColumnNames :: tuple().
|
||||
F :: fun((Row) -> any()) | fun((ColumnNames, Row) -> any()),
|
||||
Row :: tuple(),
|
||||
ColumnNames :: tuple().
|
||||
foreach_s(F, Statement) when is_function(F, 1) ->
|
||||
case try_step(Statement, 0) of
|
||||
'$done' -> ok;
|
||||
@@ -142,10 +142,10 @@ foreach_s(F, Statement) when is_function(F, 2) ->
|
||||
|
||||
%%
|
||||
-spec map_s(F, statement()) -> list(Type) when
|
||||
F :: fun((Row) -> Type) | fun((ColumnNames, Row) -> Type),
|
||||
Row :: tuple(),
|
||||
ColumnNames :: tuple(),
|
||||
Type :: term().
|
||||
F :: fun((Row) -> Type) | fun((ColumnNames, Row) -> Type),
|
||||
Row :: tuple(),
|
||||
ColumnNames :: tuple(),
|
||||
Type :: term().
|
||||
map_s(F, Statement) when is_function(F, 1) ->
|
||||
case try_step(Statement, 0) of
|
||||
'$done' -> [];
|
||||
@@ -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()),
|
||||
@@ -345,10 +353,10 @@ receive_answer(Ref, Timeout) ->
|
||||
error_logger:warning_msg("Esqlite3: Ignoring stale answer ~p~n", [StaleAnswer]),
|
||||
PassedMics = timer:now_diff(os:timestamp(), Start) div 1000,
|
||||
NewTimeout = case Timeout - PassedMics of
|
||||
Passed when Passed < 0 -> 0;
|
||||
TO -> TO
|
||||
end,
|
||||
Passed when Passed < 0 -> 0;
|
||||
TO -> TO
|
||||
end,
|
||||
receive_answer(Ref, NewTimeout)
|
||||
after Timeout ->
|
||||
throw({error, timeout, Ref})
|
||||
throw({error, timeout, Ref})
|
||||
end.
|
||||
|
||||
@@ -22,19 +22,19 @@
|
||||
|
||||
%% low-level exports
|
||||
-export([start/0,
|
||||
open/4,
|
||||
exec/4,
|
||||
changes/3,
|
||||
insert/4,
|
||||
prepare/4,
|
||||
step/3,
|
||||
reset/3,
|
||||
finalize/3,
|
||||
bind/4,
|
||||
column_names/3,
|
||||
column_types/3,
|
||||
close/3
|
||||
]).
|
||||
open/4,
|
||||
exec/4,
|
||||
changes/3,
|
||||
insert/4,
|
||||
prepare/4,
|
||||
step/3,
|
||||
reset/3,
|
||||
finalize/3,
|
||||
bind/4,
|
||||
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).
|
||||
|
||||
Reference in New Issue
Block a user