Implemented BaseDatabaseFeatures and changed all code to access it -- connection.features.foo instead of backend.foo

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5974 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-08-20 02:20:33 +00:00
parent 4f82250512
commit 1a8f9b2b97
12 changed files with 69 additions and 91 deletions

View File

@ -34,7 +34,7 @@ class Command(NoArgsCommand):
# Get a list of all existing database tables, # Get a list of all existing database tables,
# so we know what needs to be added. # so we know what needs to be added.
table_list = table_list() table_list = table_list()
if backend.uses_case_insensitive_names: if connection.features.uses_case_insensitive_names:
table_name_converter = str.upper table_name_converter = str.upper
else: else:
table_name_converter = lambda x: x table_name_converter = lambda x: x

View File

@ -15,12 +15,12 @@ def table_list():
def installed_models(table_list): def installed_models(table_list):
"Returns a set of all models that are installed, given a list of existing table names." "Returns a set of all models that are installed, given a list of existing table names."
from django.db import backend, models from django.db import connection, models
all_models = [] all_models = []
for app in models.get_apps(): for app in models.get_apps():
for model in models.get_models(app): for model in models.get_models(app):
all_models.append(model) all_models.append(model)
if backend.uses_case_insensitive_names: if connection.features.uses_case_insensitive_names:
converter = lambda x: x.upper() converter = lambda x: x.upper()
else: else:
converter = lambda x: x converter = lambda x: x
@ -110,7 +110,7 @@ def sql_delete(app, style):
table_names = introspection.get_table_list(cursor) table_names = introspection.get_table_list(cursor)
else: else:
table_names = [] table_names = []
if backend.uses_case_insensitive_names: if connection.features.uses_case_insensitive_names:
table_name_converter = str.upper table_name_converter = str.upper
else: else:
table_name_converter = lambda x: x table_name_converter = lambda x: x
@ -138,7 +138,7 @@ def sql_delete(app, style):
# Drop the table now # Drop the table now
output.append('%s %s;' % (style.SQL_KEYWORD('DROP TABLE'), output.append('%s %s;' % (style.SQL_KEYWORD('DROP TABLE'),
style.SQL_TABLE(qn(model._meta.db_table)))) style.SQL_TABLE(qn(model._meta.db_table))))
if backend.supports_constraints and model in references_to_delete: if connection.features.supports_constraints and model in references_to_delete:
for rel_class, f in references_to_delete[model]: for rel_class, f in references_to_delete[model]:
table = rel_class._meta.db_table table = rel_class._meta.db_table
col = f.column col = f.column
@ -232,11 +232,11 @@ def sql_model_create(model, style, known_models=set()):
field_output = [style.SQL_FIELD(qn(f.column)), field_output = [style.SQL_FIELD(qn(f.column)),
style.SQL_COLTYPE(col_type)] style.SQL_COLTYPE(col_type)]
field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or ''))) field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or '')))
if f.unique and (not f.primary_key or backend.allows_unique_and_pk): if f.unique and (not f.primary_key or connection.features.allows_unique_and_pk):
field_output.append(style.SQL_KEYWORD('UNIQUE')) field_output.append(style.SQL_KEYWORD('UNIQUE'))
if f.primary_key: if f.primary_key:
field_output.append(style.SQL_KEYWORD('PRIMARY KEY')) field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
if tablespace and backend.supports_tablespaces and (f.unique or f.primary_key) and backend.autoindexes_primary_keys: if tablespace and connection.features.supports_tablespaces and (f.unique or f.primary_key) and connection.features.autoindexes_primary_keys:
# We must specify the index tablespace inline, because we # We must specify the index tablespace inline, because we
# won't be generating a CREATE INDEX statement for this field. # won't be generating a CREATE INDEX statement for this field.
field_output.append(connection.ops.tablespace_sql(tablespace, inline=True)) field_output.append(connection.ops.tablespace_sql(tablespace, inline=True))
@ -264,7 +264,7 @@ def sql_model_create(model, style, known_models=set()):
for i, line in enumerate(table_output): # Combine and add commas. for i, line in enumerate(table_output): # Combine and add commas.
full_statement.append(' %s%s' % (line, i < len(table_output)-1 and ',' or '')) full_statement.append(' %s%s' % (line, i < len(table_output)-1 and ',' or ''))
full_statement.append(')') full_statement.append(')')
if opts.db_tablespace and backend.supports_tablespaces: if opts.db_tablespace and connection.features.supports_tablespaces:
full_statement.append(connection.ops.tablespace_sql(opts.db_tablespace)) full_statement.append(connection.ops.tablespace_sql(opts.db_tablespace))
full_statement.append(';') full_statement.append(';')
final_output.append('\n'.join(full_statement)) final_output.append('\n'.join(full_statement))
@ -287,7 +287,7 @@ def sql_for_pending_references(model, style, pending_references):
qn = connection.ops.quote_name qn = connection.ops.quote_name
final_output = [] final_output = []
if backend.supports_constraints: if connection.features.supports_constraints:
opts = model._meta opts = model._meta
if model in pending_references: if model in pending_references:
for rel_class, f in pending_references[model]: for rel_class, f in pending_references[model]:
@ -316,7 +316,7 @@ def many_to_many_sql_for_model(model, style):
for f in opts.many_to_many: for f in opts.many_to_many:
if not isinstance(f.rel, generic.GenericRel): if not isinstance(f.rel, generic.GenericRel):
tablespace = f.db_tablespace or opts.db_tablespace tablespace = f.db_tablespace or opts.db_tablespace
if tablespace and backend.supports_tablespaces and backend.autoindexes_primary_keys: if tablespace and connection.features.supports_tablespaces and connection.features.autoindexes_primary_keys:
tablespace_sql = ' ' + connection.ops.tablespace_sql(tablespace, inline=True) tablespace_sql = ' ' + connection.ops.tablespace_sql(tablespace, inline=True)
else: else:
tablespace_sql = '' tablespace_sql = ''
@ -347,7 +347,7 @@ def many_to_many_sql_for_model(model, style):
style.SQL_FIELD(qn(f.m2m_reverse_name())), style.SQL_FIELD(qn(f.m2m_reverse_name())),
tablespace_sql)) tablespace_sql))
table_output.append(')') table_output.append(')')
if opts.db_tablespace and backend.supports_tablespaces: if opts.db_tablespace and connection.features.supports_tablespaces:
# f.db_tablespace is only for indices, so ignore its value here. # f.db_tablespace is only for indices, so ignore its value here.
table_output.append(connection.ops.tablespace_sql(opts.db_tablespace)) table_output.append(connection.ops.tablespace_sql(opts.db_tablespace))
table_output.append(';') table_output.append(';')
@ -395,10 +395,10 @@ def sql_indexes_for_model(model, style):
qn = connection.ops.quote_name qn = connection.ops.quote_name
for f in model._meta.fields: for f in model._meta.fields:
if f.db_index and not ((f.primary_key or f.unique) and backend.autoindexes_primary_keys): if f.db_index and not ((f.primary_key or f.unique) and connection.features.autoindexes_primary_keys):
unique = f.unique and 'UNIQUE ' or '' unique = f.unique and 'UNIQUE ' or ''
tablespace = f.db_tablespace or model._meta.db_tablespace tablespace = f.db_tablespace or model._meta.db_tablespace
if tablespace and backend.supports_tablespaces: if tablespace and connection.features.supports_tablespaces:
tablespace_sql = ' ' + connection.ops.tablespace_sql(tablespace) tablespace_sql = ' ' + connection.ops.tablespace_sql(tablespace)
else: else:
tablespace_sql = '' tablespace_sql = ''

View File

@ -39,6 +39,16 @@ class BaseDatabaseWrapper(local):
from django.db.backends import util from django.db.backends import util
return util.CursorDebugWrapper(cursor, self) return util.CursorDebugWrapper(cursor, self)
class BaseDatabaseFeatures(object):
allows_group_by_ordinal = True
allows_unique_and_pk = True
autoindexes_primary_keys = True
needs_datetime_string_cast = True
needs_upper_for_iops = False
supports_constraints = True
supports_tablespaces = False
uses_case_insensitive_names = False
class BaseDatabaseOperations(object): class BaseDatabaseOperations(object):
""" """
This class encapsulates all backend-specific differences, such as the way This class encapsulates all backend-specific differences, such as the way

View File

@ -4,7 +4,7 @@ ADO MSSQL database backend for Django.
Requires adodbapi 2.0.1: http://adodbapi.sourceforge.net/ Requires adodbapi 2.0.1: http://adodbapi.sourceforge.net/
""" """
from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
try: try:
import adodbapi as Database import adodbapi as Database
except ImportError, e: except ImportError, e:
@ -48,6 +48,9 @@ def variantToPython(variant, adType):
return res return res
Database.convertVariantToPython = variantToPython Database.convertVariantToPython = variantToPython
class DatabaseFeatures(BaseDatabaseFeatures):
supports_tablespaces = True
class DatabaseOperations(BaseDatabaseOperations): class DatabaseOperations(BaseDatabaseOperations):
def date_extract_sql(self, lookup_type, field_name): def date_extract_sql(self, lookup_type, field_name):
return "DATEPART(%s, %s)" % (lookup_type, field_name) return "DATEPART(%s, %s)" % (lookup_type, field_name)
@ -79,6 +82,7 @@ class DatabaseOperations(BaseDatabaseOperations):
return "ON %s" % self.quote_name(tablespace) return "ON %s" % self.quote_name(tablespace)
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseDatabaseWrapper):
features = DatabaseFeatures()
ops = DatabaseOperations() ops = DatabaseOperations()
def _cursor(self, settings): def _cursor(self, settings):
@ -93,15 +97,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.connection = Database.connect(conn_string) self.connection = Database.connect(conn_string)
return self.connection.cursor() return self.connection.cursor()
allows_group_by_ordinal = True
allows_unique_and_pk = True
autoindexes_primary_keys = True
needs_datetime_string_cast = True
needs_upper_for_iops = False
supports_constraints = True
supports_tablespaces = True
uses_case_insensitive_names = False
OPERATOR_MAPPING = { OPERATOR_MAPPING = {
'exact': '= %s', 'exact': '= %s',
'iexact': 'LIKE %s', 'iexact': 'LIKE %s',

View File

@ -21,12 +21,13 @@ class DatabaseError(Exception):
class IntegrityError(DatabaseError): class IntegrityError(DatabaseError):
pass pass
class DatabaseOperations(object): class ComplainOnGetattr(object):
def __getattr__(self, *args, **kwargs): def __getattr__(self, *args, **kwargs):
complain() complain()
class DatabaseWrapper(object): class DatabaseWrapper(object):
ops = DatabaseOperations() ops = ComplainOnGetattr()
features = ComplainOnGetattr()
cursor = complain cursor = complain
_commit = complain _commit = complain
_rollback = ignore _rollback = ignore
@ -37,7 +38,4 @@ class DatabaseWrapper(object):
def close(self): def close(self):
pass # close() pass # close()
supports_constraints = False
supports_tablespaces = False
OPERATOR_MAPPING = {} OPERATOR_MAPPING = {}

View File

@ -4,7 +4,7 @@ MySQL database backend for Django.
Requires MySQLdb: http://sourceforge.net/projects/mysql-python Requires MySQLdb: http://sourceforge.net/projects/mysql-python
""" """
from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
try: try:
import MySQLdb as Database import MySQLdb as Database
except ImportError, e: except ImportError, e:
@ -53,6 +53,9 @@ server_version_re = re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})')
# standard util.CursorDebugWrapper can be used. Also, using sql_mode # standard util.CursorDebugWrapper can be used. Also, using sql_mode
# TRADITIONAL will automatically cause most warnings to be treated as errors. # TRADITIONAL will automatically cause most warnings to be treated as errors.
class DatabaseFeatures(BaseDatabaseFeatures):
autoindexes_primary_keys = False
class DatabaseOperations(BaseDatabaseOperations): class DatabaseOperations(BaseDatabaseOperations):
def date_extract_sql(self, lookup_type, field_name): def date_extract_sql(self, lookup_type, field_name):
# http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
@ -116,6 +119,7 @@ class DatabaseOperations(BaseDatabaseOperations):
return [] return []
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseDatabaseWrapper):
features = DatabaseFeatures()
ops = DatabaseOperations() ops = DatabaseOperations()
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -175,15 +179,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.server_version = tuple([int(x) for x in m.groups()]) self.server_version = tuple([int(x) for x in m.groups()])
return self.server_version return self.server_version
allows_group_by_ordinal = True
allows_unique_and_pk = True
autoindexes_primary_keys = False
needs_datetime_string_cast = True # MySQLdb requires a typecast for dates
needs_upper_for_iops = False
supports_constraints = True
supports_tablespaces = False
uses_case_insensitive_names = False
OPERATOR_MAPPING = { OPERATOR_MAPPING = {
'exact': '= %s', 'exact': '= %s',
'iexact': 'LIKE %s', 'iexact': 'LIKE %s',

View File

@ -4,7 +4,7 @@ MySQL database backend for Django.
Requires MySQLdb: http://sourceforge.net/projects/mysql-python Requires MySQLdb: http://sourceforge.net/projects/mysql-python
""" """
from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
from django.utils.encoding import force_unicode from django.utils.encoding import force_unicode
try: try:
import MySQLdb as Database import MySQLdb as Database
@ -63,6 +63,9 @@ class MysqlDebugWrapper:
else: else:
return getattr(self.cursor, attr) return getattr(self.cursor, attr)
class DatabaseFeatures(BaseDatabaseFeatures):
autoindexes_primary_keys = False
class DatabaseOperations(BaseDatabaseOperations): class DatabaseOperations(BaseDatabaseOperations):
def date_extract_sql(self, lookup_type, field_name): def date_extract_sql(self, lookup_type, field_name):
# http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
@ -126,6 +129,7 @@ class DatabaseOperations(BaseDatabaseOperations):
return [] return []
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseDatabaseWrapper):
features = DatabaseFeatures()
ops = DatabaseOperations() ops = DatabaseOperations()
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -194,15 +198,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.server_version = tuple([int(x) for x in m.groups()]) self.server_version = tuple([int(x) for x in m.groups()])
return self.server_version return self.server_version
allows_group_by_ordinal = True
allows_unique_and_pk = True
autoindexes_primary_keys = False
needs_datetime_string_cast = True # MySQLdb requires a typecast for dates
needs_upper_for_iops = False
supports_constraints = True
supports_tablespaces = False
uses_case_insensitive_names = False
OPERATOR_MAPPING = { OPERATOR_MAPPING = {
'exact': '= %s', 'exact': '= %s',
'iexact': 'LIKE %s', 'iexact': 'LIKE %s',

View File

@ -4,7 +4,7 @@ Oracle database backend for Django.
Requires cx_Oracle: http://www.python.net/crew/atuining/cx_Oracle/ Requires cx_Oracle: http://www.python.net/crew/atuining/cx_Oracle/
""" """
from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from django.utils.encoding import smart_str, force_unicode from django.utils.encoding import smart_str, force_unicode
import datetime import datetime
@ -21,6 +21,14 @@ except ImportError, e:
DatabaseError = Database.Error DatabaseError = Database.Error
IntegrityError = Database.IntegrityError IntegrityError = Database.IntegrityError
class DatabaseFeatures(BaseDatabaseFeatures):
allows_group_by_ordinal = False
allows_unique_and_pk = False # Suppress UNIQUE/PK for Oracle (ORA-02259)
needs_datetime_string_cast = False
needs_upper_for_iops = True
supports_tablespaces = True
uses_case_insensitive_names = True
class DatabaseOperations(BaseDatabaseOperations): class DatabaseOperations(BaseDatabaseOperations):
def autoinc_sql(self, table): def autoinc_sql(self, table):
# To simulate auto-incrementing primary keys in Oracle, we have to # To simulate auto-incrementing primary keys in Oracle, we have to
@ -128,6 +136,7 @@ class DatabaseOperations(BaseDatabaseOperations):
return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""), self.quote_name(tablespace)) return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""), self.quote_name(tablespace))
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseDatabaseWrapper):
features = DatabaseFeatures()
ops = DatabaseOperations() ops = DatabaseOperations()
def _valid_connection(self): def _valid_connection(self):
@ -151,15 +160,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'")
return cursor return cursor
allows_group_by_ordinal = False
allows_unique_and_pk = False # Suppress UNIQUE/PK for Oracle (ORA-02259)
autoindexes_primary_keys = True
needs_datetime_string_cast = False
needs_upper_for_iops = True
supports_constraints = True
supports_tablespaces = True
uses_case_insensitive_names = True
class FormatStylePlaceholderCursor(Database.Cursor): class FormatStylePlaceholderCursor(Database.Cursor):
""" """
Django uses "format" (e.g. '%s') style placeholders, but Oracle uses ":var" Django uses "format" (e.g. '%s') style placeholders, but Oracle uses ":var"

View File

@ -5,7 +5,7 @@ Requires psycopg 1: http://initd.org/projects/psycopg1
""" """
from django.utils.encoding import smart_str, smart_unicode from django.utils.encoding import smart_str, smart_unicode
from django.db.backends import BaseDatabaseWrapper, util from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, util
from django.db.backends.postgresql.operations import DatabaseOperations from django.db.backends.postgresql.operations import DatabaseOperations
try: try:
import psycopg as Database import psycopg as Database
@ -56,7 +56,11 @@ class UnicodeCursorWrapper(object):
else: else:
return getattr(self.cursor, attr) return getattr(self.cursor, attr)
class DatabaseFeatures(BaseDatabaseFeatures):
pass # This backend uses all the defaults.
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseDatabaseWrapper):
features = DatabaseFeatures()
ops = DatabaseOperations() ops = DatabaseOperations()
def _cursor(self, settings): def _cursor(self, settings):
@ -87,15 +91,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.ops.postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] self.ops.postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
return cursor return cursor
allows_group_by_ordinal = True
allows_unique_and_pk = True
autoindexes_primary_keys = True
needs_datetime_string_cast = True
needs_upper_for_iops = False
supports_constraints = True
supports_tablespaces = False
uses_case_insensitive_names = False
def typecast_string(s): def typecast_string(s):
""" """
Cast all returned strings to unicode strings. Cast all returned strings to unicode strings.

View File

@ -4,7 +4,7 @@ PostgreSQL database backend for Django.
Requires psycopg 2: http://initd.org/projects/psycopg2 Requires psycopg 2: http://initd.org/projects/psycopg2
""" """
from django.db.backends import BaseDatabaseWrapper from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures
from django.db.backends.postgresql.operations import DatabaseOperations from django.db.backends.postgresql.operations import DatabaseOperations
try: try:
import psycopg2 as Database import psycopg2 as Database
@ -18,7 +18,11 @@ IntegrityError = Database.IntegrityError
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
class DatabaseFeatures(BaseDatabaseFeatures):
needs_datetime_string_cast = False
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseDatabaseWrapper):
features = DatabaseFeatures()
ops = DatabaseOperations() ops = DatabaseOperations()
def _cursor(self, settings): def _cursor(self, settings):
@ -49,15 +53,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.ops.postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] self.ops.postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
return cursor return cursor
allows_group_by_ordinal = True
allows_unique_and_pk = True
autoindexes_primary_keys = True
needs_datetime_string_cast = False
needs_upper_for_iops = False
supports_constraints = True
supports_tablespaces = False
uses_case_insensitive_names = False
OPERATOR_MAPPING = { OPERATOR_MAPPING = {
'exact': '= %s', 'exact': '= %s',
'iexact': 'ILIKE %s', 'iexact': 'ILIKE %s',

View File

@ -2,7 +2,7 @@
SQLite3 backend for django. Requires pysqlite2 (http://pysqlite.org/). SQLite3 backend for django. Requires pysqlite2 (http://pysqlite.org/).
""" """
from django.db.backends import BaseDatabaseWrapper, BaseDatabaseOperations, util from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
try: try:
try: try:
from sqlite3 import dbapi2 as Database from sqlite3 import dbapi2 as Database
@ -34,6 +34,9 @@ Database.register_converter("TIMESTAMP", util.typecast_timestamp)
Database.register_converter("decimal", util.typecast_decimal) Database.register_converter("decimal", util.typecast_decimal)
Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal) Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal)
class DatabaseFeatures(BaseDatabaseFeatures):
supports_constraints = False
class DatabaseOperations(BaseDatabaseOperations): class DatabaseOperations(BaseDatabaseOperations):
def date_extract_sql(self, lookup_type, field_name): def date_extract_sql(self, lookup_type, field_name):
# sqlite doesn't support extract, so we fake it with the user-defined # sqlite doesn't support extract, so we fake it with the user-defined
@ -70,6 +73,7 @@ class DatabaseOperations(BaseDatabaseOperations):
return sql return sql
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseDatabaseWrapper):
features = DatabaseFeatures()
ops = DatabaseOperations() ops = DatabaseOperations()
def _cursor(self, settings): def _cursor(self, settings):
@ -111,15 +115,6 @@ class SQLiteCursorWrapper(Database.Cursor):
def convert_query(self, query, num_params): def convert_query(self, query, num_params):
return query % tuple("?" * num_params) return query % tuple("?" * num_params)
allows_group_by_ordinal = True
allows_unique_and_pk = True
autoindexes_primary_keys = True
needs_datetime_string_cast = True
needs_upper_for_iops = False
supports_constraints = False
supports_tablespaces = False
uses_case_insensitive_names = False
def _sqlite_extract(lookup_type, dt): def _sqlite_extract(lookup_type, dt):
try: try:
dt = util.typecast_timestamp(dt) dt = util.typecast_timestamp(dt)

View File

@ -651,7 +651,7 @@ class DateQuerySet(QuerySet):
table_name = qn(self.model._meta.db_table) table_name = qn(self.model._meta.db_table)
field_name = qn(self._field.column) field_name = qn(self._field.column)
if backend.allows_group_by_ordinal: if connection.features.allows_group_by_ordinal:
group_by = '1' group_by = '1'
else: else:
group_by = connection.ops.date_trunc_sql(self._kind, '%s.%s' % (table_name, field_name)) group_by = connection.ops.date_trunc_sql(self._kind, '%s.%s' % (table_name, field_name))
@ -663,7 +663,7 @@ class DateQuerySet(QuerySet):
cursor.execute(sql, params) cursor.execute(sql, params)
has_resolve_columns = hasattr(self, 'resolve_columns') has_resolve_columns = hasattr(self, 'resolve_columns')
needs_datetime_string_cast = backend.needs_datetime_string_cast needs_datetime_string_cast = connection.features.needs_datetime_string_cast
dates = [] dates = []
# It would be better to use self._field here instead of DateTimeField(), # It would be better to use self._field here instead of DateTimeField(),
# but in Oracle that will result in a list of datetime.date instead of # but in Oracle that will result in a list of datetime.date instead of
@ -796,7 +796,7 @@ def get_where_clause(lookup_type, table_prefix, field_name, value, db_type):
else: else:
field_cast_sql = '%s%s' field_cast_sql = '%s%s'
field_sql = field_cast_sql % (table_prefix, field_name) field_sql = field_cast_sql % (table_prefix, field_name)
if lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith') and backend.needs_upper_for_iops: if lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith') and connection.features.needs_upper_for_iops:
format = 'UPPER(%s) %s' format = 'UPPER(%s) %s'
else: else:
format = '%s %s' format = '%s %s'