Skip to content

Commit

Permalink
fix remaining integer to string bits and improve tyrant error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim McCoy authored and Jim McCoy committed May 21, 2009
1 parent f6cac0e commit 08cd40b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/principe.erl
Expand Up @@ -621,6 +621,20 @@ ext(Socket, Func, Opts, Key, Value) ->

tyrant_response(Socket, ResponseHandler) ->
receive
{tcp, Socket, <<1:8, _Rest/binary>>} ->
{error, invalid_operation};
{tcp, Socket, <<2:8, _Rest/binary>>} ->
{error, no_host_found};
{tcp, Socket, <<3:8, _Rest/binary>>} ->
{error, connection_refused};
{tcp, Socket, <<4:8, _Rest/binary>>} ->
{error, send_error};
{tcp, Socket, <<5:8, _Rest/binary>>} ->
{error, recv_error};
{tcp, Socket, <<6:8, _Rest/binary>>} ->
{error, existing_record};
{tcp, Socket, <<7:8, _Rest/binary>>} ->
{error, no_such_record};
{tcp, Socket, <<ErrorCode:8, _Rest/binary>>} when ErrorCode =/= 0 ->
{error, ErrorCode};
{tcp_closed, Socket} ->
Expand Down
24 changes: 19 additions & 5 deletions src/principe_table.erl
Expand Up @@ -459,7 +459,7 @@ genuid(Socket) ->
%% @end
query_add_condition(Query, ColName, Op, ExprList) when is_list(ExprList) ->
[{add_cond, {ColName,
integer_to_list(add_condition_op_val(Op)),
add_condition_op_val(Op),
convert_query_exprlist(ExprList)}} | Query].

%% @spec query_set_limit(Query::proplist(),
Expand Down Expand Up @@ -655,14 +655,28 @@ query_to_argslist([{K, V} | T], BinArgs) ->
case K of
add_cond ->
{ColName, Op, ExprList} = V,
query_to_argslist(T, [["addcond", ?NULL, ColName, ?NULL, Op, ?NULL, ExprList] | BinArgs]);
query_to_argslist(T, [["addcond",
?NULL,
ColName,
?NULL,
integer_to_list(Op),
?NULL,
ExprList] | BinArgs]);
set_limit ->
% XXX: check spec to see if the max and skip should be integers or chars
{M, S} = V,
query_to_argslist(T, [["setlimit", ?NULL, <<M:32>>, ?NULL, <<S:32>>] | BinArgs]);
{Max, Skip} = V,
query_to_argslist(T, [["setlimit",
?NULL,
integer_to_list(Max),
?NULL,
integer_to_list(Skip)] | BinArgs]);
set_order ->
{ColName, Type} = V,
query_to_argslist(T, [["setorder", ?NULL, ColName, ?NULL, Type] | BinArgs])
query_to_argslist(T, [["setorder",
?NULL,
ColName,
?NULL,
integer_to_list(Type)] | BinArgs])
end;
query_to_argslist([], BinArgs) ->
lists:reverse(BinArgs).
Expand Down
7 changes: 5 additions & 2 deletions test/principe_table_test.erl
Expand Up @@ -191,14 +191,17 @@ query_generation_test(Mod) ->
[{set_order, {"foo", 0}}] = Mod:query_set_order([{set_order, blah}], "foo", str_ascending),
[{set_limit, {2, 0}}] = Mod:query_set_limit([], 2),
[{set_limit, {4, 1}}] = Mod:query_set_limit([{set_limit, blah}], 4, 1),
[{add_cond, {"foo", "0", ["bar"]}}] = Mod:query_add_condition([], "foo", str_eq, ["bar"]),
[{add_cond, {"foo", "16777220", ["bar",",","baz"]}}] =
[{add_cond, {"foo", 0, ["bar"]}}] = Mod:query_add_condition([], "foo", str_eq, ["bar"]),
[{add_cond, {"foo", 16777220, ["bar",",","baz"]}}] =
Mod:query_add_condition([], "foo", {no, str_and}, ["bar", "baz"]),
ok.

search_test(Mod) ->
Socket = setup_column_data(Mod),
Query1 = Mod:query_add_condition([], "name", str_eq, ["alice"]),
[<<"rec1">>] = Mod:search(Socket, Query1),
Query2 = Mod:query_add_condition([], "name", {no, str_eq}, ["alice"]),
Query2A = Mod:query_set_limit(Query2, 2),
[<<"rec2">>, <<"rec3">>] = Mod:search(Socket, Query2A),
ok.

0 comments on commit 08cd40b

Please sign in to comment.