當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.EmptyResultSet方法代碼示例

本文整理匯總了Python中django.core.exceptions.EmptyResultSet方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.EmptyResultSet方法的具體用法?Python exceptions.EmptyResultSet怎麽用?Python exceptions.EmptyResultSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.exceptions的用法示例。


在下文中一共展示了exceptions.EmptyResultSet方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_empty_full_handling_conjunction

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def test_empty_full_handling_conjunction(self):
        if django.VERSION < (1, 11, 0):
            self.skipTest("does not work on older Django")
        compiler = WhereNodeTest.MockCompiler()
        w = WhereNode(children=[NothingNode()])
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection)
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('', []))
        w = WhereNode(children=[self.DummyNode(), self.DummyNode()])
        self.assertEqual(w.as_sql(compiler, connection), ('(dummy AND dummy)', []))
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('NOT (dummy AND dummy)', []))
        w = WhereNode(children=[NothingNode(), self.DummyNode()])
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection)
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('', [])) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:20,代碼來源:tests.py

示例2: test_empty_full_handling_disjunction

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def test_empty_full_handling_disjunction(self):
        if django.VERSION < (1, 11, 0):
            self.skipTest("does not work on older Django")
        compiler = WhereNodeTest.MockCompiler()
        w = WhereNode(children=[NothingNode()], connector='OR')
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection)
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('', []))
        w = WhereNode(children=[self.DummyNode(), self.DummyNode()], connector='OR')
        self.assertEqual(w.as_sql(compiler, connection), ('(dummy OR dummy)', []))
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('NOT (dummy OR dummy)', []))
        w = WhereNode(children=[NothingNode(), self.DummyNode()], connector='OR')
        self.assertEqual(w.as_sql(compiler, connection), ('dummy', []))
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('NOT (dummy)', [])) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:19,代碼來源:tests.py

示例3: test_empty_nodes

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def test_empty_nodes(self):
        if django.VERSION < (1, 11, 0):
            self.skipTest("does not work on older Django")
        compiler = WhereNodeTest.MockCompiler()
        empty_w = WhereNode()
        w = WhereNode(children=[empty_w, empty_w])
        self.assertEqual(w.as_sql(compiler, connection), ('', []))
        w.negate()
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection)
        w.connector = 'OR'
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection)
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('', []))
        w = WhereNode(children=[empty_w, NothingNode()], connector='OR')
        self.assertEqual(w.as_sql(compiler, connection), ('', []))
        w = WhereNode(children=[empty_w, NothingNode()], connector='AND')
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:22,代碼來源:tests.py

示例4: test_empty_full_handling_conjunction

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def test_empty_full_handling_conjunction(self):
        compiler = WhereNodeTest.MockCompiler()
        w = WhereNode(children=[NothingNode()])
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection)
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('', []))
        w = WhereNode(children=[self.DummyNode(), self.DummyNode()])
        self.assertEqual(w.as_sql(compiler, connection), ('(dummy AND dummy)', []))
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('NOT (dummy AND dummy)', []))
        w = WhereNode(children=[NothingNode(), self.DummyNode()])
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection)
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('', [])) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:tests.py

示例5: test_empty_nodes

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def test_empty_nodes(self):
        compiler = WhereNodeTest.MockCompiler()
        empty_w = WhereNode()
        w = WhereNode(children=[empty_w, empty_w])
        self.assertEqual(w.as_sql(compiler, connection), ('', []))
        w.negate()
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection)
        w.connector = 'OR'
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection)
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('', []))
        w = WhereNode(children=[empty_w, NothingNode()], connector='OR')
        self.assertEqual(w.as_sql(compiler, connection), ('', []))
        w = WhereNode(children=[empty_w, NothingNode()], connector='AND')
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:20,代碼來源:tests.py

示例6: as_sql

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def as_sql(self, compiler, connection, template=None, case_joiner=None, **extra_context):
        connection.ops.check_expression_support(self)
        if not self.cases:
            return compiler.compile(self.default)
        template_params = self.extra.copy()
        template_params.update(extra_context)
        case_parts = []
        sql_params = []
        for case in self.cases:
            try:
                case_sql, case_params = compiler.compile(case)
            except EmptyResultSet:
                continue
            case_parts.append(case_sql)
            sql_params.extend(case_params)
        default_sql, default_params = compiler.compile(self.default)
        if not case_parts:
            return default_sql, default_params
        case_joiner = case_joiner or self.case_joiner
        template_params['cases'] = case_joiner.join(case_parts)
        template_params['default'] = default_sql
        sql_params.extend(default_params)
        template = template or template_params.get('template', self.template)
        sql = template % template_params
        if self._output_field_or_none is not None:
            sql = connection.ops.unification_cast_sql(self.output_field) % sql
        return sql, sql_params 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:29,代碼來源:expressions.py

示例7: get_combinator_sql

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def get_combinator_sql(self, combinator, all):
        features = self.connection.features
        compilers = [
            query.get_compiler(self.using, self.connection)
            for query in self.query.combined_queries if not query.is_empty()
        ]
        if not features.supports_slicing_ordering_in_compound:
            for query, compiler in zip(self.query.combined_queries, compilers):
                if query.low_mark or query.high_mark:
                    raise DatabaseError('LIMIT/OFFSET not allowed in subqueries of compound statements.')
                if compiler.get_order_by():
                    raise DatabaseError('ORDER BY not allowed in subqueries of compound statements.')
        parts = ()
        for compiler in compilers:
            try:
                # If the columns list is limited, then all combined queries
                # must have the same columns list. Set the selects defined on
                # the query on all combined queries, if not already set.
                if not compiler.query.values_select and self.query.values_select:
                    compiler.query.set_values(self.query.values_select)
                parts += (compiler.as_sql(),)
            except EmptyResultSet:
                # Omit the empty queryset with UNION and with DIFFERENCE if the
                # first queryset is nonempty.
                if combinator == 'union' or (combinator == 'difference' and parts):
                    continue
                raise
        if not parts:
            raise EmptyResultSet
        combinator_sql = self.connection.ops.set_operators[combinator]
        if all and combinator == 'union':
            combinator_sql += ' ALL'
        braces = '({})' if features.supports_slicing_ordering_in_compound else '{}'
        sql_parts, args_parts = zip(*((braces.format(sql), args) for sql, args in parts))
        result = [' {} '.format(combinator_sql).join(sql_parts)]
        params = []
        for part in args_parts:
            params.extend(part)
        return result, params 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:41,代碼來源:compiler.py

示例8: as_sql

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def as_sql(self, compiler, connection, template=None, case_joiner=None, **extra_context):
        connection.ops.check_expression_support(self)
        if not self.cases:
            return compiler.compile(self.default)
        template_params = {**self.extra, **extra_context}
        case_parts = []
        sql_params = []
        for case in self.cases:
            try:
                case_sql, case_params = compiler.compile(case)
            except EmptyResultSet:
                continue
            case_parts.append(case_sql)
            sql_params.extend(case_params)
        default_sql, default_params = compiler.compile(self.default)
        if not case_parts:
            return default_sql, default_params
        case_joiner = case_joiner or self.case_joiner
        template_params['cases'] = case_joiner.join(case_parts)
        template_params['default'] = default_sql
        sql_params.extend(default_params)
        template = template or template_params.get('template', self.template)
        sql = template % template_params
        if self._output_field_or_none is not None:
            sql = connection.ops.unification_cast_sql(self.output_field) % sql
        return sql, sql_params 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:28,代碼來源:expressions.py

示例9: get_combinator_sql

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def get_combinator_sql(self, combinator, all):
        features = self.connection.features
        compilers = [
            query.get_compiler(self.using, self.connection)
            for query in self.query.combined_queries if not query.is_empty()
        ]
        if not features.supports_slicing_ordering_in_compound:
            for query, compiler in zip(self.query.combined_queries, compilers):
                if query.low_mark or query.high_mark:
                    raise DatabaseError('LIMIT/OFFSET not allowed in subqueries of compound statements.')
                if compiler.get_order_by():
                    raise DatabaseError('ORDER BY not allowed in subqueries of compound statements.')
        parts = ()
        for compiler in compilers:
            try:
                parts += (compiler.as_sql(),)
            except EmptyResultSet:
                # Omit the empty queryset with UNION and with DIFFERENCE if the
                # first queryset is nonempty.
                if combinator == 'union' or (combinator == 'difference' and parts):
                    continue
                raise
        if not parts:
            raise EmptyResultSet
        combinator_sql = self.connection.ops.set_operators[combinator]
        if all and combinator == 'union':
            combinator_sql += ' ALL'
        braces = '({})' if features.supports_slicing_ordering_in_compound else '{}'
        sql_parts, args_parts = zip(*((braces.format(sql), args) for sql, args in parts))
        result = [' {} '.format(combinator_sql).join(sql_parts)]
        params = []
        for part in args_parts:
            params.extend(part)
        return result, params 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:36,代碼來源:compiler.py

示例10: test_ticket10181

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def test_ticket10181(self):
        # Avoid raising an EmptyResultSet if an inner query is probably
        # empty (and hence, not executed).
        self.assertQuerysetEqual(
            Tag.objects.filter(id__in=Tag.objects.filter(id__in=[])),
            []
        ) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:9,代碼來源:tests.py

示例11: test_empty_full_handling_disjunction

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def test_empty_full_handling_disjunction(self):
        compiler = WhereNodeTest.MockCompiler()
        w = WhereNode(children=[NothingNode()], connector='OR')
        with self.assertRaises(EmptyResultSet):
            w.as_sql(compiler, connection)
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('', []))
        w = WhereNode(children=[self.DummyNode(), self.DummyNode()], connector='OR')
        self.assertEqual(w.as_sql(compiler, connection), ('(dummy OR dummy)', []))
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('NOT (dummy OR dummy)', []))
        w = WhereNode(children=[NothingNode(), self.DummyNode()], connector='OR')
        self.assertEqual(w.as_sql(compiler, connection), ('dummy', []))
        w.negate()
        self.assertEqual(w.as_sql(compiler, connection), ('NOT (dummy)', [])) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:17,代碼來源:tests.py

示例12: as_sql

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def as_sql(self, compiler, connection):
        """
        Return the SQL version of the where clause and the value to be
        substituted in. Return '', [] if this node matches everything,
        None, [] if this node is empty, and raise EmptyResultSet if this
        node can't match anything.
        """
        result = []
        result_params = []
        if self.connector == AND:
            full_needed, empty_needed = len(self.children), 1
        else:
            full_needed, empty_needed = 1, len(self.children)

        for child in self.children:
            try:
                sql, params = compiler.compile(child)
            except EmptyResultSet:
                empty_needed -= 1
            else:
                if sql:
                    result.append(sql)
                    result_params.extend(params)
                else:
                    full_needed -= 1
            # Check if this node matches nothing or everything.
            # First check the amount of full nodes and empty nodes
            # to make this node empty/full.
            # Now, check if this node is full/empty using the
            # counts.
            if empty_needed == 0:
                if self.negated:
                    return '', []
                else:
                    raise EmptyResultSet
            if full_needed == 0:
                if self.negated:
                    raise EmptyResultSet
                else:
                    return '', []
        conn = ' %s ' % self.connector
        sql_string = conn.join(result)
        if sql_string:
            if self.negated:
                # Some backends (Oracle at least) need parentheses
                # around the inner SQL in the negated case, even if the
                # inner SQL contains just a single expression.
                sql_string = 'NOT (%s)' % sql_string
            elif len(result) > 1 or self.resolved:
                sql_string = '(%s)' % sql_string
        return sql_string, result_params 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:53,代碼來源:where.py

示例13: get_combinator_sql

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def get_combinator_sql(self, combinator, all):
        features = self.connection.features
        compilers = [
            query.get_compiler(self.using, self.connection)
            for query in self.query.combined_queries if not query.is_empty()
        ]
        if not features.supports_slicing_ordering_in_compound:
            for query, compiler in zip(self.query.combined_queries, compilers):
                if query.low_mark or query.high_mark:
                    raise DatabaseError('LIMIT/OFFSET not allowed in subqueries of compound statements.')
                if compiler.get_order_by():
                    raise DatabaseError('ORDER BY not allowed in subqueries of compound statements.')
        parts = ()
        for compiler in compilers:
            try:
                # If the columns list is limited, then all combined queries
                # must have the same columns list. Set the selects defined on
                # the query on all combined queries, if not already set.
                if not compiler.query.values_select and self.query.values_select:
                    compiler.query.set_values((
                        *self.query.extra_select,
                        *self.query.values_select,
                        *self.query.annotation_select,
                    ))
                parts += (compiler.as_sql(),)
            except EmptyResultSet:
                # Omit the empty queryset with UNION and with DIFFERENCE if the
                # first queryset is nonempty.
                if combinator == 'union' or (combinator == 'difference' and parts):
                    continue
                raise
        if not parts:
            raise EmptyResultSet
        combinator_sql = self.connection.ops.set_operators[combinator]
        if all and combinator == 'union':
            combinator_sql += ' ALL'
        braces = '({})' if features.supports_slicing_ordering_in_compound else '{}'
        sql_parts, args_parts = zip(*((braces.format(sql), args) for sql, args in parts))
        result = [' {} '.format(combinator_sql).join(sql_parts)]
        params = []
        for part in args_parts:
            params.extend(part)
        return result, params 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:45,代碼來源:compiler.py

示例14: as_sql

# 需要導入模塊: from django.core import exceptions [as 別名]
# 或者: from django.core.exceptions import EmptyResultSet [as 別名]
def as_sql(self, compiler, connection):
        """
        Returns the SQL version of the where clause and the value to be
        substituted in. Returns '', [] if this node matches everything,
        None, [] if this node is empty, and raises EmptyResultSet if this
        node can't match anything.
        """
        result = []
        result_params = []
        if self.connector == AND:
            full_needed, empty_needed = len(self.children), 1
        else:
            full_needed, empty_needed = 1, len(self.children)

        for child in self.children:
            try:
                sql, params = compiler.compile(child)
            except EmptyResultSet:
                empty_needed -= 1
            else:
                if sql:
                    result.append(sql)
                    result_params.extend(params)
                else:
                    full_needed -= 1
            # Check if this node matches nothing or everything.
            # First check the amount of full nodes and empty nodes
            # to make this node empty/full.
            # Now, check if this node is full/empty using the
            # counts.
            if empty_needed == 0:
                if self.negated:
                    return '', []
                else:
                    raise EmptyResultSet
            if full_needed == 0:
                if self.negated:
                    raise EmptyResultSet
                else:
                    return '', []
        conn = ' %s ' % self.connector
        sql_string = conn.join(result)
        if sql_string:
            if self.negated:
                # Some backends (Oracle at least) need parentheses
                # around the inner SQL in the negated case, even if the
                # inner SQL contains just a single expression.
                sql_string = 'NOT (%s)' % sql_string
            elif len(result) > 1:
                sql_string = '(%s)' % sql_string
        return sql_string, result_params 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:53,代碼來源:where.py


注:本文中的django.core.exceptions.EmptyResultSet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。