[Groonga-commit] groonga/groonga [master] select query_flags: accept NONE for no flags

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Aug 16 16:18:16 JST 2012


Kouhei Sutou	2012-08-16 16:18:16 +0900 (Thu, 16 Aug 2012)

  New Revision: 639ec5cda112dfb492613a191561ee05464f77a3
  https://github.com/groonga/groonga/commit/639ec5cda112dfb492613a191561ee05464f77a3

  Log:
    select query_flags: accept NONE for no flags

  Added files:
    test/function/suite/select/query_flags/none.expected
    test/function/suite/select/query_flags/none.test
  Modified files:
    doc/source/reference/commands/select.txt
    lib/proc.c

  Modified: doc/source/reference/commands/select.txt (+4 -1)
===================================================================
--- doc/source/reference/commands/select.txt    2012-08-16 15:46:16 +0900 (7f6d1f8)
+++ doc/source/reference/commands/select.txt    2012-08-16 16:18:16 +0900 (204f7e7)
@@ -40,7 +40,7 @@ Syntax
          [cache=yes]
          [match_escalation_threshold=0]
          [query_expansion=null]
-         [query_flags=ALLOW_PRAGMA|ALLOW_COLUMN|ALLOW_UPDATE]
+         [query_flags=ALLOW_PRAGMA|ALLOW_COLUMN|ALLOW_UPDATE|NONE]
 
 Usage
 -----
@@ -550,6 +550,7 @@ Here are available values:
 * ``ALLOW_PRAGMA``
 * ``ALLOW_COLUMN``
 * ``ALLOW_UPDATE``
+* ``NONE``
 
 ``ALLOW_PRAGMA`` enables pragma at the head of ``query``.
 
@@ -561,6 +562,8 @@ syntaxes.
 ``COLUMN:=NEW_VALUE`` syntax. ``ALLOW_COLUMN`` is also required to
 update column because the column update syntax specifies column.
 
+``NONE`` is just ignores. You can use ``NONE`` for specifying no flags.
+
 They can be combined by separated ``|`` such as
 ``ALLOW_COLUMN|ALLOW_UPDATE``.
 

  Modified: lib/proc.c (+13 -12)
===================================================================
--- lib/proc.c    2012-08-16 15:46:16 +0900 (1e4cd30)
+++ lib/proc.c    2012-08-16 16:18:16 +0900 (32be4f1)
@@ -264,20 +264,21 @@ grn_parse_query_flags(grn_ctx *ctx, const char *query_flags,
       (!memcmp(query_flags, #name, sizeof(#name) - 1))) {\
     flags |= GRN_EXPR_ ## name;\
     query_flags += sizeof(#name);\
-    break;\
+    continue;\
   }
-    switch (*query_flags) {
-    case 'A' :
-      CHECK_EXPR_FLAG(ALLOW_PRAGMA);
-      CHECK_EXPR_FLAG(ALLOW_COLUMN);
-      CHECK_EXPR_FLAG(ALLOW_UPDATE);
-    default :
-      ERR(GRN_INVALID_ARGUMENT, "invalid query flag: <%.*s>",
-          (int)(query_flags_end - query_flags), query_flags);
-      return 0;
-    }
-#undef CHECK_EXPR_FLAG
 
+    CHECK_EXPR_FLAG(ALLOW_PRAGMA);
+    CHECK_EXPR_FLAG(ALLOW_COLUMN);
+    CHECK_EXPR_FLAG(ALLOW_UPDATE);
+
+#define GRN_EXPR_NONE 0
+    CHECK_EXPR_FLAG(NONE);
+#undef GNR_EXPR_NONE
+
+    ERR(GRN_INVALID_ARGUMENT, "invalid query flag: <%.*s>",
+        (int)(query_flags_end - query_flags), query_flags);
+    return 0;
+#undef CHECK_EXPR_FLAG
   }
 
   return flags;

  Added: test/function/suite/select/query_flags/none.expected (+55 -0) 100644
===================================================================
--- /dev/null
+++ test/function/suite/select/query_flags/none.expected    2012-08-16 16:18:16 +0900 (f87aca7)
@@ -0,0 +1,55 @@
+table_create Users TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Users age COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create Users description COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+table_create Terms TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigramSplitSymbolAlphaDigit
+[[0,0.0,0.0],true]
+column_create Terms description_index COLUMN_INDEX|WITH_POSITION Users description
+[[0,0.0,0.0],true]
+load --table Users
+[
+{"_key": "alice", "age": 18, "description": "brother's age:20"},
+{"_key": "bob",   "age": 20, "description": "sister's age:18"}
+]
+[[0,0.0,0.0],2]
+select Users   --match_columns "description"   --query "age:18"   --query_flags "NONE"
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "age",
+          "UInt32"
+        ],
+        [
+          "description",
+          "ShortText"
+        ]
+      ],
+      [
+        2,
+        "bob",
+        20,
+        "sister's age:18"
+      ]
+    ]
+  ]
+]

  Added: test/function/suite/select/query_flags/none.test (+17 -0) 100644
===================================================================
--- /dev/null
+++ test/function/suite/select/query_flags/none.test    2012-08-16 16:18:16 +0900 (7524df4)
@@ -0,0 +1,17 @@
+table_create Users TABLE_HASH_KEY ShortText
+column_create Users age COLUMN_SCALAR UInt32
+column_create Users description COLUMN_SCALAR ShortText
+
+table_create Terms TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigramSplitSymbolAlphaDigit
+column_create Terms description_index COLUMN_INDEX|WITH_POSITION Users description
+
+load --table Users
+[
+{"_key": "alice", "age": 18, "description": "brother's age:20"},
+{"_key": "bob",   "age": 20, "description": "sister's age:18"}
+]
+
+select Users \
+  --match_columns "description" \
+  --query "age:18" \
+  --query_flags "NONE"
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index