Code

Ticket #2358: mssql.diff

File mssql.diff, 3.1 KB (added by Dan Hristodorescu, 8 years ago)
Line 
1Index: django/db/backends/ado_mssql/base.py
2===================================================================
3--- django/db/backends/ado_mssql/base.py        (revision 3354)
4+++ django/db/backends/ado_mssql/base.py        (working copy)
5@@ -70,7 +70,7 @@
6             # TODO: Handle DATABASE_PORT.
7             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)
8             self.connection = Database.connect(conn_string)
9-        cursor = self.connection.cursor()
10+        cursor = Cursor(self.connection)
11         if settings.DEBUG:
12             return util.CursorDebugWrapper(cursor, self)
13         return cursor
14@@ -117,10 +117,13 @@
15 
16 def get_limit_offset_sql(limit, offset=None):
17     # TODO: This is a guess. Make sure this is correct.
18-    sql = "LIMIT %s" % limit
19-    if offset and offset != 0:
20-        sql += " OFFSET %s" % offset
21-    return sql
22+    # should be "SELECT TOP %s" % limit
23+    # not LIMIT at the end
24+    return ""
25+    #sql = "LIMIT %s" % limit
26+    #if offset and offset != 0:
27+    #    sql += " OFFSET %s" % offset
28+    #return sql
29 
30 def get_random_function_sql():
31     return "RAND()"
32Index: django/db/backends/ado_mssql/introspection.py
33===================================================================
34--- django/db/backends/ado_mssql/introspection.py       (revision 3354)
35+++ django/db/backends/ado_mssql/introspection.py       (working copy)
36@@ -1,5 +1,6 @@
37 def get_table_list(cursor):
38-    raise NotImplementedError
39+    cursor.execute('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES')
40+    return [row[0] for row in cursor.fetchall()]
41 
42 def get_table_description(cursor, table_name):
43     raise NotImplementedError
44Index: django/db/models/base.py
45===================================================================
46--- django/db/models/base.py    (revision 3354)
47+++ django/db/models/base.py    (working copy)
48@@ -172,7 +172,7 @@
49         record_exists = True
50         if pk_set:
51             # Determine whether a record with the primary key already exists.
52-            cursor.execute("SELECT 1 FROM %s WHERE %s=%%s LIMIT 1" % \
53+            cursor.execute("SELECT 1 FROM %s WHERE %s=%%s" % \
54                 (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)), [pk_val])
55             # If it does already exist, do an UPDATE.
56             if cursor.fetchone():
57Index: django/db/models/fields/__init__.py
58===================================================================
59--- django/db/models/fields/__init__.py (revision 3354)
60+++ django/db/models/fields/__init__.py (working copy)
61@@ -478,7 +478,7 @@
62         if value is not None:
63             # MySQL will throw a warning if microseconds are given, because it
64             # doesn't support microseconds.
65-            if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'):
66+            if settings.DATABASE_ENGINE == 'mysql' or settings.DATABASE_ENGINE == 'ado_mssql' and hasattr(value, 'microsecond'):
67                 value = value.replace(microsecond=0)
68             value = str(value)
69         return Field.get_db_prep_save(self, value)