Changeset 5951
- Timestamp:
- 08/19/07 17:40:06 (1 year ago)
- Files:
-
- django/trunk/django/db/backends/ado_mssql/base.py (modified) (2 diffs)
- django/trunk/django/db/backends/dummy/base.py (modified) (1 diff)
- django/trunk/django/db/backends/__init__.py (modified) (1 diff)
- django/trunk/django/db/backends/mysql/base.py (modified) (2 diffs)
- django/trunk/django/db/backends/mysql_old/base.py (modified) (2 diffs)
- django/trunk/django/db/backends/oracle/base.py (modified) (2 diffs)
- django/trunk/django/db/backends/postgresql/base.py (modified) (2 diffs)
- django/trunk/django/db/backends/postgresql_psycopg2/base.py (modified) (2 diffs)
- django/trunk/django/db/backends/sqlite3/base.py (modified) (2 diffs)
- django/trunk/django/db/models/query.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/backends/ado_mssql/base.py
r5950 r5951 50 50 51 51 class DatabaseOperations(BaseDatabaseOperations): 52 pass 52 def date_extract_sql(self, lookup_type, field_name): 53 return "DATEPART(%s, %s)" % (lookup_type, field_name) 53 54 54 55 class DatabaseWrapper(BaseDatabaseWrapper): … … 88 89 cursor.execute("SELECT %s FROM %s WHERE %s = @@IDENTITY" % (pk_name, table_name, pk_name)) 89 90 return cursor.fetchone()[0] 90 91 def get_date_extract_sql(lookup_type, table_name):92 # lookup_type is 'year', 'month', 'day'93 return "DATEPART(%s, %s)" % (lookup_type, table_name)94 91 95 92 def get_date_trunc_sql(lookup_type, field_name): django/trunk/django/db/backends/dummy/base.py
r5950 r5951 45 45 dictfetchall = complain 46 46 get_last_insert_id = complain 47 get_date_extract_sql = complain48 47 get_date_trunc_sql = complain 49 48 get_datetime_cast_sql = complain django/trunk/django/db/backends/__init__.py
r5950 r5951 54 54 """ 55 55 return None 56 57 def date_extract_sql(self, lookup_type, field_name): 58 """ 59 Given a lookup_type of 'year', 'month' or 'day', returns the SQL that 60 extracts a value from the given date field field_name. 61 """ 62 raise NotImplementedError() django/trunk/django/db/backends/mysql/base.py
r5950 r5951 55 55 56 56 class DatabaseOperations(BaseDatabaseOperations): 57 pass 57 def date_extract_sql(self, lookup_type, field_name): 58 # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html 59 return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), field_name) 58 60 59 61 class DatabaseWrapper(BaseDatabaseWrapper): … … 138 140 return cursor.lastrowid 139 141 140 def get_date_extract_sql(lookup_type, table_name):141 # lookup_type is 'year', 'month', 'day'142 # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html143 return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), table_name)144 145 142 def get_date_trunc_sql(lookup_type, field_name): 146 143 # lookup_type is 'year', 'month', 'day' django/trunk/django/db/backends/mysql_old/base.py
r5950 r5951 65 65 66 66 class DatabaseOperations(BaseDatabaseOperations): 67 pass 67 def date_extract_sql(self, lookup_type, field_name): 68 # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html 69 return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), field_name) 68 70 69 71 class DatabaseWrapper(BaseDatabaseWrapper): … … 157 159 return cursor.lastrowid 158 160 159 def get_date_extract_sql(lookup_type, table_name):160 # lookup_type is 'year', 'month', 'day'161 # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html162 return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), table_name)163 164 161 def get_date_trunc_sql(lookup_type, field_name): 165 162 # lookup_type is 'year', 'month', 'day' django/trunk/django/db/backends/oracle/base.py
r5950 r5951 39 39 return sequence_sql, trigger_sql 40 40 41 def date_extract_sql(self, lookup_type, field_name): 42 # http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96540/functions42a.htm#1017163 43 return "EXTRACT(%s FROM %s)" % (lookup_type, field_name) 44 41 45 class DatabaseWrapper(BaseDatabaseWrapper): 42 46 ops = DatabaseOperations() … … 153 157 cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name) 154 158 return cursor.fetchone()[0] 155 156 def get_date_extract_sql(lookup_type, table_name):157 # lookup_type is 'year', 'month', 'day'158 # http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96540/functions42a.htm#1017163159 return "EXTRACT(%s FROM %s)" % (lookup_type, table_name)160 159 161 160 def get_date_trunc_sql(lookup_type, field_name): django/trunk/django/db/backends/postgresql/base.py
r5950 r5951 59 59 60 60 class DatabaseOperations(BaseDatabaseOperations): 61 pass 61 def date_extract_sql(self, lookup_type, field_name): 62 # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT 63 return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name) 62 64 63 65 class DatabaseWrapper(BaseDatabaseWrapper): … … 122 124 cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name)) 123 125 return cursor.fetchone()[0] 124 125 def get_date_extract_sql(lookup_type, table_name):126 # lookup_type is 'year', 'month', 'day'127 # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT128 return "EXTRACT('%s' FROM %s)" % (lookup_type, table_name)129 126 130 127 def get_date_trunc_sql(lookup_type, field_name): django/trunk/django/db/backends/postgresql_psycopg2/base.py
r5950 r5951 21 21 22 22 class DatabaseOperations(BaseDatabaseOperations): 23 pass 23 def date_extract_sql(self, lookup_type, field_name): 24 # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT 25 return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name) 24 26 25 27 class DatabaseWrapper(BaseDatabaseWrapper): … … 76 78 cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name)) 77 79 return cursor.fetchone()[0] 78 79 def get_date_extract_sql(lookup_type, table_name):80 # lookup_type is 'year', 'month', 'day'81 # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT82 return "EXTRACT('%s' FROM %s)" % (lookup_type, table_name)83 80 84 81 def get_date_trunc_sql(lookup_type, field_name): django/trunk/django/db/backends/sqlite3/base.py
r5950 r5951 36 36 37 37 class DatabaseOperations(BaseDatabaseOperations): 38 pass 38 def date_extract_sql(self, lookup_type, field_name): 39 # sqlite doesn't support extract, so we fake it with the user-defined 40 # function _sqlite_extract that's registered in connect(). 41 return 'django_extract("%s", %s)' % (lookup_type.lower(), field_name) 39 42 40 43 class DatabaseWrapper(BaseDatabaseWrapper): … … 100 103 def get_last_insert_id(cursor, table_name, pk_name): 101 104 return cursor.lastrowid 102 103 def get_date_extract_sql(lookup_type, table_name):104 # lookup_type is 'year', 'month', 'day'105 # sqlite doesn't support extract, so we fake it with the user-defined106 # function _sqlite_extract that's registered in connect(), above.107 return 'django_extract("%s", %s)' % (lookup_type.lower(), table_name)108 105 109 106 def _sqlite_extract(lookup_type, dt): django/trunk/django/db/models/query.py
r5943 r5951 809 809 return '%s BETWEEN %%s AND %%s' % field_sql 810 810 elif lookup_type in ('month', 'day'): 811 return "%s = %%s" % backend.get_date_extract_sql(lookup_type, field_sql)811 return "%s = %%s" % connection.ops.date_extract_sql(lookup_type, field_sql) 812 812 elif lookup_type == 'isnull': 813 813 return "%s IS %sNULL" % (field_sql, (not value and 'NOT ' or ''))
