Cleaned up connection reference inside c-struct of statement

This commit is contained in:
Maas-Maarten Zeeman
2017-02-28 23:38:14 +01:00
parent 3f1ef40b90
commit d4969140bc
4 changed files with 103 additions and 92 deletions

View File

@@ -278,17 +278,17 @@ step(Stmt) ->
%%
%% @spec step(prepared_statement(), timeout()) -> tuple()
-spec step(term(), timeout()) -> tuple() | '$busy' | '$done'.
step({statement, Stmt, _}, Timeout) ->
step({statement, Stmt, {connection, _, Conn}}, Timeout) ->
Ref = make_ref(),
ok = esqlite3_nif:step(Stmt, Ref, self()),
ok = esqlite3_nif:step(Conn, Stmt, Ref, self()),
receive_answer(Ref, Timeout).
%% @doc Reset the prepared statement back to its initial state.
%%
%% @spec reset(prepared_statement()) -> ok | {error, error_message()}
reset({statement, Stmt, _}) ->
reset({statement, Stmt, {connection, _, Conn}}) ->
Ref = make_ref(),
ok = esqlite3_nif:reset(Stmt, Ref, self()),
ok = esqlite3_nif:reset(Conn, Stmt, Ref, self()),
receive_answer(Ref, ?DEFAULT_TIMEOUT).
%% @doc Bind values to prepared statements
@@ -300,9 +300,9 @@ bind(Stmt, Args) ->
%% @doc Bind values to prepared statements
%%
%% @spec bind(prepared_statement(), [], timeout()) -> ok | {error, error_message()}
bind({statement, Stmt, _}, Args, Timeout) ->
bind({statement, Stmt, {connection, _, Conn}}, Args, Timeout) ->
Ref = make_ref(),
ok = esqlite3_nif:bind(Stmt, Ref, self(), Args),
ok = esqlite3_nif:bind(Conn, Stmt, Ref, self(), Args),
receive_answer(Ref, Timeout).
%% @doc Return the column names of the prepared statement.
@@ -312,9 +312,9 @@ column_names(Stmt) ->
column_names(Stmt, ?DEFAULT_TIMEOUT).
-spec column_names(statement(), timeout()) -> {atom()}.
column_names({statement, Stmt, _}, Timeout) ->
column_names({statement, Stmt, {connection, _, Conn}}, Timeout) ->
Ref = make_ref(),
ok = esqlite3_nif:column_names(Stmt, Ref, self()),
ok = esqlite3_nif:column_names(Conn, Stmt, Ref, self()),
receive_answer(Ref, Timeout).
%% @doc Return the column types of the prepared statement.
@@ -324,9 +324,9 @@ column_types(Stmt) ->
column_types(Stmt, ?DEFAULT_TIMEOUT).
-spec column_types(statement(), timeout()) -> {atom()}.
column_types({statement, Stmt, _}, Timeout) ->
column_types({statement, Stmt, {connection, _, Conn}}, Timeout) ->
Ref = make_ref(),
ok = esqlite3_nif:column_types(Stmt, Ref, self()),
ok = esqlite3_nif:column_types(Conn, Stmt, Ref, self()),
receive_answer(Ref, Timeout).
%% @doc Close the database

View File

@@ -27,12 +27,12 @@
changes/3,
insert/4,
prepare/4,
step/3,
reset/3,
finalize/3,
bind/4,
column_names/3,
column_types/3,
step/4,
reset/4,
finalize/4,
bind/5,
column_names/4,
column_types/4,
close/3
]).
@@ -91,37 +91,37 @@ prepare(_Db, _Ref, _Dest, _Sql) ->
%% @doc
%%
%% @spec step(statement(), reference(), pid()) -> ok | {error, message()}
step(_Stmt, _Ref, _Dest) ->
step(_Db, _Stmt, _Ref, _Dest) ->
erlang:nif_error(nif_library_not_loaded).
%% @doc
%%
%% @spec reset(statement(), reference(), pid()) -> ok | {error, message()}
reset(_Stmt, _Ref, _Dest) ->
reset(_Db, _Stmt, _Ref, _Dest) ->
erlang:nif_error(nif_library_not_loaded).
%% @doc
%%
%%
finalize(_Stmt, _Ref, _Dest) ->
finalize(_Db, _Stmt, _Ref, _Dest) ->
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) ->
%% @spec bind(connection(), statement(), reference(), pid(), []) -> ok | {error, message()}
bind(_Db, _Stmt, _Ref, _Dest, _Args) ->
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) ->
%% @spec column_names(connection(), statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
column_names(_Db, _Stmt, _Ref, _Dest) ->
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) ->
%% @spec column_types(connection(), statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
column_types(_Db, _Stmt, _Ref, _Dest) ->
erlang:nif_error(nif_library_not_loaded).
%% @doc Close the connection.