add insert function to get last insert rowid

This commit is contained in:
qingliangcn
2013-11-28 00:22:40 +08:00
parent b2d1f7ed9f
commit a921bd65b2
3 changed files with 89 additions and 14 deletions

View File

@@ -23,6 +23,7 @@
%% higher-level export
-export([open/1, open/2,
exec/2, exec/3,
insert/2,
prepare/2, prepare/3,
step/1, step/2,
bind/2, bind/3,
@@ -199,6 +200,20 @@ exec(Sql, {connection, _Ref, Connection}, Timeout) ->
ok = esqlite3_nif:exec(Connection, Ref, self(), Sql),
receive_answer(Ref, Timeout).
%% @doc Insert records, returns the last rowid.
%%
%% @spec insert(iolist(), connection()) -> integer() | {error, error_message()}
insert(Sql, Connection) ->
insert(Sql, Connection, ?DEFAULT_TIMEOUT).
%% @doc Insert
%%
%% @spec insert(iolist(), connection(), timeout()) -> integer() | {error, error_message()}
insert(Sql, {connection, _Ref, Connection}, Timeout) ->
Ref = make_ref(),
ok = esqlite3_nif:insert(Connection, Ref, self(), Sql),
receive_answer(Ref, Timeout).
%% @doc Prepare a statement
%%
%% @spec prepare(iolist(), connection()) -> {ok, prepared_statement()} | {error, error_message()}