Improved accuracy of the returned error tuples. Made closed error tuple an exception

This commit is contained in:
Maas-Maarten Zeeman
2022-05-29 13:36:50 +02:00
parent e098dc1ca4
commit bd98ad8030
2 changed files with 47 additions and 16 deletions

View File

@@ -269,7 +269,7 @@ get_autocommit(#esqlite3{db=Connection}) ->
-spec exec(Connection, Sql) -> ExecResult
when Connection :: esqlite3(),
Sql :: sql(),
ExecResult :: ok | {error, _}.
ExecResult :: ok | esqlite3_nif:error().
exec(#esqlite3{db=Connection}, Sql) ->
esqlite3_nif:exec(Connection, Sql).
@@ -283,7 +283,7 @@ exec(#esqlite3{db=Connection}, Sql) ->
-spec prepare(Connection, Sql) -> PrepareResult
when Connection :: esqlite3(),
Sql :: sql(),
PrepareResult :: {ok, esqlite3_stmt()} | {error, _}.
PrepareResult :: {ok, esqlite3_stmt()} | esqlite3_nif:error().
prepare(Connection, Sql) ->
prepare(Connection, Sql, []).
@@ -351,15 +351,15 @@ bind_arg(Statement, Column, {blob, Value}) ->
Statement :: esqlite3_stmt(),
Index :: integer(),
Value :: integer(),
BindResult :: ok | {error, _}.
BindResult :: ok | esqlite3_nif:error().
bind_int(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
esqlite3_nif:bind_int(Stmt, Index, Value).
-spec bind_int64(Statement, Index, Value) -> BindResult when
Statement :: esqlite3_stmt(),
Index :: integer(),
Index :: non_neg_integer(),
Value :: integer(),
BindResult :: ok | {error, _}.
BindResult :: ok | esqlite3_nif:error().
bind_int64(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
esqlite3_nif:bind_int64(Stmt, Index, Value).
@@ -367,7 +367,7 @@ bind_int64(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
when Statement :: esqlite3_stmt(),
Index :: integer(),
Value :: float(),
BindResult :: ok | {error, _}.
BindResult :: ok | esqlite3_nif:error().
bind_double(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
esqlite3_nif:bind_double(Stmt, Index, Value).
@@ -375,7 +375,7 @@ bind_double(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
when Statement :: esqlite3_stmt(),
Index :: integer(),
Value :: iodata(),
BindResult :: ok | {error, _}.
BindResult :: ok | esqlite3_nif:error().
bind_text(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
esqlite3_nif:bind_text(Stmt, Index, Value).
@@ -383,14 +383,14 @@ bind_text(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
when Statement :: esqlite3_stmt(),
Index :: integer(),
Value :: iodata(),
BindResult :: ok | {error, _}.
BindResult :: ok | esqlite3_nif:error().
bind_blob(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
esqlite3_nif:bind_blob(Stmt, Index, Value).
-spec bind_null(Statement, Index) -> BindResult
when Statement :: esqlite3_stmt(),
Index :: integer(),
BindResult :: ok | {error, _}.
BindResult :: ok | esqlite3_nif:error().
bind_null(#esqlite3_stmt{stmt=Stmt}, Index) ->
esqlite3_nif:bind_null(Stmt, Index).

View File

@@ -112,7 +112,6 @@ error_info(_Db) ->
%% @doc Set an update hook
%%
-spec set_update_hook(Connection, Pid) -> Result
when Connection :: esqlite3_ref(),
Pid :: pid(),
@@ -122,40 +121,73 @@ set_update_hook(_Db, _Pid) ->
%% @doc Execute a sql statement
%%
-spec exec(Connection, Sql) -> ExecResult
when Connection :: esqlite3_ref(),
Sql :: sql(),
ExecResult :: ok | {error, _}.
ExecResult :: ok | error().
exec(_Connection, _Sql) ->
erlang:nif_error(nif_library_not_loaded).
%% @doc Compile a sql statement.
%%
-spec prepare(Connection, Sql, PrepareFlags) -> PrepareResult
when Connection :: esqlite3_ref(),
Sql :: sql(),
PrepareFlags :: non_neg_integer(),
PrepareResult :: {ok, esqlite3_stmt_ref()} | {error, _}.
PrepareResult :: {ok, esqlite3_stmt_ref()} | error().
prepare(_Connection, _Sql, _PrepareFlags) ->
erlang:nif_error(nif_library_not_loaded).
% @doc Bind an integer to a position in a prepared statement.
-spec bind_int(Statement, Index, Value) -> Result when
Statement :: esqlite3_stmt_ref(),
Index :: integer(),
Value :: integer(), %% [todo] Should be a 32 bit integer range.
Result :: ok | error().
bind_int(_Statement, _Index, _Value) ->
erlang:nif_error(nif_library_not_loaded).
% @doc Bind a 64 bit integer to a position in a prepared statement.
-spec bind_int64(Statement, Index, Value) -> Result when
Statement :: esqlite3_stmt_ref(),
Index :: integer(),
Value :: integer(), %% [todo] Should be a 64 bit integer range.
Result :: ok | error().
bind_int64(_Statement, _Index, _Value) ->
erlang:nif_error(nif_library_not_loaded).
% @doc Bind an double/float to a position in a prepared statement.
-spec bind_double(Statement, Index, Value) -> Result when
Statement :: esqlite3_stmt_ref(),
Index :: integer(),
Value :: float(), %% [todo] Should be a 64 bit integer range.
Result :: ok | error().
bind_double(_Statement, _Index, _Value) ->
erlang:nif_error(nif_library_not_loaded).
% @doc Bind a utf-8 string to a position in a prepared statement.
-spec bind_text(Statement, Index, Value) -> Result when
Statement :: esqlite3_stmt_ref(),
Index :: integer(),
Value :: iodata(), %% [todo] Should be a utf-8 iodata.
Result :: ok | error().
bind_text(_Statement, _Index, _Value) ->
erlang:nif_error(nif_library_not_loaded).
% @doc Bind a blob to a position in a prepared statement.
-spec bind_blob(Statement, Index, Value) -> Result when
Statement :: esqlite3_stmt_ref(),
Index :: integer(),
Value :: iodata(),
Result :: ok | error().
bind_blob(_Statement, _Index, _Value) ->
erlang:nif_error(nif_library_not_loaded).
% @doc Bind a null to a position in a prepared statement.
-spec bind_null(Statement, Index) -> Result when
Statement :: esqlite3_stmt_ref(),
Index :: integer(),
Result :: ok | error().
bind_null(_Statement, _Index) ->
erlang:nif_error(nif_library_not_loaded).
@@ -189,7 +221,6 @@ column_decltypes(_Stmt) ->
backup_init(_Dest, _DestName, _Src, _SrcName) ->
erlang:nif_error(nif_library_not_loaded).
backup_remaining(_Backup) ->
erlang:nif_error(nif_library_not_loaded).
@@ -249,7 +280,7 @@ memory_stats(_Flag) ->
-spec status(Op, HighwaterResetFlag) -> Stats when
Op :: integer(),
HighwaterResetFlag :: integer(),
Stats :: #{ used := integer(), highwater := integer() }.
Stats :: #{ used := non_neg_integer(), highwater := non_neg_integer() }.
status(_Op, _Flag) ->
erlang:nif_error(nif_library_not_loaded).