Busy adding remaining and pagecount
This commit is contained in:
@@ -734,7 +734,6 @@ do_column_types(ErlNifEnv *env, sqlite3_stmt *stmt)
|
||||
static ERL_NIF_TERM
|
||||
do_backup_init(ErlNifEnv *env, sqlite3 *db, const ERL_NIF_TERM arg)
|
||||
{
|
||||
int rc;
|
||||
int tuple_arity;
|
||||
const ERL_NIF_TERM *elements;
|
||||
sqlite3_backup *backup;
|
||||
@@ -800,13 +799,35 @@ do_backup_step(ErlNifEnv *env, const ERL_NIF_TERM arg)
|
||||
static ERL_NIF_TERM
|
||||
do_backup_remaining(ErlNifEnv *env, const ERL_NIF_TERM arg)
|
||||
{
|
||||
return make_atom(env, "todo");
|
||||
esqlite_backup *esqlite_backup;
|
||||
int remaining;
|
||||
ERL_NIF_TERM remaining_term;
|
||||
|
||||
if(!enif_get_resource(env, arg, esqlite_backup_type, (void **) &esqlite_backup)) {
|
||||
return make_error_tuple(env, "invalid");
|
||||
}
|
||||
|
||||
remaining = sqlite3_backup_remaining(esqlite_backup->backup);
|
||||
remaining_term = enif_make_int64(env, remaining);
|
||||
|
||||
return make_ok_tuple(env, remaining_term);
|
||||
}
|
||||
|
||||
static ERL_NIF_TERM
|
||||
do_backup_pagecount(ErlNifEnv *env, const ERL_NIF_TERM arg)
|
||||
{
|
||||
return make_atom(env, "todo");
|
||||
esqlite_backup *esqlite_backup;
|
||||
int pagecount;
|
||||
ERL_NIF_TERM pagecount_term;
|
||||
|
||||
if(!enif_get_resource(env, arg, esqlite_backup_type, (void **) &esqlite_backup)) {
|
||||
return make_error_tuple(env, "invalid");
|
||||
}
|
||||
|
||||
pagecount = sqlite3_backup_pagecount(esqlite_backup->backup);
|
||||
pagecount_term = enif_make_int64(env, pagecount);
|
||||
|
||||
return make_ok_tuple(env, pagecount_term);
|
||||
}
|
||||
|
||||
static ERL_NIF_TERM
|
||||
@@ -1512,7 +1533,7 @@ esqlite_backup_remaining(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
|
||||
if(!enif_get_resource(env, argv[0], esqlite_connection_type, (void **) &conn))
|
||||
return enif_make_badarg(env);
|
||||
// backup
|
||||
// backup 1
|
||||
if(!enif_is_ref(env, argv[2]))
|
||||
return make_error_tuple(env, "invalid_ref");
|
||||
if(!enif_get_local_pid(env, argv[3], &pid))
|
||||
@@ -1543,7 +1564,7 @@ esqlite_backup_pagecount(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
|
||||
if(!enif_get_resource(env, argv[0], esqlite_connection_type, (void **) &conn))
|
||||
return enif_make_badarg(env);
|
||||
// backup
|
||||
// backup 1
|
||||
if(!enif_is_ref(env, argv[2]))
|
||||
return make_error_tuple(env, "invalid_ref");
|
||||
if(!enif_get_local_pid(env, argv[3], &pid))
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
column_names/1, column_names/2,
|
||||
column_types/1, column_types/2,
|
||||
backup_init/4, backup_init/5,
|
||||
backup_remaining/1, backup_remaining/2,
|
||||
backup_pagecount/1, backup_pagecount/2,
|
||||
close/1, close/2,
|
||||
flush/0
|
||||
]).
|
||||
@@ -58,6 +60,7 @@
|
||||
}).
|
||||
|
||||
-record(backup, {
|
||||
raw_connection :: esqlite_nif:raw_connection(),
|
||||
raw_backup :: esqlite_nif:raw_backup()
|
||||
}).
|
||||
|
||||
@@ -544,7 +547,46 @@ backup_init(Dest, DestName, Src, SrcName) ->
|
||||
backup_init(#connection{raw_connection=Dest}, DestName, #connection{raw_connection=Src}, SrcName, Timeout) ->
|
||||
Ref = make_ref(),
|
||||
ok = esqlite3_nif:backup_init(Dest, DestName, Src, SrcName, Ref, self()),
|
||||
receive_answer(Dest, Ref, Timeout).
|
||||
case receive_answer(Dest, Ref, Timeout) of
|
||||
{ok, RawBackup} when is_reference(RawBackup) ->
|
||||
{ok, #backup{raw_connection=Dest, raw_backup=RawBackup}};
|
||||
{error, _} = Error ->
|
||||
Error
|
||||
end.
|
||||
|
||||
%% @doc Get the remaining number of pages which need to be backed up.
|
||||
-spec backup_remaining(backup()) -> {ok, pos_integer()} | {error, _}.
|
||||
backup_remaining(Backup) ->
|
||||
backup_remaining(Backup, ?DEFAULT_TIMEOUT).
|
||||
|
||||
%% @doc Get the remaining number of pages which need to be backed up.
|
||||
-spec backup_remaining(backup(), timeout()) -> {ok, pos_integer()} | {error, _}.
|
||||
backup_remaining(#backup{raw_connection=Conn, raw_backup=Back}, Timeout) ->
|
||||
Ref = make_ref(),
|
||||
ok = esqlite3_nif:backup_remaining(Conn, Back, Ref, self()),
|
||||
case receive_answer(Conn, Ref, Timeout) of
|
||||
{ok, R} when is_integer(R) ->
|
||||
{ok, R};
|
||||
{error, _}=E ->
|
||||
E
|
||||
end.
|
||||
|
||||
%% @doc Get the remaining number of pages which need to be backed up.
|
||||
-spec backup_pagecount(backup()) -> {ok, pos_integer()} | {error, _}.
|
||||
backup_pagecount(Backup) ->
|
||||
backup_pagecount(Backup, ?DEFAULT_TIMEOUT).
|
||||
|
||||
%% @doc Get the remaining number of pages which need to be backed up.
|
||||
-spec backup_pagecount(backup(), timeout()) -> {ok, pos_integer()} | {error, _}.
|
||||
backup_pagecount(#backup{raw_connection=Conn, raw_backup=Back}, Timeout) ->
|
||||
Ref = make_ref(),
|
||||
ok = esqlite3_nif:backup_pagecount(Conn, Back, Ref, self()),
|
||||
case receive_answer(Conn, Ref, Timeout) of
|
||||
{ok, R} when is_integer(R) ->
|
||||
{ok, R};
|
||||
{error, _}=E ->
|
||||
E
|
||||
end.
|
||||
|
||||
|
||||
%% @doc Close the database
|
||||
|
||||
@@ -445,6 +445,8 @@ backup_test() ->
|
||||
{ok, Source} = esqlite3:open("test2.sql"),
|
||||
|
||||
{ok, Backup} = esqlite3:backup_init(Dest, "main", Source, "main"),
|
||||
{ok, 0} = esqlite3:backup_remaining(Backup),
|
||||
{ok, 0} = esqlite3:backup_pagecount(Backup),
|
||||
|
||||
ok.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user