Ticket #25705: ticket25705.patch

File ticket25705.patch, 4.8 KB (added by Dmitry Dygalo, 9 years ago)

Initial draft

  • django/db/backends/base/operations.py

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    313313        """
    314314        raise NotImplementedError('subclasses of BaseDatabaseOperations may require a quote_name() method')
    315315
     316    def adapt_param(self, param):
     317        """
     318        Returns adapted version of parameter.
     319        """
     320        return param
     321
    316322    def random_function_sql(self):
    317323        """
    318324        Returns an SQL expression that returns a random value.
  • django/db/backends/postgresql/operations.py

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    11from __future__ import unicode_literals
    22
     3from psycopg2.extensions import adapt
    34from psycopg2.extras import Inet
    45
    56from django.conf import settings
     
    9394        if name.startswith('"') and name.endswith('"'):
    9495            return name  # Quoting once is enough.
    9596        return '"%s"' % name
     97
     98    def adapt_param(self, param):
     99        return adapt(param).getquoted()
    96100
    97101    def set_time_zone_sql(self):
    98102        return "SET TIME ZONE %s"
  • django/db/models/sql/compiler.py

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    476476            raise EmptyResultSet
    477477        return nested_sql
    478478
     479    def as_quoted_sql(self):
     480        """
     481        Returns SQL for this query with adapted parameters to use in string representation.
     482        """
     483        sql, params = self.as_sql()
     484        return sql, tuple(self.connection.ops.adapt_param(param) for param in params)
     485
    479486    def get_default_columns(self, start_alias=None, opts=None, from_parent=None):
    480487        """
    481488        Computes the default columns for selecting every field in the base
  • django/db/models/sql/query.py

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    216216        """
    217217        Returns the query as a string of SQL with the parameter values
    218218        substituted in (use sql_with_params() to see the unsubstituted string).
    219 
    220         Parameter values won't necessarily be quoted correctly, since that is
    221         done by the database interface at execution time.
    222219        """
    223220        sql, params = self.sql_with_params()
    224221        return sql % params
     
    228225        Returns the query as an SQL string and the parameters that will be
    229226        substituted into the query.
    230227        """
    231         return self.get_compiler(DEFAULT_DB_ALIAS).as_sql()
     228        return self.get_compiler(DEFAULT_DB_ALIAS).as_quoted_sql()
    232229
    233230    def __deepcopy__(self, memo):
    234231        result = self.clone(memo=memo)
  • tests/postgres_tests/test_ranges.py

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    630630            '<input type="text" name="datetimerange_0" value="2006-01-10 07:30:00" />'
    631631            '<input type="text" name="datetimerange_1" value="2006-02-12 09:50:00" />'
    632632        )
     633
     634
     635class TestRepresentation(PostgreSQLTestCase):
     636
     637    def test_numeric_range(self):
     638        self.assertEqual(
     639            str(RangesModel.objects.filter(ints__overlap=NumericRange(1, 5)).query),
     640            'SELECT "postgres_tests_rangesmodel"."id", "postgres_tests_rangesmodel"."ints", '
     641            '"postgres_tests_rangesmodel"."bigints", "postgres_tests_rangesmodel"."floats", '
     642            '"postgres_tests_rangesmodel"."timestamps", "postgres_tests_rangesmodel"."dates" '
     643            'FROM "postgres_tests_rangesmodel" WHERE "postgres_tests_rangesmodel"."ints" && \'[1,5)\''
     644        )
Back to Top