Fixed dialyzer warnings

This commit is contained in:
Maas-Maarten Zeeman
2022-05-28 22:42:03 +02:00
parent 887e91b1de
commit 1d9e9ee696
3 changed files with 25 additions and 11 deletions

View File

@@ -1009,7 +1009,7 @@ esqlite_interrupt(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
esqlite3 *db = (esqlite3 *) conn; esqlite3 *db = (esqlite3 *) conn;
if(db->db == NULL) { if(db->db == NULL) {
return make_error_tuple(env, "closed"); return make_atom(env, "ok");
} }
sqlite3_interrupt(db->db); sqlite3_interrupt(db->db);

View File

@@ -157,7 +157,7 @@ error_info(#esqlite3{db=Connection}) ->
%% @doc Interrupt a long running query. See [https://sqlite.org/c3ref/interrupt.html] for more details. %% @doc Interrupt a long running query. See [https://sqlite.org/c3ref/interrupt.html] for more details.
-spec interrupt(Connection) -> Result -spec interrupt(Connection) -> Result
when Connection :: esqlite3(), when Connection :: esqlite3(),
Result:: ok | {error, _}. Result:: ok.
interrupt(#esqlite3{db=Db}) -> interrupt(#esqlite3{db=Db}) ->
esqlite3_nif:interrupt(Db). esqlite3_nif:interrupt(Db).
@@ -170,9 +170,12 @@ interrupt(#esqlite3{db=Db}) ->
%% ```{update, binary(), binary(), rowid()}''' %% ```{update, binary(), binary(), rowid()}'''
%% When a row has been updated. %% When a row has been updated.
%% %%
-spec set_update_hook(esqlite3(), pid() | undefined) -> ok | {error, term()}. -spec set_update_hook(Connection, Pid) -> Result when
set_update_hook(#esqlite3{db=Connection}, MaybePid) when is_pid(MaybePid) orelse MaybePid =:= undefined -> Connection :: esqlite3(),
esqlite3_nif:set_update_hook(Connection, MaybePid). Pid :: pid(),
Result :: ok | {error, closed}.
set_update_hook(#esqlite3{db=Connection}, Pid) ->
esqlite3_nif:set_update_hook(Connection, Pid).
%%% %%%
%%% q %%% q
@@ -217,6 +220,10 @@ q(Connection, Sql, Args) ->
%% fetchall %% fetchall
%% %%
% @doc Fetch all rows from the prepared statement.
-spec fetchall(Statement) -> Result when
Statement :: esqlite3_stmt(),
Result :: list(row()) | {error, _}.
fetchall(Statement) -> fetchall(Statement) ->
fetchall1(Statement, []). fetchall1(Statement, []).
@@ -295,16 +302,23 @@ prepare(#esqlite3{db=Connection}, Sql, PrepareFlags) ->
Error Error
end. end.
%% @doc Bind an array of values to a prepared statement %% @doc Bind an array of values as parameters of a prepared statement
%% -spec bind(Statement, Args) -> Result when
Statement :: esqlite3_stmt(),
Args :: list(),
Result :: ok | {error, _}.
bind(#esqlite3_stmt{}=Statement, Args) when is_list(Args) -> bind(#esqlite3_stmt{}=Statement, Args) when is_list(Args) ->
bind1(Statement, 1, Args). bind1(Statement, 1, Args).
bind1(_Statement, _Column, []) -> bind1(_Statement, _Column, []) ->
ok; ok;
bind1(Statement, Column, [Arg | Args]) -> bind1(Statement, Column, [Arg | Args]) ->
bind_arg(Statement, Column, Arg), case bind_arg(Statement, Column, Arg) of
bind1(Statement, Column + 1, Args). ok ->
bind1(Statement, Column + 1, Args);
{error, _}=Error ->
Error
end.
% Bind with automatic tyoe conversion % Bind with automatic tyoe conversion
bind_arg(Statement, Column, undefined) -> bind_arg(Statement, Column, undefined) ->
@@ -382,7 +396,7 @@ bind_null(#esqlite3_stmt{stmt=Stmt}, Index) ->
-spec step(Statement) -> StepResult -spec step(Statement) -> StepResult
when Statement :: esqlite3_stmt(), when Statement :: esqlite3_stmt(),
StepResult:: ok | {error, _}. StepResult:: row() | '$done' | {error, _}.
step(#esqlite3_stmt{stmt=Stmt}) -> step(#esqlite3_stmt{stmt=Stmt}) ->
esqlite3_nif:step(Stmt). esqlite3_nif:step(Stmt).

View File

@@ -106,7 +106,7 @@ error_info(_Db) ->
-spec set_update_hook(Connection, Pid) -> Result -spec set_update_hook(Connection, Pid) -> Result
when Connection :: esqlite3(), when Connection :: esqlite3(),
Pid :: pid(), Pid :: pid(),
Result :: ok | {error, _}. Result :: ok | {error, closed}.
set_update_hook(_Db, _Pid) -> set_update_hook(_Db, _Pid) ->
erlang:nif_error(nif_library_not_loaded). erlang:nif_error(nif_library_not_loaded).