summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2ced8af)
raw | patch | inline | side by side (parent: 2ced8af)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 27 Jul 2014 16:42:23 +0000 (18:42 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 27 Jul 2014 16:42:23 +0000 (18:42 +0200) |
'WHERE' was too SQL-like while it has somewhat different semantics. Using a
different keyword will hopefully avoid any confusion.
different keyword will hopefully avoid any confusion.
diff --git a/doc/sysdbql.7.txt b/doc/sysdbql.7.txt
index c4f52a9a8c1110ac3880b7c03b849eeb6b75d991..447950d37ec00ad11c8dbd403212895e2be346a1 100644 (file)
--- a/doc/sysdbql.7.txt
+++ b/doc/sysdbql.7.txt
LIST;
- QUERY hosts WHERE attribute.architecture = 'amd64';
+ LOOKUP hosts MATCHING attribute.architecture = 'amd64';
DESCRIPTION
-----------
list of attributes for the host and each service. If the host does not exist,
an error is returned.
-*LOOKUP* hosts *WHERE* '<search_condition>'::
+*LOOKUP* hosts *MATCHING* '<search_condition>'::
Retrieve detailed information about all host objects matching the specified
search condition. The return value is a list of detailed information for each
matching host providing the same details as returned by the *FETCH* command.
-See the section "WHERE clause" for more details about how to specify the
+See the section "MATCHING clause" for more details about how to specify the
search condition.
-WHERE clause
-~~~~~~~~~~~~
-The *WHERE* clause in a query specifies a boolean expression which is used to
-match host objects based on their names, their attributes, or services
-referenced by the host. Each *WHERE* clause may be made up of one or multiple
-subexpressions each matching on one criteria. The following subexpressions
-are supported by SysDB:
+MATCHING clause
+~~~~~~~~~~~~~~~
+The *MATCHING* clause in a query specifies a boolean expression which is used
+to match host objects based on their names, their attributes, or services
+referenced by the host. Each *MATCHING* clause may be made up of one or
+multiple subexpressions each matching on one criteria. The following
+subexpressions are supported by SysDB:
'<field>' '<operator>' '<value>'::
Match a named field against the specified value. See below for what fields
...
}]}
- LOOKUP hosts WHERE attribute.architecture = 'amd64';
+ LOOKUP hosts MATCHING attribute.architecture = 'amd64';
[{
"name": "host1.example.com",
"last_update": "2001-02-03 04:05:06 +0700",
diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index d5054854c3153a1298a238ad1bee2026a965cd51..74e28dd837f7e8eb7a819e1a0a4ed2ebda032ffb 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
%token SCANNER_ERROR
-%token AND OR IS NOT WHERE
+%token AND OR IS NOT MATCHING
%token CMP_EQUAL CMP_NEQUAL CMP_REGEX CMP_NREGEX
%token CMP_LT CMP_LE CMP_GE CMP_GT
;
/*
- * LOOKUP <type> WHERE <expression>;
+ * LOOKUP <type> MATCHING <expression>;
*
* Returns detailed information about <type> matching expression.
*/
lookup_statement:
- LOOKUP IDENTIFIER WHERE expression
+ LOOKUP IDENTIFIER MATCHING expression
{
/* TODO: support other types as well */
if (strcasecmp($2, "hosts")) {
diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l
index a7b72b43794541985e722ca2f2c6ea3a61848e12..ef30682b45b837f8cb931f1e7257f7568ddd3f2b 100644 (file)
--- a/src/frontend/scanner.l
+++ b/src/frontend/scanner.l
return LIST;
else if (! strcasecmp(yytext, "LOOKUP"))
return LOOKUP;
+ else if (! strcasecmp(yytext, "MATCHING"))
+ return MATCHING;
else if (! strcasecmp(yytext, "NOT"))
return NOT;
else if (! strcasecmp(yytext, "NULL"))
return NULL_T;
else if (! strcasecmp(yytext, "OR"))
return OR;
- else if (! strcasecmp(yytext, "WHERE"))
- return WHERE;
yylval->str = strdup(yytext);
return IDENTIFIER;
index ef12bf8f2dbf1a735ff284c7cfb8b084b19098c9..6d7f5e5d9af9228b2b20e40e66b4bb0d62b976bb 100755 (executable)
echo "$output" | grep -F 'not found'
output="$( run_sysdb -H "$SOCKET_FILE" \
- -c "LOOKUP hosts WHERE attribute.architecture = 'x42'" )"
+ -c "LOOKUP hosts MATCHING attribute.architecture = 'x42'" )"
echo "$output" \
| grep -F '"host1.example.com"' \
| grep -F '"host2.example.com"'
echo "$output" | grep -F 'some.host.name' && exit 1
output="$( run_sysdb -H "$SOCKET_FILE" \
- -c "LOOKUP hosts WHERE attribute != 'architecture'" )"
+ -c "LOOKUP hosts MATCHING attribute != 'architecture'" )"
echo "$output" \
| grep -F '"some.host.name"' \
| grep -F '"localhost"'
echo "$output" | grep -F 'host2.example.com' && exit 1
output="$( run_sysdb -H "$SOCKET_FILE" \
- -c "LOOKUP hosts WHERE service = 'sysdbd'" )"
+ -c "LOOKUP hosts MATCHING service = 'sysdbd'" )"
echo "$output" | grep -F '"localhost"'
echo "$output" | grep -F 'some.host.name' && exit 1
echo "$output" | grep -F 'other.host.name' && exit 1
echo "$output" | grep -F 'host2.example.com' && exit 1
output="$( run_sysdb -H "$SOCKET_FILE" \
- -c "LOOKUP hosts WHERE host =~ 'example.com'" )"
+ -c "LOOKUP hosts MATCHING host =~ 'example.com'" )"
echo "$output" \
| grep -F '"host1.example.com"' \
| grep -F '"host2.example.com"'
# When querying hosts that don't exist, expect a zero exit code.
output="$( run_sysdb -H "$SOCKET_FILE" \
- -c "LOOKUP hosts WHERE attribute.invalid = 'none'" )"
+ -c "LOOKUP hosts MATCHING attribute.invalid = 'none'" )"
echo $output | grep -E '^\[\]$'
stop_sysdbd
index f1e656982cbb21de211fd850b64e456da68ee84f..3ca27ba19ffb47ec637575469b398c7d85d10961 100644 (file)
{ "LIST;", -1, 1, CONNECTION_LIST },
{ "LIST; INVALID", 5, 1, CONNECTION_LIST },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"host = 'host'", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE NOT "
+ { "LOOKUP hosts MATCHING NOT "
"host = 'host'", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"host =~ 'p' AND "
"service =~ 'p'", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE NOT "
+ { "LOOKUP hosts MATCHING NOT "
"host =~ 'p' AND "
"service =~ 'p'", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"host =~ 'p' AND "
"service =~ 'p' OR "
"service =~ 'r'", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE NOT "
+ { "LOOKUP hosts MATCHING NOT "
"host =~ 'p' AND "
"service =~ 'p' OR "
"service =~ 'r'", -1, 1, CONNECTION_LOOKUP },
/* numeric constants */
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo = "
"1234", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo != "
"+234", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo < "
"-234", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo > "
"12.4", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo <= "
"12.", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo >= "
".4", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo = "
"+12e3", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo = "
"+12e-3", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo = "
"-12e+3", -1, 1, CONNECTION_LOOKUP },
/* NULL */
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo "
"IS NULL", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo "
"IS NOT NULL", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"NOT attribute.foo "
"IS NULL", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"host IS NULL", -1, -1, 0 },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"service IS NULL", -1, -1, 0 },
/* invalid numeric constants */
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo = "
"+-12e+3", -1, -1, 0 },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo = "
"-12e-+3", -1, -1, 0 },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo = "
"e+3", -1, -1, 0 },
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo = "
"3e", -1, -1, 0 },
/* following SQL standard, we don't support hex numbers */
- { "LOOKUP hosts WHERE "
+ { "LOOKUP hosts MATCHING "
"attribute.foo = "
"0x12", -1, -1, 0 },
{ "/* some incomplete", -1, -1, 0 },
{ "LOOKUP hosts", -1, -1, 0 },
- { "LOOKUP foo WHERE "
+ { "LOOKUP foo MATCHING "
"host = 'host'", -1, -1, 0 },
};