예제 #1
0
    def test_lookup_cast(self):
        from django.db.backends.postgresql.operations import DatabaseOperations

        do = DatabaseOperations(connection=None)
        for lookup in ('iexact', 'contains', 'icontains', 'startswith',
                       'istartswith', 'endswith', 'iendswith', 'regex', 'iregex'):
            self.assertIn('::text', do.lookup_cast(lookup))
예제 #2
0
파일: tests.py 프로젝트: Brian-Rono/django
    def test_lookup_cast(self):
        from django.db.backends.postgresql.operations import DatabaseOperations

        do = DatabaseOperations(connection=None)
        for lookup in ('iexact', 'contains', 'icontains', 'startswith',
                       'istartswith', 'endswith', 'iendswith', 'regex', 'iregex'):
            self.assertIn('::text', do.lookup_cast(lookup))
예제 #3
0
파일: tests.py 프로젝트: Birama0810/Django
 def test_lookup_cast(self):
     from django.db.backends.postgresql.operations import DatabaseOperations
     do = DatabaseOperations(connection=None)
     lookups = (
         'iexact', 'contains', 'icontains', 'startswith', 'istartswith',
         'endswith', 'iendswith', 'regex', 'iregex',
     )
     for lookup in lookups:
         with self.subTest(lookup=lookup):
             self.assertIn('::text', do.lookup_cast(lookup))
     for lookup in lookups:
         for field_type in ('CICharField', 'CIEmailField', 'CITextField'):
             with self.subTest(lookup=lookup, field_type=field_type):
                 self.assertIn('::citext', do.lookup_cast(lookup, internal_type=field_type))
예제 #4
0
 def test_lookup_cast(self):
     from django.db.backends.postgresql.operations import DatabaseOperations
     do = DatabaseOperations(connection=None)
     lookups = (
         'iexact', 'contains', 'icontains', 'startswith', 'istartswith',
         'endswith', 'iendswith', 'regex', 'iregex',
     )
     for lookup in lookups:
         with self.subTest(lookup=lookup):
             self.assertIn('::text', do.lookup_cast(lookup))
     for lookup in lookups:
         for field_type in ('CICharField', 'CIEmailField', 'CITextField'):
             with self.subTest(lookup=lookup, field_type=field_type):
                 self.assertIn('::citext', do.lookup_cast(lookup, internal_type=field_type))
예제 #5
0
    def __init__(self, *args, **kwargs):
        super(DatabaseWrapper, self).__init__(*args, **kwargs)

        self.features = DatabaseFeatures()
        self.ops = DatabaseOperations(self)
        self.client = DatabaseClient(self)
        self.creation = DatabaseCreation(self)
        self.introspection = DatabaseIntrospection(self)
        self.validation = BaseDatabaseValidation(self)
예제 #6
0
class DatabaseWrapper(BaseDatabaseWrapper):
    features = DatabaseFeatures()
    ops = DatabaseOperations()
    operators = {
        'exact': '= %s',
        'iexact': 'ILIKE %s',
        'contains': 'LIKE %s',
        'icontains': 'ILIKE %s',
        'regex': '~ %s',
        'iregex': '~* %s',
        'gt': '> %s',
        'gte': '>= %s',
        'lt': '< %s',
        'lte': '<= %s',
        'startswith': 'LIKE %s',
        'endswith': 'LIKE %s',
        'istartswith': 'ILIKE %s',
        'iendswith': 'ILIKE %s',
    }

    def _cursor(self, settings):
        set_tz = False
        if self.connection is None:
            set_tz = True
            if settings.DATABASE_NAME == '':
                from django.core.exceptions import ImproperlyConfigured
                raise ImproperlyConfigured(
                    "You need to specify DATABASE_NAME in your Django settings file."
                )
            host = settings.DATABASE_HOST or 'localhost'
            port = settings.DATABASE_PORT and (':' +
                                               settings.DATABASE_PORT) or ''
            conn_string = "jdbc:postgresql://%s%s/%s" % (
                host, port, settings.DATABASE_NAME)
            self.connection = Database.connect(conn_string,
                                               settings.DATABASE_USER,
                                               settings.DATABASE_PASSWORD,
                                               'org.postgresql.Driver',
                                               **self.options)
            # make transactions transparent to all cursors
            from java.sql import Connection
            jdbc_conn = self.connection.__connection__
            jdbc_conn.setTransactionIsolation(
                Connection.TRANSACTION_READ_COMMITTED)
        real_cursor = self.connection.cursor()
        # setup the JDBC3 DataHandler and our data handler
        real_cursor.datahandler = JDBC30DataHandler(
            DjangoDataHandler(real_cursor.datahandler))
        cursor = CursorWrapper(real_cursor)
        if set_tz:
            # XXX: settings.TIME_ZONE could inject SQL
            #      Does it matter? If someone can edit settings.py, it already
            #      have the user and password!
            cursor.execute("SET TIME ZONE %s" %
                           self.ops.quote_name(settings.TIME_ZONE))

        return cursor
예제 #7
0
파일: base.py 프로젝트: raj88iitr/applause
    def __init__(self, *args, **kwargs):
        super(DatabaseWrapper, self).__init__(*args, **kwargs)

        import warnings
        warnings.warn(
            'The "postgresql" backend has been deprecated. Use "postgresql_psycopg2" instead.',
            DeprecationWarning)

        self.features = DatabaseFeatures(self)
        self.ops = DatabaseOperations(self)
        self.client = DatabaseClient(self)
        self.creation = DatabaseCreation(self)
        self.introspection = DatabaseIntrospection(self)
        self.validation = BaseDatabaseValidation(self)
예제 #8
0
    def test_lookup_cast(self):
        from django.db.backends.postgresql.operations import DatabaseOperations

        do = DatabaseOperations(connection=None)
        lookups = (
            "iexact",
            "contains",
            "icontains",
            "startswith",
            "istartswith",
            "endswith",
            "iendswith",
            "regex",
            "iregex",
        )
        for lookup in lookups:
            with self.subTest(lookup=lookup):
                self.assertIn("::text", do.lookup_cast(lookup))
        for lookup in lookups:
            for field_type in ("CICharField", "CIEmailField", "CITextField"):
                with self.subTest(lookup=lookup, field_type=field_type):
                    self.assertIn(
                        "::citext",
                        do.lookup_cast(lookup, internal_type=field_type))
예제 #9
0
class DatabaseWrapper(BaseDatabaseWrapper):
    features = DatabaseFeatures()
    ops = DatabaseOperations()
    operators = {
        'exact': '= %s',
        'iexact': 'ILIKE %s',
        'contains': 'LIKE %s',
        'icontains': 'ILIKE %s',
        'regex': '~ %s',
        'iregex': '~* %s',
        'gt': '> %s',
        'gte': '>= %s',
        'lt': '< %s',
        'lte': '<= %s',
        'startswith': 'LIKE %s',
        'endswith': 'LIKE %s',
        'istartswith': 'ILIKE %s',
        'iendswith': 'ILIKE %s',
    }

    def _cursor(self, settings):
        set_tz = False
        if self.connection is None:
            set_tz = True
            if settings.DATABASE_NAME == '':
                from django.core.exceptions import ImproperlyConfigured
                raise ImproperlyConfigured(
                    "You need to specify DATABASE_NAME in your Django settings file."
                )
            conn_string = "dbname=%s" % settings.DATABASE_NAME
            if settings.DATABASE_USER:
                conn_string = "user=%s %s" % (settings.DATABASE_USER,
                                              conn_string)
            if settings.DATABASE_PASSWORD:
                conn_string += " password='******'" % settings.DATABASE_PASSWORD
            if settings.DATABASE_HOST:
                conn_string += " host=%s" % settings.DATABASE_HOST
            if settings.DATABASE_PORT:
                conn_string += " port=%s" % settings.DATABASE_PORT
            self.connection = Database.connect(conn_string, **self.options)
            self.connection.set_isolation_level(
                1)  # make transactions transparent to all cursors
        cursor = self.connection.cursor()
        if set_tz:
            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
        cursor.execute("SET client_encoding to 'UNICODE'")
        cursor = UnicodeCursorWrapper(cursor, 'utf-8')
        return cursor