Django

Code

Changeset 5951

Show
Ignore:
Timestamp:
08/19/07 17:40:06 (1 year ago)
Author:
adrian
Message:

Refactored get_date_extract_sql() to DatabaseOperations?.date_extract_sql(). Refs #5106

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/ado_mssql/base.py

    r5950 r5951  
    5050 
    5151class DatabaseOperations(BaseDatabaseOperations): 
    52     pass 
     52    def date_extract_sql(self, lookup_type, field_name): 
     53        return "DATEPART(%s, %s)" % (lookup_type, field_name) 
    5354 
    5455class DatabaseWrapper(BaseDatabaseWrapper): 
     
    8889    cursor.execute("SELECT %s FROM %s WHERE %s = @@IDENTITY" % (pk_name, table_name, pk_name)) 
    8990    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) 
    9491 
    9592def get_date_trunc_sql(lookup_type, field_name): 
  • django/trunk/django/db/backends/dummy/base.py

    r5950 r5951  
    4545dictfetchall = complain 
    4646get_last_insert_id = complain 
    47 get_date_extract_sql = complain 
    4847get_date_trunc_sql = complain 
    4948get_datetime_cast_sql = complain 
  • django/trunk/django/db/backends/__init__.py

    r5950 r5951  
    5454        """ 
    5555        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  
    5555 
    5656class 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) 
    5860 
    5961class DatabaseWrapper(BaseDatabaseWrapper): 
     
    138140    return cursor.lastrowid 
    139141 
    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.html 
    143     return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), table_name) 
    144  
    145142def get_date_trunc_sql(lookup_type, field_name): 
    146143    # lookup_type is 'year', 'month', 'day' 
  • django/trunk/django/db/backends/mysql_old/base.py

    r5950 r5951  
    6565 
    6666class 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) 
    6870 
    6971class DatabaseWrapper(BaseDatabaseWrapper): 
     
    157159    return cursor.lastrowid 
    158160 
    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.html 
    162     return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), table_name) 
    163  
    164161def get_date_trunc_sql(lookup_type, field_name): 
    165162    # lookup_type is 'year', 'month', 'day' 
  • django/trunk/django/db/backends/oracle/base.py

    r5950 r5951  
    3939        return sequence_sql, trigger_sql 
    4040 
     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 
    4145class DatabaseWrapper(BaseDatabaseWrapper): 
    4246    ops = DatabaseOperations() 
     
    153157    cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name) 
    154158    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#1017163 
    159     return "EXTRACT(%s FROM %s)" % (lookup_type, table_name) 
    160159 
    161160def get_date_trunc_sql(lookup_type, field_name): 
  • django/trunk/django/db/backends/postgresql/base.py

    r5950 r5951  
    5959 
    6060class 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) 
    6264 
    6365class DatabaseWrapper(BaseDatabaseWrapper): 
     
    122124    cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name)) 
    123125    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-EXTRACT 
    128     return "EXTRACT('%s' FROM %s)" % (lookup_type, table_name) 
    129126 
    130127def get_date_trunc_sql(lookup_type, field_name): 
  • django/trunk/django/db/backends/postgresql_psycopg2/base.py

    r5950 r5951  
    2121 
    2222class 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) 
    2426 
    2527class DatabaseWrapper(BaseDatabaseWrapper): 
     
    7678    cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name)) 
    7779    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-EXTRACT 
    82     return "EXTRACT('%s' FROM %s)" % (lookup_type, table_name) 
    8380 
    8481def get_date_trunc_sql(lookup_type, field_name): 
  • django/trunk/django/db/backends/sqlite3/base.py

    r5950 r5951  
    3636 
    3737class 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) 
    3942 
    4043class DatabaseWrapper(BaseDatabaseWrapper): 
     
    100103def get_last_insert_id(cursor, table_name, pk_name): 
    101104    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-defined 
    106     # function _sqlite_extract that's registered in connect(), above. 
    107     return 'django_extract("%s", %s)' % (lookup_type.lower(), table_name) 
    108105 
    109106def _sqlite_extract(lookup_type, dt): 
  • django/trunk/django/db/models/query.py

    r5943 r5951  
    809809        return '%s BETWEEN %%s AND %%s' % field_sql 
    810810    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) 
    812812    elif lookup_type == 'isnull': 
    813813        return "%s IS %sNULL" % (field_sql, (not value and 'NOT ' or ''))