couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r993226 - in /couchdb/trunk: share/www/script/test/view_errors.js src/couchdb/couch_httpd_view.erl
Date Tue, 07 Sep 2010 06:28:59 GMT
Author: jchris
Date: Tue Sep  7 06:28:58 2010
New Revision: 993226

URL: http://svn.apache.org/viewvc?rev=993226&view=rev
Log:
warn when a view query will be empty due to backwards start and end keys

Modified:
    couchdb/trunk/share/www/script/test/view_errors.js
    couchdb/trunk/src/couchdb/couch_httpd_view.erl

Modified: couchdb/trunk/share/www/script/test/view_errors.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/view_errors.js?rev=993226&r1=993225&r2=993226&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/view_errors.js (original)
+++ couchdb/trunk/share/www/script/test/view_errors.js Tue Sep  7 06:28:58 2010
@@ -158,5 +158,13 @@ couchTests.view_errors = function(debug)
       T(xhr.status == 500);
       result = JSON.parse(xhr.responseText);
       T(result.error == "reduce_overflow_error");
+
+      try {
+          db.query(function() {emit(null, null)}, null, {startkey: 2, endkey:1});
+          T(0 == 1);
+      } catch(e) {
+          T(e.error == "query_parse_error");
+          T(e.reason.match(/no rows can match/i));
+      }
     });
 };

Modified: couchdb/trunk/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_view.erl?rev=993226&r1=993225&r2=993226&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_view.erl Tue Sep  7 06:28:58 2010
@@ -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 ->



Mime
View raw message