Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored get_datetime_cast_sql() to DatabaseOperations.datetime_cas…

…t_sql(). Refs #5106

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5953 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 29f67dce9efd048b915d70f905ee1c9d2bda5de9 1 parent 5f51f05
Adrian Holovaty adrianholovaty authored
7 django/db/backends/__init__.py
View
@@ -68,3 +68,10 @@ def date_trunc_sql(self, lookup_type, field_name):
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
3  django/db/backends/ado_mssql/base.py
View
@@ -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
1  django/db/backends/dummy/base.py
View
@@ -44,7 +44,6 @@ def close(self):
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
3  django/db/backends/mysql/base.py
View
@@ -152,9 +152,6 @@ def quote_name(name):
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:
3  django/db/backends/mysql_old/base.py
View
@@ -171,9 +171,6 @@ def quote_name(name):
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:
6 django/db/backends/oracle/base.py
View
@@ -51,6 +51,9 @@ def date_trunc_sql(self, lookup_type, field_name):
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)"
3  django/db/backends/postgresql/base.py
View
@@ -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:
3  django/db/backends/postgresql_psycopg2/base.py
View
@@ -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:
3  django/db/backends/sqlite3/base.py
View
@@ -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:
7 django/db/models/query.py
View
@@ -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':
Please sign in to comment.
Something went wrong with that request. Please try again.