Merge pull request #7 from arjan/parametrized-exec
Add parametrized exec's (esqlite3:exec/3 and esqlite3:exec/4)
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <erl_nif.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "queue.h"
|
||||
#include "sqlite3.h"
|
||||
@@ -491,12 +492,7 @@ do_step(ErlNifEnv *env, sqlite3 *db, sqlite3_stmt *stmt)
|
||||
if(rc == SQLITE_BUSY)
|
||||
return make_atom(env, "$busy");
|
||||
|
||||
if(rc == SQLITE_ERROR)
|
||||
return make_sqlite3_error_tuple(env, rc, db);
|
||||
if(rc == SQLITE_MISUSE)
|
||||
return make_error_tuple(env, "misuse");
|
||||
|
||||
return make_error_tuple(env, "unexpected_return_value");
|
||||
return make_sqlite3_error_tuple(env, rc, db);
|
||||
}
|
||||
|
||||
static ERL_NIF_TERM
|
||||
|
||||
@@ -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.
|
||||
%%
|
||||
|
||||
Reference in New Issue
Block a user