Adding column names functionality
This commit is contained in:
@@ -71,7 +71,8 @@ foreach(F, Sql, Connection) ->
|
||||
%%
|
||||
foreach_s(F, Statement) ->
|
||||
case try_step(Statement, 0) of
|
||||
'$done' -> ok;
|
||||
'$done' ->
|
||||
ok;
|
||||
Row when is_tuple(Row) ->
|
||||
F(Row),
|
||||
foreach_s(F, Statement)
|
||||
@@ -82,7 +83,7 @@ map_s(F, Statement) ->
|
||||
case try_step(Statement, 0) of
|
||||
'$done' ->
|
||||
[];
|
||||
Row ->
|
||||
Row when is_tuple(Row) ->
|
||||
[F(Row) | map_s(F, Statement)]
|
||||
end.
|
||||
|
||||
@@ -95,11 +96,13 @@ do_steps(Statement) ->
|
||||
[Row | do_steps(Statement)]
|
||||
end.
|
||||
|
||||
%% Try the step, when the database is busy,
|
||||
try_step(_Statement, Tries) when Tries > 5 ->
|
||||
throw(too_many_tries);
|
||||
try_step(Statement, Tries) ->
|
||||
case esqlite3:step(Statement) of
|
||||
'$busy' ->
|
||||
timer:sleep(100 * Tries),
|
||||
try_step(Statement, Tries + 1);
|
||||
Something ->
|
||||
Something
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
prepare/4,
|
||||
step/3,
|
||||
bind/4,
|
||||
column_names/3,
|
||||
close/3
|
||||
]).
|
||||
|
||||
@@ -70,16 +71,22 @@ prepare(_Db, _Ref, _Dest, _Sql) ->
|
||||
|
||||
%% @doc
|
||||
%%
|
||||
%% @spec step(connection(), reference(), pid()) -> ok | {error, message()}
|
||||
%% @spec step(statement(), reference(), pid()) -> ok | {error, message()}
|
||||
step(_Stmt, _Ref, _Dest) ->
|
||||
exit(nif_library_not_loaded).
|
||||
|
||||
%% @doc Bind parameters to a prepared statement.
|
||||
%%
|
||||
%% @spec bind(connection(), reference(), pid(), []) -> ok | {error, message()}
|
||||
%% @spec bind(statement(), reference(), pid(), []) -> ok | {error, message()}
|
||||
bind(_Stmt, _Ref, _Dest, _Args) ->
|
||||
exit(nif_library_not_loaded).
|
||||
|
||||
%% @doc Retrieve the column names of the prepared statement
|
||||
%%
|
||||
%% @spec column_names(statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
|
||||
column_names(_Stmt, _Ref, _Dest) ->
|
||||
exit(nif_library_not_loaded).
|
||||
|
||||
%% @doc Close the connection.
|
||||
%%
|
||||
%% @spec close(connection(), reference(), pid()) -> ok | {error, message()}
|
||||
|
||||
Reference in New Issue
Block a user