summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2010-09-07 06:28:58 +0000
committerJohn Christopher Anderson <jchris@apache.org>2010-09-07 06:28:58 +0000
commit3ff18b6b7ca953224e5f03061acefb1ddb69b165 (patch)
treee362a22139cd4d7000a97e0b8d8227ec2c5694d8 /src
parent1c1c7d8359053b8b4b473903b7fadd354064c032 (diff)
warn when a view query will be empty due to backwards start and end keys
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@993226 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_httpd_view.erl21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl
index 16b2791f..96bb45ff 100644
--- a/src/couchdb/couch_httpd_view.erl
+++ b/src/couchdb/couch_httpd_view.erl
@@ -246,7 +246,7 @@ parse_view_params(Req, Keys, ViewType) ->
QueryArgs = lists:foldl(fun({K, V}, Args2) ->
validate_view_query(K, V, Args2)
end, Args, lists:reverse(QueryParams)), % Reverse to match QS order.
-
+ warn_on_empty_key_range(QueryArgs),
GroupLevel = QueryArgs#view_query_args.group_level,
case {ViewType, GroupLevel, IsMultiGet} of
{reduce, exact, true} ->
@@ -313,6 +313,25 @@ parse_view_param("callback", _) ->
parse_view_param(Key, Value) ->
[{extra, {Key, Value}}].
+warn_on_empty_key_range(#view_query_args{start_key=undefined}) ->
+ ok;
+warn_on_empty_key_range(#view_query_args{end_key=undefined}) ->
+ ok;
+warn_on_empty_key_range(#view_query_args{start_key=A, end_key=A}) ->
+ ok;
+warn_on_empty_key_range(#view_query_args{
+ start_key=StartKey, end_key=EndKey, direction=Dir}) ->
+ ?LOG_ERROR("view_query_args ~p", [{StartKey, EndKey, Dir}]),
+ case {Dir, couch_view:less_json(StartKey, EndKey)} of
+ {fwd, false} ->
+ throw({query_parse_error,
+ <<"No rows can match your key range, reverse your startkey and endkey or set descending=true">>});
+ {rev, true} ->
+ throw({query_parse_error,
+ <<"No rows can match your key range, reverse your startkey and endkey or set descending=false">>});
+ _ -> ok
+ end.
+
validate_view_query(start_key, Value, Args) ->
case Args#view_query_args.multi_get of
true ->