Add esqlite3:changes/3 function to get nr of affected rows

This commit is contained in:
Arjan Scherpenisse
2014-06-15 00:14:11 +02:00
parent 3847315586
commit 476c34e1e3
4 changed files with 78 additions and 1 deletions

View File

@@ -23,8 +23,9 @@
%% higher-level export
-export([open/1, open/2,
exec/2, exec/3,
changes/1, changes/2,
insert/2,
prepare/2, prepare/3,
prepare/2, prepare/3,
step/1, step/2,
bind/2, bind/3,
fetchone/1,
@@ -200,6 +201,16 @@ exec(Sql, {connection, _Ref, Connection}, Timeout) ->
ok = esqlite3_nif:exec(Connection, Ref, self(), Sql),
receive_answer(Ref, Timeout).
%% @doc Return the number of affected rows of last statement.
changes(Connection) ->
changes(Connection, ?DEFAULT_TIMEOUT).
%% @doc Return the number of affected rows of last statement.
changes({connection, _Ref, Connection}, Timeout) ->
Ref = make_ref(),
ok = esqlite3_nif:changes(Connection, Ref, self()),
receive_answer(Ref, Timeout).
%% @doc Insert records, returns the last rowid.
%%
%% @spec insert(iolist(), connection()) -> {ok, integer()} | {error, error_message()}

View File

@@ -24,6 +24,7 @@
-export([start/0,
open/4,
exec/4,
changes/3,
insert/4,
prepare/4,
step/3,
@@ -70,6 +71,14 @@ open(_Db, _Ref, _Dest, _Filename) ->
exec(_Db, _Ref, _Dest, _Sql) ->
exit(nif_library_not_loaded).
%% @doc Get the number of affected rows of last statement
%%
%% When the statement is executed Dest will receive message {Ref, answer()}
%% with answer() integer | {error, reason()}
%%
changes(_Db, _Ref, _Dest) ->
exit(nif_library_not_loaded).
%% @doc
%%
%% @spec prepare(connection(), reference(), pid(), string()) -> ok | {error, message()}