Factored out database-specific date_extract behavior into dbmod.get_date_extract_sql(). Refs #46
git-svn-id: http://code.djangoproject.com/svn/django/trunk@159 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
35e81ce5af
commit
272b217557
|
@ -24,5 +24,6 @@ dictfetchmany = dbmod.dictfetchmany
|
|||
dictfetchall = dbmod.dictfetchall
|
||||
dictfetchall = dbmod.dictfetchall
|
||||
get_last_insert_id = dbmod.get_last_insert_id
|
||||
get_date_extract_sql = dbmod.get_date_extract_sql
|
||||
OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING
|
||||
DATA_TYPES = dbmod.DATA_TYPES
|
||||
|
|
|
@ -62,6 +62,10 @@ def get_last_insert_id(cursor, table_name, pk_name):
|
|||
cursor.execute("SELECT LAST_INSERT_ID()")
|
||||
return cursor.fetchone()[0]
|
||||
|
||||
def get_date_extract_sql(lookup_type, table_name):
|
||||
# lookup_type is 'year', 'month', 'day'
|
||||
return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), table_name)
|
||||
|
||||
OPERATOR_MAPPING = {
|
||||
'exact': '=',
|
||||
'iexact': 'LIKE',
|
||||
|
|
|
@ -61,6 +61,10 @@ 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_date_extract_sql(lookup_type, table_name):
|
||||
# lookup_type is 'year', 'month', 'day'
|
||||
return "EXTRACT('%s' FROM %s)" % (lookup_type, table_name)
|
||||
|
||||
# Register these custom typecasts, because Django expects dates/times to be
|
||||
# in Python's native (standard-library) datetime/time format, whereas psycopg
|
||||
# use mx.DateTime by default.
|
||||
|
|
|
@ -1006,7 +1006,7 @@ def _get_where_clause(lookup_type, table_prefix, field_name, value):
|
|||
if lookup_type in ('range', 'year'):
|
||||
return '%s%s BETWEEN %%s AND %%s' % (table_prefix, field_name)
|
||||
elif lookup_type in ('month', 'day'):
|
||||
return "EXTRACT('%s' FROM %s%s) = %%s" % (lookup_type, table_prefix, field_name)
|
||||
return "%s = %%s" % db.get_date_extract_sql(lookup_type, table_prefix + field_name)
|
||||
elif lookup_type == 'isnull':
|
||||
return "%s%s IS %sNULL" % (table_prefix, field_name, (not value and 'NOT ' or ''))
|
||||
raise TypeError, "Got invalid lookup_type: %s" % repr(lookup_type)
|
||||
|
|
Loading…
Reference in New Issue