mirror of https://github.com/django/django.git
Refactored get_datetime_cast_sql() to DatabaseOperations.datetime_cast_sql(). Refs #5106
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5953 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5f51f0524a
commit
29f67dce9e
|
@ -68,3 +68,10 @@ class BaseDatabaseOperations(object):
|
|||
the given specificity.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def datetime_cast_sql(self):
|
||||
"""
|
||||
Returns the SQL necessary to cast a datetime value so that it will be
|
||||
retrieved as a Python datetime object instead of a string.
|
||||
"""
|
||||
return None
|
||||
|
|
|
@ -97,9 +97,6 @@ def get_last_insert_id(cursor, table_name, pk_name):
|
|||
cursor.execute("SELECT %s FROM %s WHERE %s = @@IDENTITY" % (pk_name, table_name, pk_name))
|
||||
return cursor.fetchone()[0]
|
||||
|
||||
def get_datetime_cast_sql():
|
||||
return None
|
||||
|
||||
def get_limit_offset_sql(limit, offset=None):
|
||||
# TODO: This is a guess. Make sure this is correct.
|
||||
sql = "LIMIT %s" % limit
|
||||
|
|
|
@ -44,7 +44,6 @@ dictfetchone = complain
|
|||
dictfetchmany = complain
|
||||
dictfetchall = complain
|
||||
get_last_insert_id = complain
|
||||
get_datetime_cast_sql = complain
|
||||
get_limit_offset_sql = complain
|
||||
get_random_function_sql = complain
|
||||
get_deferrable_sql = complain
|
||||
|
|
|
@ -152,9 +152,6 @@ dictfetchall = util.dictfetchall
|
|||
def get_last_insert_id(cursor, table_name, pk_name):
|
||||
return cursor.lastrowid
|
||||
|
||||
def get_datetime_cast_sql():
|
||||
return None
|
||||
|
||||
def get_limit_offset_sql(limit, offset=None):
|
||||
sql = "LIMIT "
|
||||
if offset and offset != 0:
|
||||
|
|
|
@ -171,9 +171,6 @@ dictfetchall = util.dictfetchall
|
|||
def get_last_insert_id(cursor, table_name, pk_name):
|
||||
return cursor.lastrowid
|
||||
|
||||
def get_datetime_cast_sql():
|
||||
return None
|
||||
|
||||
def get_limit_offset_sql(limit, offset=None):
|
||||
sql = "LIMIT "
|
||||
if offset and offset != 0:
|
||||
|
|
|
@ -51,6 +51,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||
sql = "TRUNC(%s, '%s')" % (field_name, lookup_type)
|
||||
return sql
|
||||
|
||||
def datetime_cast_sql(self):
|
||||
return "TO_TIMESTAMP(%s, 'YYYY-MM-DD HH24:MI:SS.FF')"
|
||||
|
||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
ops = DatabaseOperations()
|
||||
|
||||
|
@ -166,9 +169,6 @@ def get_last_insert_id(cursor, table_name, pk_name):
|
|||
cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name)
|
||||
return cursor.fetchone()[0]
|
||||
|
||||
def get_datetime_cast_sql():
|
||||
return "TO_TIMESTAMP(%s, 'YYYY-MM-DD HH24:MI:SS.FF')"
|
||||
|
||||
def get_field_cast_sql(db_type):
|
||||
if db_type.endswith('LOB'):
|
||||
return "DBMS_LOB.SUBSTR(%s%s)"
|
||||
|
|
|
@ -128,9 +128,6 @@ def get_last_insert_id(cursor, table_name, pk_name):
|
|||
cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
|
||||
return cursor.fetchone()[0]
|
||||
|
||||
def get_datetime_cast_sql():
|
||||
return None
|
||||
|
||||
def get_limit_offset_sql(limit, offset=None):
|
||||
sql = "LIMIT %s" % limit
|
||||
if offset and offset != 0:
|
||||
|
|
|
@ -82,9 +82,6 @@ def get_last_insert_id(cursor, table_name, pk_name):
|
|||
cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
|
||||
return cursor.fetchone()[0]
|
||||
|
||||
def get_datetime_cast_sql():
|
||||
return None
|
||||
|
||||
def get_limit_offset_sql(limit, offset=None):
|
||||
sql = "LIMIT %s" % limit
|
||||
if offset and offset != 0:
|
||||
|
|
|
@ -115,9 +115,6 @@ def _sqlite_extract(lookup_type, dt):
|
|||
return None
|
||||
return str(getattr(dt, lookup_type))
|
||||
|
||||
def get_datetime_cast_sql():
|
||||
return None
|
||||
|
||||
def get_limit_offset_sql(limit, offset=None):
|
||||
sql = "LIMIT %s" % limit
|
||||
if offset and offset != 0:
|
||||
|
|
|
@ -780,8 +780,8 @@ def get_where_clause(lookup_type, table_prefix, field_name, value, db_type):
|
|||
if table_prefix.endswith('.'):
|
||||
table_prefix = backend.quote_name(table_prefix[:-1])+'.'
|
||||
field_name = backend.quote_name(field_name)
|
||||
if type(value) == datetime.datetime and backend.get_datetime_cast_sql():
|
||||
cast_sql = backend.get_datetime_cast_sql()
|
||||
if type(value) == datetime.datetime and connection.ops.datetime_cast_sql():
|
||||
cast_sql = connection.ops.datetime_cast_sql()
|
||||
else:
|
||||
cast_sql = '%s'
|
||||
if db_type and hasattr(backend, 'get_field_cast_sql'):
|
||||
|
@ -794,8 +794,7 @@ def get_where_clause(lookup_type, table_prefix, field_name, value, db_type):
|
|||
else:
|
||||
format = '%s %s'
|
||||
try:
|
||||
return format % (field_sql,
|
||||
backend.OPERATOR_MAPPING[lookup_type] % cast_sql)
|
||||
return format % (field_sql, backend.OPERATOR_MAPPING[lookup_type] % cast_sql)
|
||||
except KeyError:
|
||||
pass
|
||||
if lookup_type == 'in':
|
||||
|
|
Loading…
Reference in New Issue