Navigation Menu

Skip to content

Commit

Permalink
select query_flags: accept NONE for no flags
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 16, 2012
1 parent 29dc0de commit 639ec5c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 13 deletions.
5 changes: 4 additions & 1 deletion doc/source/reference/commands/select.txt
Expand Up @@ -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
-----
Expand Down Expand Up @@ -550,6 +550,7 @@ Here are available values:
* ``ALLOW_PRAGMA``
* ``ALLOW_COLUMN``
* ``ALLOW_UPDATE``
* ``NONE``

``ALLOW_PRAGMA`` enables pragma at the head of ``query``.

Expand All @@ -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``.

Expand Down
25 changes: 13 additions & 12 deletions lib/proc.c
Expand Up @@ -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;
Expand Down
55 changes: 55 additions & 0 deletions test/function/suite/select/query_flags/none.expected
@@ -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"
]
]
]
]
17 changes: 17 additions & 0 deletions test/function/suite/select/query_flags/none.test
@@ -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"

0 comments on commit 639ec5c

Please sign in to comment.