示例#1
0
    def select_any(self):
        saved_match = self.tokens.matched
        # Any can be either a start of a pseudosql query or the any builtin.
        if self.tokens.match(common_grammar.lparen):
            self.tokens.matched = saved_match
            # The paren means we're calling 'any(...)' - the builtin.
            return self.builtin(self.tokens.matched.value)

        # An optional FROM can go after ANY.
        # "SELECT ANY FROM", "ANY FROM", "SELECT ANY" and just "ANY" all mean
        # the exact same thing. The full form of SELECT ANY FROM is preferred
        # but the shorthand is very useful for writing boolean indicators and
        # so it's worth allowing it.
        start = self.tokens.matched.start
        self.tokens.accept(grammar.select_from)

        source_expression = self.expression()

        if self.tokens.accept(grammar.select_where):
            map_expression = self.expression()
        else:
            map_expression = None

        # ORDER after ANY doesn't make any sense.
        self.tokens.reject(grammar.select_order)

        if map_expression:
            return ast.Any(source_expression, map_expression,
                           start=start, end=map_expression.end,
                           source=self.original)

        return ast.Any(source_expression, start=start,
                       end=self.tokens.matched.end, source=self.original)
示例#2
0
    def testSelectAny(self):
        self.assertQueryMatches("SELECT ANY FROM pslist()",
                                ast.Any(ast.Apply(ast.Var("pslist"))))

        # Shorthands for any should work.
        self.assertQueryMatches("SELECT ANY FROM pslist()",
                                ast.Any(ast.Apply(ast.Var("pslist"))))

        self.assertQueryMatches("ANY pslist()",
                                ast.Any(ast.Apply(ast.Var("pslist"))))

        # Any doesn't allow ORDER BY.
        self.assertQueryRaises("SELECT ANY FROM pslist() ORDER BY pid")
示例#3
0
    def testAny(self):
        self.assertTrue(
            solve.solve(
                q.Query("any Process.parent where (pid == 1)"), {
                    "Process": {
                        "parent":
                        repeated.meld(mocks.Process(1, None, None),
                                      mocks.Process(2, None, None))
                    }
                }).value)

        # Test that unary ANY works as expected.
        query = q.Query(ast.Any(ast.Var("x")))
        self.assertFalse(solve.solve(query, {"x": None}).value)
        self.assertTrue(solve.solve(query, {"x": 1}).value)
        self.assertTrue(
            solve.solve(query, {
                "x": repeated.meld(1, 2, 3)
            }).value)
示例#4
0
 def testSelectAnyWhere(self):
     self.assertQueryMatches(
         "SELECT ANY FROM pslist() WHERE pid == 1",
         ast.Any(ast.Apply(ast.Var("pslist")),
                 ast.Equivalence(ast.Var("pid"), ast.Literal(1))))
示例#5
0
 def testAnyBuiltin(self):
     self.assertQueryMatches(
         "any(x) and any(y)",
         ast.Intersection(ast.Any(ast.Var("x")), ast.Any(ast.Var("y"))))