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
|
*.o
|
||||||
*~
|
*~
|
||||||
_build
|
_build
|
||||||
|
c_src/*.d
|
||||||
|
|||||||
10
rebar.config
10
rebar.config
@@ -4,8 +4,18 @@
|
|||||||
{"darwin", "DRV_LDFLAGS",
|
{"darwin", "DRV_LDFLAGS",
|
||||||
"-flat_namespace -undefined suppress $ERL_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"}
|
{"CFLAGS", "$CFLAGS -DSQLITE_THREADSAFE=1 -DSQLITE_USE_URI -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS"}
|
||||||
]}.
|
]}.
|
||||||
{port_specs, [
|
{port_specs, [
|
||||||
{"priv/esqlite3_nif.so", ["c_src/esqlite3_nif.c", "c_src/queue.c", "c_src/sqlite3.c"]}
|
{"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,
|
{application, esqlite,
|
||||||
[
|
[
|
||||||
{description, "sqlite nif interface"},
|
{description, "sqlite nif interface"},
|
||||||
{vsn, "1"},
|
{vsn, "0.1.1"},
|
||||||
{modules, [esqlite3, esqlite3_nif]},
|
{modules, [esqlite3, esqlite3_nif]},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications, [
|
{applications, [
|
||||||
|
|||||||
@@ -47,14 +47,14 @@
|
|||||||
%% @doc Opens a sqlite3 database mentioned in Filename.
|
%% @doc Opens a sqlite3 database mentioned in Filename.
|
||||||
%%
|
%%
|
||||||
-spec open(FileName) -> {ok, connection()} | {error, _} when
|
-spec open(FileName) -> {ok, connection()} | {error, _} when
|
||||||
FileName :: string().
|
FileName :: string().
|
||||||
open(Filename) ->
|
open(Filename) ->
|
||||||
open(Filename, ?DEFAULT_TIMEOUT).
|
open(Filename, ?DEFAULT_TIMEOUT).
|
||||||
|
|
||||||
%% @doc Open a database connection
|
%% @doc Open a database connection
|
||||||
%%
|
%%
|
||||||
-spec open(Filename, timeout()) -> {ok, connection()} | {error, _} when
|
-spec open(Filename, timeout()) -> {ok, connection()} | {error, _} when
|
||||||
Filename :: string().
|
Filename :: string().
|
||||||
open(Filename, Timeout) ->
|
open(Filename, Timeout) ->
|
||||||
{ok, Connection} = esqlite3_nif:start(),
|
{ok, Connection} = esqlite3_nif:start(),
|
||||||
|
|
||||||
@@ -92,10 +92,10 @@ q(Sql, Args, Connection) ->
|
|||||||
|
|
||||||
%% @doc
|
%% @doc
|
||||||
-spec map(F, sql(), connection()) -> list(Type) when
|
-spec map(F, sql(), connection()) -> list(Type) when
|
||||||
F :: fun((Row) -> Type) | fun((ColumnNames, Row) -> Type),
|
F :: fun((Row) -> Type) | fun((ColumnNames, Row) -> Type),
|
||||||
Row :: tuple(),
|
Row :: tuple(),
|
||||||
ColumnNames :: tuple(),
|
ColumnNames :: tuple(),
|
||||||
Type :: any().
|
Type :: any().
|
||||||
map(F, Sql, Connection) ->
|
map(F, Sql, Connection) ->
|
||||||
case prepare(Sql, Connection) of
|
case prepare(Sql, Connection) of
|
||||||
{ok, Statement} ->
|
{ok, Statement} ->
|
||||||
@@ -106,9 +106,9 @@ map(F, Sql, Connection) ->
|
|||||||
|
|
||||||
%% @doc
|
%% @doc
|
||||||
-spec foreach(F, sql(), connection()) -> ok when
|
-spec foreach(F, sql(), connection()) -> ok when
|
||||||
F :: fun((Row) -> any()) | fun((ColumnNames, Row) -> any()),
|
F :: fun((Row) -> any()) | fun((ColumnNames, Row) -> any()),
|
||||||
Row :: tuple(),
|
Row :: tuple(),
|
||||||
ColumnNames :: tuple().
|
ColumnNames :: tuple().
|
||||||
foreach(F, Sql, Connection) ->
|
foreach(F, Sql, Connection) ->
|
||||||
case prepare(Sql, Connection) of
|
case prepare(Sql, Connection) of
|
||||||
{ok, Statement} ->
|
{ok, Statement} ->
|
||||||
@@ -119,9 +119,9 @@ foreach(F, Sql, Connection) ->
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
-spec foreach_s(F, statement()) -> ok when
|
-spec foreach_s(F, statement()) -> ok when
|
||||||
F :: fun((Row) -> any()) | fun((ColumnNames, Row) -> any()),
|
F :: fun((Row) -> any()) | fun((ColumnNames, Row) -> any()),
|
||||||
Row :: tuple(),
|
Row :: tuple(),
|
||||||
ColumnNames :: tuple().
|
ColumnNames :: tuple().
|
||||||
foreach_s(F, Statement) when is_function(F, 1) ->
|
foreach_s(F, Statement) when is_function(F, 1) ->
|
||||||
case try_step(Statement, 0) of
|
case try_step(Statement, 0) of
|
||||||
'$done' -> ok;
|
'$done' -> ok;
|
||||||
@@ -142,10 +142,10 @@ foreach_s(F, Statement) when is_function(F, 2) ->
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
-spec map_s(F, statement()) -> list(Type) when
|
-spec map_s(F, statement()) -> list(Type) when
|
||||||
F :: fun((Row) -> Type) | fun((ColumnNames, Row) -> Type),
|
F :: fun((Row) -> Type) | fun((ColumnNames, Row) -> Type),
|
||||||
Row :: tuple(),
|
Row :: tuple(),
|
||||||
ColumnNames :: tuple(),
|
ColumnNames :: tuple(),
|
||||||
Type :: term().
|
Type :: term().
|
||||||
map_s(F, Statement) when is_function(F, 1) ->
|
map_s(F, Statement) when is_function(F, 1) ->
|
||||||
case try_step(Statement, 0) of
|
case try_step(Statement, 0) of
|
||||||
'$done' -> [];
|
'$done' -> [];
|
||||||
@@ -172,18 +172,25 @@ fetchone(Statement) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
%%
|
%%
|
||||||
-spec fetchall(statement()) -> list(tuple()).
|
-spec fetchall(statement()) ->
|
||||||
|
list(tuple()) |
|
||||||
|
{error, term()}.
|
||||||
fetchall(Statement) ->
|
fetchall(Statement) ->
|
||||||
case try_step(Statement, 0) of
|
case try_step(Statement, 0) of
|
||||||
'$done' ->
|
'$done' ->
|
||||||
[];
|
[];
|
||||||
{error, _} = E -> E;
|
{error, _} = E -> E;
|
||||||
{row, Row} ->
|
{row, Row} ->
|
||||||
[Row | fetchall(Statement)]
|
case fetchall(Statement) of
|
||||||
|
{error, _} = E -> E;
|
||||||
|
Rest -> [Row | Rest]
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Try the step, when the database is busy,
|
%% 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 ->
|
try_step(_Statement, Tries) when Tries > 5 ->
|
||||||
throw(too_many_tries);
|
throw(too_many_tries);
|
||||||
try_step(Statement, Tries) ->
|
try_step(Statement, Tries) ->
|
||||||
@@ -267,6 +274,7 @@ step(Stmt) ->
|
|||||||
%% @doc
|
%% @doc
|
||||||
%%
|
%%
|
||||||
%% @spec step(prepared_statement(), timeout()) -> tuple()
|
%% @spec step(prepared_statement(), timeout()) -> tuple()
|
||||||
|
-spec step(term(), timeout()) -> tuple() | '$busy' | '$done'.
|
||||||
step(Stmt, Timeout) ->
|
step(Stmt, Timeout) ->
|
||||||
Ref = make_ref(),
|
Ref = make_ref(),
|
||||||
ok = esqlite3_nif:step(Stmt, Ref, self()),
|
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]),
|
error_logger:warning_msg("Esqlite3: Ignoring stale answer ~p~n", [StaleAnswer]),
|
||||||
PassedMics = timer:now_diff(os:timestamp(), Start) div 1000,
|
PassedMics = timer:now_diff(os:timestamp(), Start) div 1000,
|
||||||
NewTimeout = case Timeout - PassedMics of
|
NewTimeout = case Timeout - PassedMics of
|
||||||
Passed when Passed < 0 -> 0;
|
Passed when Passed < 0 -> 0;
|
||||||
TO -> TO
|
TO -> TO
|
||||||
end,
|
end,
|
||||||
receive_answer(Ref, NewTimeout)
|
receive_answer(Ref, NewTimeout)
|
||||||
after Timeout ->
|
after Timeout ->
|
||||||
throw({error, timeout, Ref})
|
throw({error, timeout, Ref})
|
||||||
end.
|
end.
|
||||||
|
|||||||
@@ -22,19 +22,19 @@
|
|||||||
|
|
||||||
%% low-level exports
|
%% low-level exports
|
||||||
-export([start/0,
|
-export([start/0,
|
||||||
open/4,
|
open/4,
|
||||||
exec/4,
|
exec/4,
|
||||||
changes/3,
|
changes/3,
|
||||||
insert/4,
|
insert/4,
|
||||||
prepare/4,
|
prepare/4,
|
||||||
step/3,
|
step/3,
|
||||||
reset/3,
|
reset/3,
|
||||||
finalize/3,
|
finalize/3,
|
||||||
bind/4,
|
bind/4,
|
||||||
column_names/3,
|
column_names/3,
|
||||||
column_types/3,
|
column_types/3,
|
||||||
close/3
|
close/3
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-on_load(init/0).
|
-on_load(init/0).
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ init() ->
|
|||||||
%%
|
%%
|
||||||
%% @spec start() -> {ok, connection()} | {error, msg()}
|
%% @spec start() -> {ok, connection()} | {error, msg()}
|
||||||
start() ->
|
start() ->
|
||||||
exit(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
%% @doc Open the specified sqlite3 database.
|
%% @doc Open the specified sqlite3 database.
|
||||||
%%
|
%%
|
||||||
@@ -58,8 +58,9 @@ start() ->
|
|||||||
%% ok immediately. When the database is opened
|
%% ok immediately. When the database is opened
|
||||||
%%
|
%%
|
||||||
%% @spec open(connection(), reference(), pid(), string()) -> ok | {error, message()}
|
%% @spec open(connection(), reference(), pid(), string()) -> ok | {error, message()}
|
||||||
|
|
||||||
open(_Db, _Ref, _Dest, _Filename) ->
|
open(_Db, _Ref, _Dest, _Filename) ->
|
||||||
exit(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
%% @doc Exec the query.
|
%% @doc Exec the query.
|
||||||
%%
|
%%
|
||||||
@@ -71,7 +72,7 @@ open(_Db, _Ref, _Dest, _Filename) ->
|
|||||||
%%
|
%%
|
||||||
%% @spec exec(connection(), Ref::reference(), Dest::pid(), string()) -> ok | {error, message()}
|
%% @spec exec(connection(), Ref::reference(), Dest::pid(), string()) -> ok | {error, message()}
|
||||||
exec(_Db, _Ref, _Dest, _Sql) ->
|
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
|
%% @doc Get the number of affected rows of last statement
|
||||||
%%
|
%%
|
||||||
@@ -79,62 +80,59 @@ exec(_Db, _Ref, _Dest, _Sql) ->
|
|||||||
%% with answer() integer | {error, reason()}
|
%% with answer() integer | {error, reason()}
|
||||||
%%
|
%%
|
||||||
changes(_Db, _Ref, _Dest) ->
|
changes(_Db, _Ref, _Dest) ->
|
||||||
exit(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
%% @doc
|
%% @doc
|
||||||
%%
|
%%
|
||||||
%% @spec prepare(connection(), reference(), pid(), string()) -> ok | {error, message()}
|
%% @spec prepare(connection(), reference(), pid(), string()) -> ok | {error, message()}
|
||||||
prepare(_Db, _Ref, _Dest, _Sql) ->
|
prepare(_Db, _Ref, _Dest, _Sql) ->
|
||||||
exit(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
%% @doc
|
%% @doc
|
||||||
%%
|
%%
|
||||||
%% @spec step(statement(), reference(), pid()) -> ok | {error, message()}
|
%% @spec step(statement(), reference(), pid()) -> ok | {error, message()}
|
||||||
step(_Stmt, _Ref, _Dest) ->
|
step(_Stmt, _Ref, _Dest) ->
|
||||||
exit(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
%% @doc
|
%% @doc
|
||||||
%%
|
%%
|
||||||
%% @spec reset(statement(), reference(), pid()) -> ok | {error, message()}
|
%% @spec reset(statement(), reference(), pid()) -> ok | {error, message()}
|
||||||
reset(_Stmt, _Ref, _Dest) ->
|
reset(_Stmt, _Ref, _Dest) ->
|
||||||
exit(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
%% @doc
|
%% @doc
|
||||||
%%
|
%%
|
||||||
%%
|
%%
|
||||||
finalize(_Stmt, _Ref, _Dest) ->
|
finalize(_Stmt, _Ref, _Dest) ->
|
||||||
exit(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
%% @doc Bind parameters to a prepared statement.
|
%% @doc Bind parameters to a prepared statement.
|
||||||
%%
|
%%
|
||||||
%% @spec bind(statement(), reference(), pid(), []) -> ok | {error, message()}
|
%% @spec bind(statement(), reference(), pid(), []) -> ok | {error, message()}
|
||||||
bind(_Stmt, _Ref, _Dest, _Args) ->
|
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
|
%% @doc Retrieve the column names of the prepared statement
|
||||||
%%
|
%%
|
||||||
%% @spec column_names(statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
|
%% @spec column_names(statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
|
||||||
column_names(_Stmt, _Ref, _Dest) ->
|
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
|
%% @doc Retrieve the column types of the prepared statement
|
||||||
%%
|
%%
|
||||||
%% @spec column_types(statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
|
%% @spec column_types(statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
|
||||||
column_types(_Stmt, _Ref, _Dest) ->
|
column_types(_Stmt, _Ref, _Dest) ->
|
||||||
exit(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
%% @doc Close the connection.
|
%% @doc Close the connection.
|
||||||
%%
|
%%
|
||||||
%% @spec close(connection(), reference(), pid()) -> ok | {error, message()}
|
%% @spec close(connection(), reference(), pid()) -> ok | {error, message()}
|
||||||
close(_Db, _Ref, _Dest) ->
|
close(_Db, _Ref, _Dest) ->
|
||||||
exit(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
|
|
||||||
%% @doc Insert record
|
%% @doc Insert record
|
||||||
%%
|
%%
|
||||||
%% @spec insert(connection(), Ref::reference(), Dest::pid(), string()) -> {ok, integer()} | {error, message()}
|
%% @spec insert(connection(), Ref::reference(), Dest::pid(), string()) -> {ok, integer()} | {error, message()}
|
||||||
insert(_Db, _Ref, _Dest, _Sql) ->
|
insert(_Db, _Ref, _Dest, _Sql) ->
|
||||||
exit(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user