Support parametrized statements

This commit is contained in:
Alexey Romanov
2010-11-19 16:36:46 +03:00
parent 169e0d0ae4
commit 864d01aec1
4 changed files with 234 additions and 34 deletions

View File

@@ -107,9 +107,21 @@ parametrized() ->
drop_table_if_exists(ct, user1),
sqlite3:create_table(ct, user1, [{id, integer}, {name, text}]),
sqlite3:sql_exec(ct, "INSERT INTO user1 (id, name) VALUES (?, ?)", [{1, 1}, {2, "john"}]),
sqlite3:sql_exec(ct, "INSERT INTO user1 (id, name) VALUES (?3, ?5)", [{3, 2}, {5, "joe"}]),
sqlite3:sql_exec(ct, "INSERT INTO user1 (id, name) VALUES (:id, @name)", [{":id", 3}, {'@name', <<"jack">>}]),
sqlite3:sql_exec(ct, "INSERT INTO user1 (id, name) VALUES (?, ?)", [4, "james"]),
?assertEqual(
[{columns, ["id", "name"]}, {rows, [{1, <<"john">>}]}],
sqlite3:sql_exec(ct, "select * from user1;")).
[{columns, ["id", "name"]},
{rows, [{1, <<"john">>}, {2, <<"joe">>}, {3, <<"jack">>}, {4, <<"james">>}]}],
sqlite3:read_all(ct, user1)),
sqlite3:drop_table(ct, user1),
sqlite3:create_table(ct, user1, [{i, integer}, {d, double}, {b, blob}]),
sqlite3:sql_exec(ct, "INSERT INTO user1 (i, d, b) VALUES (?, ?, ?)",
[null, 1.0, {blob, <<1,0,0>>}]),
?assertEqual(
[{columns, ["i", "d", "b"]},
{rows, [{null, 1.0, <<1,0,0>>}]}],
sqlite3:read_all(ct, user1)).
blob() ->
drop_table_if_exists(ct, blobs),
@@ -148,21 +160,21 @@ select_many_records() ->
N,
length(rows(sqlite3:sql_exec(ct, "select * from many_records;")))).
%% %% note that inserts are actually serialized by gen_server
%% concurrent_inserts_test() ->
%% N = 1024,
%% sqlite3:open(concurrent, [in_memory]), %% doing this test not in memory is much slower!
%% drop_table_if_exists(concurrent, t),
%% sqlite3:create_table(concurrent, t, [{id0, integer}]),
%% Self = self(),
%% [spawn(fun () ->
%% sqlite3:write(concurrent, t, [{id0, X}]),
%% Self ! {finished, N}
%% end) || X <- lists:seq(1, N)],
%% loop_concurrent_inserts(N),
%% ?assertEqual(
%% N, length(rows(sqlite3:read_all(concurrent, t)))),
%% sqlite3:close(concurrent).
%% note that inserts are actually serialized by gen_server
concurrent_inserts_test() ->
N = 1024,
sqlite3:open(concurrent, [in_memory]), %% doing this test not in memory is much slower!
drop_table_if_exists(concurrent, t),
sqlite3:create_table(concurrent, t, [{id0, integer}]),
Self = self(),
[spawn(fun () ->
sqlite3:write(concurrent, t, [{id0, X}]),
Self ! {finished, N}
end) || X <- lists:seq(1, N)],
loop_concurrent_inserts(N),
?assertEqual(
N, length(rows(sqlite3:read_all(concurrent, t)))),
sqlite3:close(concurrent).
loop_concurrent_inserts(0) ->
ok;