Foundations for step. Exploring api
This commit is contained in:
@@ -252,8 +252,14 @@ do_step(ErlNifEnv *env, esqlite_connection *conn, sqlite3_stmt *stmt)
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
|
||||
if(rc == SQLITE_DONE)
|
||||
return make_atom(env, "$done");
|
||||
if(rc == SQLITE_BUSY)
|
||||
return make_atom(env, "$busy");
|
||||
|
||||
/* Now prepare the output... */
|
||||
fprintf(stderr, "step returned: %d\n", rc);
|
||||
fprintf(stderr, "nu columns: %d\n", sqlite3_column_count(stmt));
|
||||
fprintf(stderr, "# columns: %d\n", sqlite3_column_count(stmt));
|
||||
|
||||
return _atom_ok;
|
||||
}
|
||||
|
||||
@@ -38,10 +38,28 @@ prepare_test() ->
|
||||
esqlite:exec(Db, "create table test_table(one varchar(10), two int);"),
|
||||
{ok, Statement} = esqlite:prepare(Db, "insert into test_table values(\"one\", 2)"),
|
||||
|
||||
esqlite:step(Statement),
|
||||
|
||||
'$done' = esqlite:step(Statement),
|
||||
|
||||
{ok, St2} = esqlite:prepare(Db, "select * from test_table"),
|
||||
esqlite:step(St2).
|
||||
|
||||
[ok] = exec(St2),
|
||||
ok.
|
||||
|
||||
exec(Statement) ->
|
||||
exec(Statement, [], 0).
|
||||
|
||||
exec(_Statement, _Acc, Tries) when Tries > 5 ->
|
||||
throw(too_many_tries);
|
||||
exec(Statement, Acc, Tries) ->
|
||||
case esqlite:step(Statement) of
|
||||
'$done' ->
|
||||
lists:reverse(Acc);
|
||||
'$busy' ->
|
||||
timer:sleep(100),
|
||||
exec(Statement, Acc, Tries + 1);
|
||||
V ->
|
||||
exec(Statement, [V | Acc], 0)
|
||||
end.
|
||||
|
||||
%% esqlite:bind(Statement, ":one", "hello"),
|
||||
%% esqlite:bind(Statement, ":two", 11),
|
||||
|
||||
Reference in New Issue
Block a user