Code

Ticket #2358: mssql_updated.diff

File mssql_updated.diff, 4.3 KB (added by Dan Hristodorescu, 8 years ago)

updated

Line 
1Index: django/contrib/sessions/middleware.py
2===================================================================
3--- django/contrib/sessions/middleware.py       (revision 3354)
4+++ django/contrib/sessions/middleware.py       (working copy)
5@@ -53,7 +53,7 @@
6             else:
7                 try:
8                     s = Session.objects.get(session_key=self.session_key,
9-                        expire_date__gt=datetime.datetime.now())
10+                        expire_date__gt=datetime.datetime.now().replace(microsecond=0))
11                     self._session_cache = s.get_decoded()
12                 except Session.DoesNotExist:
13                     self._session_cache = {}
14Index: django/db/backends/ado_mssql/base.py
15===================================================================
16--- django/db/backends/ado_mssql/base.py        (revision 3354)
17+++ django/db/backends/ado_mssql/base.py        (working copy)
18@@ -70,7 +70,7 @@
19             # TODO: Handle DATABASE_PORT.
20             conn_string = "PROVIDER=SQLOLEDB;DATA SOURCE=%s;UID=%s;PWD=%s;DATABASE=%s" % (settings.DATABASE_HOST, settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME)
21             self.connection = Database.connect(conn_string)
22-        cursor = self.connection.cursor()
23+        cursor = Cursor(self.connection)
24         if settings.DEBUG:
25             return util.CursorDebugWrapper(cursor, self)
26         return cursor
27@@ -117,10 +117,13 @@
28 
29 def get_limit_offset_sql(limit, offset=None):
30     # TODO: This is a guess. Make sure this is correct.
31-    sql = "LIMIT %s" % limit
32-    if offset and offset != 0:
33-        sql += " OFFSET %s" % offset
34-    return sql
35+    # should be "SELECT TOP %s" % limit
36+    # not LIMIT at the end
37+    return ""
38+    #sql = "LIMIT %s" % limit
39+    #if offset and offset != 0:
40+    #    sql += " OFFSET %s" % offset
41+    #return sql
42 
43 def get_random_function_sql():
44     return "RAND()"
45Index: django/db/backends/ado_mssql/introspection.py
46===================================================================
47--- django/db/backends/ado_mssql/introspection.py       (revision 3354)
48+++ django/db/backends/ado_mssql/introspection.py       (working copy)
49@@ -1,5 +1,6 @@
50 def get_table_list(cursor):
51-    raise NotImplementedError
52+    cursor.execute('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES')
53+    return [row[0] for row in cursor.fetchall()]
54 
55 def get_table_description(cursor, table_name):
56     raise NotImplementedError
57Index: django/db/models/base.py
58===================================================================
59--- django/db/models/base.py    (revision 3354)
60+++ django/db/models/base.py    (working copy)
61@@ -172,7 +172,7 @@
62         record_exists = True
63         if pk_set:
64             # Determine whether a record with the primary key already exists.
65-            cursor.execute("SELECT 1 FROM %s WHERE %s=%%s LIMIT 1" % \
66+            cursor.execute("SELECT 1 FROM %s WHERE %s=%%s" % \
67                 (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)), [pk_val])
68             # If it does already exist, do an UPDATE.
69             if cursor.fetchone():
70Index: django/db/models/fields/__init__.py
71===================================================================
72--- django/db/models/fields/__init__.py (revision 3354)
73+++ django/db/models/fields/__init__.py (working copy)
74@@ -478,7 +478,7 @@
75         if value is not None:
76             # MySQL will throw a warning if microseconds are given, because it
77             # doesn't support microseconds.
78-            if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'):
79+            if settings.DATABASE_ENGINE == 'mysql' or settings.DATABASE_ENGINE == 'ado_mssql' and hasattr(value, 'microsecond'):
80                 value = value.replace(microsecond=0)
81             value = str(value)
82         return Field.get_db_prep_save(self, value)
83@@ -742,7 +742,7 @@
84         if value is not None:
85             # MySQL will throw a warning if microseconds are given, because it
86             # doesn't support microseconds.
87-            if settings.DATABASE_ENGINE == 'mysql':
88+            if settings.DATABASE_ENGINE == 'mysql' or settings.DATABASE_ENGINE == 'ado_mssql':
89                 value = value.replace(microsecond=0)
90             value = str(value)
91         return Field.get_db_prep_save(self, value)