merge
This commit is contained in:
@@ -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,
|
||||
@@ -122,6 +123,7 @@ foreach(F, Sql, Connection) ->
|
||||
foreach_s(F, Statement) when is_function(F, 1) ->
|
||||
case try_step(Statement, 0) of
|
||||
'$done' -> ok;
|
||||
{error, _} = E -> F(E);
|
||||
{row, Row} ->
|
||||
F(Row),
|
||||
foreach_s(F, Statement)
|
||||
@@ -130,6 +132,7 @@ foreach_s(F, Statement) when is_function(F, 2) ->
|
||||
ColumnNames = column_names(Statement),
|
||||
case try_step(Statement, 0) of
|
||||
'$done' -> ok;
|
||||
{error, _} = E -> F([], E);
|
||||
{row, Row} ->
|
||||
F(ColumnNames, Row),
|
||||
foreach_s(F, Statement)
|
||||
@@ -144,6 +147,7 @@ foreach_s(F, Statement) when is_function(F, 2) ->
|
||||
map_s(F, Statement) when is_function(F, 1) ->
|
||||
case try_step(Statement, 0) of
|
||||
'$done' -> [];
|
||||
{error, _} = E -> F(E);
|
||||
{row, Row} ->
|
||||
[F(Row) | map_s(F, Statement)]
|
||||
end;
|
||||
@@ -151,6 +155,7 @@ map_s(F, Statement) when is_function(F, 2) ->
|
||||
ColumnNames = column_names(Statement),
|
||||
case try_step(Statement, 0) of
|
||||
'$done' -> [];
|
||||
{error, _} = E -> F([], E);
|
||||
{row, Row} ->
|
||||
[F(ColumnNames, Row) | map_s(F, Statement)]
|
||||
end.
|
||||
@@ -160,6 +165,7 @@ map_s(F, Statement) when is_function(F, 2) ->
|
||||
fetchone(Statement) ->
|
||||
case try_step(Statement, 0) of
|
||||
'$done' -> ok;
|
||||
{error, _} = E -> E;
|
||||
{row, Row} -> Row
|
||||
end.
|
||||
|
||||
@@ -169,6 +175,7 @@ fetchall(Statement) ->
|
||||
case try_step(Statement, 0) of
|
||||
'$done' ->
|
||||
[];
|
||||
{error, _} = E -> E;
|
||||
{row, Row} ->
|
||||
[Row | fetchall(Statement)]
|
||||
end.
|
||||
@@ -211,6 +218,16 @@ exec(Sql, Params, {connection, _, _}=Connection, Timeout) when is_list(Params) -
|
||||
step(Statement, 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()}
|
||||
|
||||
Reference in New Issue
Block a user