Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored
7  django/db/backends/__init__.py
@@ -68,3 +68,10 @@ def date_trunc_sql(self, lookup_type, field_name):
68 68
         the given specificity.
69 69
         """
70 70
         raise NotImplementedError()
  71
+
  72
+    def datetime_cast_sql(self):
  73
+        """
  74
+        Returns the SQL necessary to cast a datetime value so that it will be
  75
+        retrieved as a Python datetime object instead of a string.
  76
+        """
  77
+        return None
3  django/db/backends/ado_mssql/base.py
@@ -97,9 +97,6 @@ def get_last_insert_id(cursor, table_name, pk_name):
97 97
     cursor.execute("SELECT %s FROM %s WHERE %s = @@IDENTITY" % (pk_name, table_name, pk_name))
98 98
     return cursor.fetchone()[0]
99 99
 
100  
-def get_datetime_cast_sql():
101  
-    return None
102  
-
103 100
 def get_limit_offset_sql(limit, offset=None):
104 101
     # TODO: This is a guess. Make sure this is correct.
105 102
     sql = "LIMIT %s" % limit
1  django/db/backends/dummy/base.py
@@ -44,7 +44,6 @@ def close(self):
44 44
 dictfetchmany = complain
45 45
 dictfetchall = complain
46 46
 get_last_insert_id = complain
47  
-get_datetime_cast_sql = complain
48 47
 get_limit_offset_sql = complain
49 48
 get_random_function_sql = complain
50 49
 get_deferrable_sql = complain
3  django/db/backends/mysql/base.py
@@ -152,9 +152,6 @@ def quote_name(name):
152 152
 def get_last_insert_id(cursor, table_name, pk_name):
153 153
     return cursor.lastrowid
154 154
 
155  
-def get_datetime_cast_sql():
156  
-    return None
157  
-
158 155
 def get_limit_offset_sql(limit, offset=None):
159 156
     sql = "LIMIT "
160 157
     if offset and offset != 0:
3  django/db/backends/mysql_old/base.py
@@ -171,9 +171,6 @@ def quote_name(name):
171 171
 def get_last_insert_id(cursor, table_name, pk_name):
172 172
     return cursor.lastrowid
173 173
 
174  
-def get_datetime_cast_sql():
175  
-    return None
176  
-
177 174
 def get_limit_offset_sql(limit, offset=None):
178 175
     sql = "LIMIT "
179 176
     if offset and offset != 0:
6  django/db/backends/oracle/base.py
@@ -51,6 +51,9 @@ def date_trunc_sql(self, lookup_type, field_name):
51 51
             sql = "TRUNC(%s, '%s')" % (field_name, lookup_type)
52 52
         return sql
53 53
 
  54
+    def datetime_cast_sql(self):
  55
+        return "TO_TIMESTAMP(%s, 'YYYY-MM-DD HH24:MI:SS.FF')"
  56
+
54 57
 class DatabaseWrapper(BaseDatabaseWrapper):
55 58
     ops = DatabaseOperations()
56 59
 
@@ -166,9 +169,6 @@ def get_last_insert_id(cursor, table_name, pk_name):
166 169
     cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name)
167 170
     return cursor.fetchone()[0]
168 171
 
169  
-def get_datetime_cast_sql():
170  
-    return "TO_TIMESTAMP(%s, 'YYYY-MM-DD HH24:MI:SS.FF')"
171  
-
172 172
 def get_field_cast_sql(db_type):
173 173
     if db_type.endswith('LOB'):
174 174
         return "DBMS_LOB.SUBSTR(%s%s)"
3  django/db/backends/postgresql/base.py
@@ -128,9 +128,6 @@ def get_last_insert_id(cursor, table_name, pk_name):
128 128
     cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
129 129
     return cursor.fetchone()[0]
130 130
 
131  
-def get_datetime_cast_sql():
132  
-    return None
133  
-
134 131
 def get_limit_offset_sql(limit, offset=None):
135 132
     sql = "LIMIT %s" % limit
136 133
     if offset and offset != 0:
3  django/db/backends/postgresql_psycopg2/base.py
@@ -82,9 +82,6 @@ def get_last_insert_id(cursor, table_name, pk_name):
82 82
     cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
83 83
     return cursor.fetchone()[0]
84 84
 
85  
-def get_datetime_cast_sql():
86  
-    return None
87  
-
88 85
 def get_limit_offset_sql(limit, offset=None):
89 86
     sql = "LIMIT %s" % limit
90 87
     if offset and offset != 0:
3  django/db/backends/sqlite3/base.py
@@ -115,9 +115,6 @@ def _sqlite_extract(lookup_type, dt):
115 115
         return None
116 116
     return str(getattr(dt, lookup_type))
117 117
 
118  
-def get_datetime_cast_sql():
119  
-    return None
120  
-
121 118
 def get_limit_offset_sql(limit, offset=None):
122 119
     sql = "LIMIT %s" % limit
123 120
     if offset and offset != 0:
7  django/db/models/query.py
@@ -780,8 +780,8 @@ def get_where_clause(lookup_type, table_prefix, field_name, value, db_type):
780 780
     if table_prefix.endswith('.'):
781 781
         table_prefix = backend.quote_name(table_prefix[:-1])+'.'
782 782
     field_name = backend.quote_name(field_name)
783  
-    if type(value) == datetime.datetime and backend.get_datetime_cast_sql():
784  
-        cast_sql = backend.get_datetime_cast_sql()
  783
+    if type(value) == datetime.datetime and connection.ops.datetime_cast_sql():
  784
+        cast_sql = connection.ops.datetime_cast_sql()
785 785
     else:
786 786
         cast_sql = '%s'
787 787
     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):
794 794
     else:
795 795
         format = '%s %s'
796 796
     try:
797  
-        return format % (field_sql,
798  
-                         backend.OPERATOR_MAPPING[lookup_type] % cast_sql)
  797
+        return format % (field_sql, backend.OPERATOR_MAPPING[lookup_type] % cast_sql)
799 798
     except KeyError:
800 799
         pass
801 800
     if lookup_type == 'in':

0 notes on commit 29f67dc

Please sign in to comment.
Something went wrong with that request. Please try again.