Esempio n. 1
0
 def _parse(self, query_string):
     try:
         ast = sqlparse.parse_string(query_string)
     except pyparsing.ParseException, err:
         msg = ["Parse Error: %s" % err, query_string, "-" * (err.col - 1) + "^"]
         logger.error("\n".join(msg))
         raise
Esempio n. 2
0
 def _parse(self, query_string):
     try:
         ast = sqlparse.parse_string(query_string)
     except pyparsing.ParseException, err:
         msg = [
             'Parse Error: %s' % err,
             query_string,
             '-' * (err.col - 1) + '^',
         ]
         logger.error('\n'.join(msg))
         raise
Esempio n. 3
0
    def parse_and_build(self, query_string):
        parse_tree = sqlparse.parse_string(query_string)
        filter_options = {}

        # collections
        self.model_class = self._get_collection_name(parse_tree)
        self.class_names = [self.model_class]

        # fields
        filter_fields = self._get_fields_option(parse_tree)
        self.fields = filter_fields.keys()
        if filter_fields:
            filter_options['fields'] = filter_fields

        return self._get_filter_criteria(parse_tree), filter_options
Esempio n. 4
0
    def parse_and_build(self, query_string):
        parse_tree = sqlparse.parse_string(query_string)
        filter_options = {}

        # collections
        self.model_class = self._get_collection_name(parse_tree)
        self.class_names = [ self.model_class ]

        # fields
        filter_fields = self._get_fields_option(parse_tree)
        self.fields = filter_fields.keys()
        if filter_fields:
            filter_options['fields'] = filter_fields

        return self._get_filter_criteria(parse_tree), filter_options
Esempio n. 5
0
    def assertParses(self, inputStr, expectError=False):
        """
        parses :inputStr: and assets the parse succeeded
        (or failed if :expectError: is True)

        returns ParseResults with parse tree

        parameters
        ----------
        inputStr : str
            query string to parse
        expectError : bool
            is this an intentionally malformed inputStr?
            if so, suppresses the ParseException
        """
        if isinstance(inputStr, list):
            return map(lambda i: self.assertParses(i, expectError=expectError),
                       inputStr)

        try:
            if self.PRINT_PARSE_RESULTS and not expectError:
                print
                print inputStr

            tokens = sqlparse.parse_string(inputStr)
            if self.PRINT_PARSE_RESULTS and not expectError:
                print tokens.asXML('query')
                #print tokens.where.dump()

            #print tokens.where.dump()

            self.assertFalse(expectError,
                             inputStr)  # parsed without error = pass
            return tokens

        except ParseException, err:
            if self.PRINT_PARSE_RESULTS and not expectError:
                #print '%s' % err.line
                print '-' * (err.col - 1) + '^'
                print 'ERROR: %s' % err
            self.assertTrue(expectError, '%s, parsing "%s"' % (err, inputStr))
Esempio n. 6
0
    def assertParses(self, inputStr, expectError=False):
        """
        parses :inputStr: and assets the parse succeeded
        (or failed if :expectError: is True)

        returns ParseResults with parse tree

        parameters
        ----------
        inputStr : str
            query string to parse
        expectError : bool
            is this an intentionally malformed inputStr?
            if so, suppresses the ParseException
        """
        if isinstance(inputStr, list):
            return map(lambda i: self.assertParses(i, expectError=expectError), inputStr)

        try:
            if self.PRINT_PARSE_RESULTS and not expectError:
                print
                print inputStr

            tokens = sqlparse.parse_string(inputStr)
            if self.PRINT_PARSE_RESULTS and not expectError:
                print tokens.asXML('query')
                #print tokens.where.dump()

            #print tokens.where.dump()

            self.assertFalse(expectError, inputStr) # parsed without error = pass
            return tokens

        except ParseException, err:
            if self.PRINT_PARSE_RESULTS and not expectError:
                #print '%s' % err.line
                print '-' * (err.col - 1) + '^'
                print 'ERROR: %s' % err
            self.assertTrue(expectError, '%s, parsing "%s"' % (err, inputStr))