Ticket #659: sqlite3.py.patch
File sqlite3.py.patch, 1.5 KB (added by , 19 years ago) |
---|
-
sqlite3.py
34 34 if self.connection is None: 35 35 self.connection = Database.connect(DATABASE_NAME, detect_types=Database.PARSE_DECLTYPES) 36 36 # register extract and date_trun functions 37 self.connection.create_function("django_extract", 2, _sqlite_extract)38 37 self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) 39 38 cursor = self.connection.cursor(factory=SQLiteCursorWrapper) 40 39 cursor.row_factory = utf8rowFactory … … 81 80 82 81 def get_date_extract_sql(lookup_type, table_name): 83 82 # lookup_type is 'year', 'month', 'day' 84 # sqlite doesn't support extract, so we fake it with the user-defined85 # function _sqlite_extract that's registered in connect(), above.86 return ' django_extract("%s", %s)' % (lookup_type.lower(), table_name)83 # sqlite doesn't support extract, so we fake it with the strftime function 84 date_codes = {'year': '"%%Y"', 'month': '"%%m"', 'day': '"%%d"'} 85 return 'strftime(%s, %s)' % (date_codes[lookup_type], table_name) 87 86 88 def _sqlite_extract(lookup_type, dt):89 try:90 dt = typecasts.typecast_timestamp(dt)91 except (ValueError, TypeError):92 return None93 return str(getattr(dt, lookup_type))94 95 87 def get_date_trunc_sql(lookup_type, field_name): 96 88 # lookup_type is 'year', 'month', 'day' 97 89 # sqlite doesn't support DATE_TRUNC, so we fake it as above.