Ticket #2763: django-mysql-zero-typcast-ticket2763.2.patch

File django-mysql-zero-typcast-ticket2763.2.patch, 2.3 KB (added by wam-djangobug@…, 9 years ago)

Update to prior patch to handle Zero times, as well as date and datetime stamps

1Index: base.py
3[1;31m--- base.py      (revision 3946)[0;0;40m
4[1;34m+++ base.py      (working copy)[0;0;40m
5[1;35m@@ -17,14 +17,40 @@[0;0;40m
6[1;37m [0;0;40m
7[1;37m DatabaseError = Database.DatabaseError[0;0;40m
8[1;37m [0;0;40m
9[1;34m+def typecast_mysql_time(s):[0;0;40m
10[1;34m+    # workaround mysql issue.[0;0;40m
11[1;34m+    # see http://code.djangoproject.com/ticket/433, 2763 and 2369 [0;0;40m
12[1;34m+    if s == "00:00:00":[0;0;40m
13[1;34m+        # an empty or invalid field gets remapped to zeros[0;0;40m
14[1;34m+        return None[0;0;40m
15[1;34m+    return util.typecast_time(s)[0;0;40m
16[1;34m+    [0;0;40m
18[1;34m+def typecast_mysql_timestamp(s):[0;0;40m
19[1;34m+    # workaround mysql issue.[0;0;40m
20[1;34m+    # see http://code.djangoproject.com/ticket/433, 2763 and 2369 [0;0;40m
21[1;34m+    if s == "0000-00-00 00:00:00":[0;0;40m
22[1;34m+        # an empty or invalid field gets remapped to zeros[0;0;40m
23[1;34m+        return None[0;0;40m
24[1;34m+    return util.typecast_timestamp(s)[0;0;40m
26[1;34m+def typecast_mysql_date(s):[0;0;40m
27[1;34m+    # workaround mysql issue.[0;0;40m
28[1;34m+    # see http://code.djangoproject.com/ticket/433, 2763 and 2369 [0;0;40m
29[1;34m+    if s == "0000-00-00":  [0;0;40m
30[1;34m+        # an empty or invalid field gets remapped to zeros[0;0;40m
31[1;34m+        return None[0;0;40m
32[1;34m+    return util.typecast_date(s)[0;0;40m
34[1;37m django_conversions = conversions.copy()[0;0;40m
35[1;37m django_conversions.update({[0;0;40m
36[1;37m     types.BooleanType: util.rev_typecast_boolean,[0;0;40m
37[1;31m-    FIELD_TYPE.DATETIME: util.typecast_timestamp,[0;0;40m
38[1;31m-    FIELD_TYPE.DATE: util.typecast_date,[0;0;40m
39[1;31m-    FIELD_TYPE.TIME: util.typecast_time,[0;0;40m
40[1;34m+    FIELD_TYPE.DATETIME: typecast_mysql_timestamp,[0;0;40m
41[1;34m+    FIELD_TYPE.DATE: typecast_mysql_date,[0;0;40m
42[1;34m+    FIELD_TYPE.TIME: typecast_mysql_time,[0;0;40m
43[1;37m })[0;0;40m
44[1;37m [0;0;40m
46[1;37m # This should match the numerical portion of the version numbers (we can treat[0;0;40m
47[1;37m # versions like 5.0.24 and 5.0.24a as the same). Based on the list of version[0;0;40m
48[1;37m # at http://dev.mysql.com/doc/refman/4.1/en/news.html and[0;0;40m
Back to Top