From f5ca40f8b0b03cd302bad656f087d94ea23a66a8 Mon Sep 17 00:00:00 2001 From: Arjan Scherpenisse Date: Sun, 19 Jan 2014 19:10:19 +0100 Subject: [PATCH] Add parametrized exec's (esqlite3:exec/3 and esqlite3:exec/4) --- src/esqlite3.erl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/esqlite3.erl b/src/esqlite3.erl index 597accc..9428040 100644 --- a/src/esqlite3.erl +++ b/src/esqlite3.erl @@ -198,7 +198,18 @@ exec(Sql, Connection) -> exec(Sql, {connection, _Ref, Connection}, Timeout) -> Ref = make_ref(), ok = esqlite3_nif:exec(Connection, Ref, self(), Sql), - receive_answer(Ref, Timeout). + receive_answer(Ref, Timeout); + +%% @spec exec(iolist(), list(term()), connection()) -> integer() | {error, error_message()} +exec(Sql, Params, {connection, _, _}=Connection) when is_list(Params) -> + exec(Sql, Params, Connection, ?DEFAULT_TIMEOUT). + +%% @spec exec(iolist(), list(term()), connection(), timeout()) -> integer() | {error, error_message()} +exec(Sql, Params, {connection, _, _}=Connection, Timeout) when is_list(Params) -> + {ok, Statement} = prepare(Sql, Connection, Timeout), + bind(Statement, Params), + step(Statement, Timeout). + %% @doc Insert records, returns the last rowid. %%