Added changes
This commit is contained in:
@@ -951,37 +951,6 @@ set_update_hook(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Execute the sql statement
|
||||
static ERL_NIF_TERM
|
||||
esqlite_exec(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
esqlite3 *db;
|
||||
esqlite_command *cmd = NULL;
|
||||
ErlNifPid pid;
|
||||
|
||||
if(argc != 4)
|
||||
return enif_make_badarg(env);
|
||||
if(!enif_get_resource(env, argv[0], esqlite3_type, (void **) &db))
|
||||
return enif_make_badarg(env);
|
||||
if(!enif_is_ref(env, argv[1]))
|
||||
return make_error_tuple(env, "invalid_ref");
|
||||
if(!enif_get_local_pid(env, argv[2], &pid))
|
||||
return make_error_tuple(env, "invalid_pid");
|
||||
|
||||
cmd = command_create();
|
||||
if(!cmd)
|
||||
return make_error_tuple(env, "command_create_failed");
|
||||
|
||||
// command
|
||||
cmd->type = cmd_exec;
|
||||
cmd->ref = enif_make_copy(cmd->env, argv[1]);
|
||||
cmd->pid = pid;
|
||||
cmd->arg = enif_make_copy(cmd->env, argv[3]);
|
||||
|
||||
return push_command(env, db, cmd);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Count the nr of changes of last statement
|
||||
@@ -1014,96 +983,6 @@ esqlite_changes(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
static ERL_NIF_TERM
|
||||
esqlite_insert(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
esqlite3 *db;
|
||||
esqlite_command *cmd = NULL;
|
||||
ErlNifPid pid;
|
||||
|
||||
if(argc != 4)
|
||||
return enif_make_badarg(env);
|
||||
if(!enif_get_resource(env, argv[0], esqlite3_type, (void **) &db))
|
||||
return enif_make_badarg(env);
|
||||
if(!enif_is_ref(env, argv[1]))
|
||||
return make_error_tuple(env, "invalid_ref");
|
||||
if(!enif_get_local_pid(env, argv[2], &pid))
|
||||
return make_error_tuple(env, "invalid_pid");
|
||||
|
||||
cmd = command_create();
|
||||
if(!cmd)
|
||||
return make_error_tuple(env, "command_create_failed");
|
||||
|
||||
// command
|
||||
cmd->type = cmd_insert;
|
||||
cmd->ref = enif_make_copy(cmd->env, argv[1]);
|
||||
cmd->pid = pid;
|
||||
cmd->arg = enif_make_copy(cmd->env, argv[3]);
|
||||
|
||||
return push_command(env, db, cmd);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
static ERL_NIF_TERM
|
||||
esqlite_last_insert_rowid(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
esqlite3 *db;
|
||||
esqlite_command *cmd = NULL;
|
||||
ErlNifPid pid;
|
||||
|
||||
if(argc != 3)
|
||||
return enif_make_badarg(env);
|
||||
if(!enif_get_resource(env, argv[0], esqlite3_type, (void **) &db))
|
||||
return enif_make_badarg(env);
|
||||
if(!enif_is_ref(env, argv[1]))
|
||||
return make_error_tuple(env, "invalid_ref");
|
||||
if(!enif_get_local_pid(env, argv[2], &pid))
|
||||
return make_error_tuple(env, "invalid_pid");
|
||||
|
||||
cmd = command_create();
|
||||
if(!cmd)
|
||||
return make_error_tuple(env, "command_create_failed");
|
||||
|
||||
// command
|
||||
cmd->type = cmd_last_insert_rowid;
|
||||
cmd->ref = enif_make_copy(cmd->env, argv[1]);
|
||||
cmd->pid = pid;
|
||||
|
||||
return push_command(env, db, cmd);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
static ERL_NIF_TERM
|
||||
esqlite_get_autocommit(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
esqlite3 *db;
|
||||
esqlite_command *cmd = NULL;
|
||||
ErlNifPid pid;
|
||||
|
||||
if(argc != 3)
|
||||
return enif_make_badarg(env);
|
||||
if(!enif_get_resource(env, argv[0], esqlite3_type, (void **) &db))
|
||||
return enif_make_badarg(env);
|
||||
if(!enif_is_ref(env, argv[1]))
|
||||
return make_error_tuple(env, "invalid_ref");
|
||||
if(!enif_get_local_pid(env, argv[2], &pid))
|
||||
return make_error_tuple(env, "invalid_pid");
|
||||
|
||||
cmd = command_create();
|
||||
if(!cmd)
|
||||
return make_error_tuple(env, "command_create_failed");
|
||||
|
||||
// command
|
||||
cmd->type = cmd_get_autocommit;
|
||||
cmd->ref = enif_make_copy(cmd->env, argv[1]);
|
||||
cmd->pid = pid;
|
||||
|
||||
return push_command(env, db, cmd);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Bind a variable to a prepared statement
|
||||
@@ -1742,6 +1621,23 @@ esqlite_last_insert_rowid(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
return enif_make_int64(env, last_rowid);
|
||||
}
|
||||
|
||||
static ERL_NIF_TERM
|
||||
esqlite_changes(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
esqlite3 *conn;
|
||||
|
||||
if(!enif_get_resource(env, argv[0], esqlite3_type, (void **) &conn))
|
||||
return enif_make_badarg(env);
|
||||
|
||||
esqlite3 *db = (esqlite3 *) conn;
|
||||
|
||||
if(db->db == NULL) {
|
||||
return make_error_tuple(env, "closed");
|
||||
}
|
||||
|
||||
sqlite3_int64 changes = sqlite3_changes64(db->db);
|
||||
return enif_make_int64(env, changes);
|
||||
}
|
||||
|
||||
/*
|
||||
* Load the nif. Initialize some stuff and such
|
||||
@@ -1818,13 +1714,12 @@ static ErlNifFunc nif_funcs[] = {
|
||||
{"interrupt", 1, esqlite_interrupt, ERL_NIF_DIRTY_JOB_IO_BOUND},
|
||||
{"last_insert_rowid", 1, esqlite_last_insert_rowid},
|
||||
{"get_autocommit", 1, esqlite_get_autocommit},
|
||||
{"changes", 1, esqlite_changes},
|
||||
|
||||
/*
|
||||
{"set_update_hook", 4, set_update_hook},
|
||||
|
||||
{"exec", 4, esqlite_exec, ERL_NIF_DIRTY_JOB_IO_BOUND},
|
||||
{"changes", 3, esqlite_changes},
|
||||
{"insert", 4, esqlite_insert},
|
||||
|
||||
{"backup_init", 6, esqlite_backup_init},
|
||||
{"backup_step", 5, esqlite_backup_step},
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
%% db connection functions
|
||||
get_autocommit/1,
|
||||
last_insert_rowid/1,
|
||||
changes/1,
|
||||
|
||||
% set_update_hook/2, set_update_hook/3,
|
||||
|
||||
prepare/2,
|
||||
@@ -44,7 +46,6 @@
|
||||
reset/1
|
||||
|
||||
% exec/2, exec/3, exec/4,
|
||||
% changes/1, changes/2,
|
||||
% insert/2, insert/3,
|
||||
%
|
||||
% fetchone/1,
|
||||
@@ -347,7 +348,8 @@ close(#esqlite3{db=Connection}) ->
|
||||
% Ref = make_ref(),
|
||||
% ok = esqlite3_nif:changes(RawConnection, Ref, self()),
|
||||
% receive_answer(RawConnection, Ref, Timeout).
|
||||
%
|
||||
|
||||
|
||||
%%% @doc Insert records, returns the last rowid.
|
||||
%%
|
||||
%-spec insert(sql(), connection()) -> {ok, rowid()} | {error, _}.
|
||||
@@ -357,15 +359,11 @@ close(#esqlite3{db=Connection}) ->
|
||||
%% @doc Like insert/2, but with extra timeout parameter.
|
||||
%-spec insert(sql(), connection(), timeout()) -> {ok, rowid()} | {error, _}.
|
||||
%insert(Sql, #connection{raw_connection=RawConnection}, Timeout) ->
|
||||
% [NOTE] it is an exec followed by a last_insert_rowid.
|
||||
% Ref = make_ref(),
|
||||
% ok = esqlite3_nif:insert(RawConnection, Ref, self(), Sql),
|
||||
% receive_answer(RawConnection, Ref, Timeout).
|
||||
|
||||
%% @doc Get the last insert rowid, using the default timeout.
|
||||
%%
|
||||
%-spec last_insert_rowid(connection()) -> {ok, rowid()} | {error, _}.
|
||||
%last_insert_rowid(Connection) ->
|
||||
% last_insert_rowid(Connection, ?DEFAULT_TIMEOUT).
|
||||
|
||||
%% @doc Get the last insert rowid.
|
||||
%%
|
||||
@@ -375,6 +373,15 @@ close(#esqlite3{db=Connection}) ->
|
||||
last_insert_rowid(#esqlite3{db=Connection}) ->
|
||||
esqlite3_nif:last_insert_rowid(Connection).
|
||||
|
||||
%% @doc Get the number of changes in the most recent INSERT, UPDATE or DELETE.
|
||||
%%
|
||||
-spec changes(Connection) -> ChangesResult
|
||||
when Connection :: esqlite3(),
|
||||
ChangesResult :: integer() | {error, closed}.
|
||||
changes(#esqlite3{db=Connection}) ->
|
||||
esqlite3_nif:changes(Connection).
|
||||
|
||||
|
||||
%% @doc Check if the connection is in auto-commit mode.
|
||||
%% See: [https://sqlite.org/c3ref/get_autocommit.html] for more details.
|
||||
%%
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
get_autocommit/1,
|
||||
last_insert_rowid/1,
|
||||
changes/1,
|
||||
|
||||
prepare/3,
|
||||
|
||||
@@ -46,7 +47,6 @@
|
||||
% set_update_hook/4,
|
||||
% exec/4,
|
||||
% changes/3,
|
||||
% insert/4,
|
||||
%
|
||||
% multi_step/5,
|
||||
% reset/4,
|
||||
@@ -216,18 +216,20 @@ column_decltypes(_Stmt) ->
|
||||
interrupt(_Db) ->
|
||||
erlang:nif_error(nif_library_not_loaded).
|
||||
|
||||
%% @doc Insert record
|
||||
%%
|
||||
%-spec insert(esqlite3(), reference(), pid(), sql()) -> ok | {error, _}.
|
||||
%insert(_Db, _Ref, _Dest, _Sql) ->
|
||||
% erlang:nif_error(nif_library_not_loaded).
|
||||
|
||||
%% @doc Get the last insert rowid.
|
||||
%%
|
||||
-spec last_insert_rowid(esqlite3()) -> integer() | {error, _}.
|
||||
last_insert_rowid(_Connection) ->
|
||||
erlang:nif_error(nif_library_not_loaded).
|
||||
|
||||
%% @doc Get number of changes insert, delete of the most recent completed
|
||||
%% INSERT, DELETE or UPDATE statement.
|
||||
%%
|
||||
-spec changes(esqlite3()) -> integer() | {error, _}.
|
||||
changes(_Connection) ->
|
||||
erlang:nif_error(nif_library_not_loaded).
|
||||
|
||||
|
||||
%% @doc Get autocommit
|
||||
%%
|
||||
-spec get_autocommit(esqlite3()) -> true | false | {error, _}.
|
||||
|
||||
Reference in New Issue
Block a user