Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactored get_limit_offset_sql() to DatabaseOperations.limit_offset_…

…sql(). Refs #5106

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5959 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d3e69c3a47dd9fc7c36414c029d9919b84b0b822 1 parent 5ce050a
Adrian Holovaty authored August 19, 2007
10  django/db/backends/__init__.py
@@ -109,3 +109,13 @@ def last_insert_id(self, cursor, table_name, pk_name):
109 109
         column.
110 110
         """
111 111
         return cursor.lastrowid
  112
+
  113
+    def limit_offset_sql(self, limit, offset=None):
  114
+        """
  115
+        Returns a LIMIT/OFFSET SQL clause, given a limit and optional offset.
  116
+        """
  117
+        # 'LIMIT 40 OFFSET 20'
  118
+        sql = "LIMIT %s" % limit
  119
+        if offset and offset != 0:
  120
+            sql += " OFFSET %s" % offset
  121
+        return sql
7  django/db/backends/ado_mssql/base.py
@@ -100,13 +100,6 @@ def quote_name(name):
100 100
 dictfetchmany = util.dictfetchmany
101 101
 dictfetchall  = util.dictfetchall
102 102
 
103  
-def get_limit_offset_sql(limit, offset=None):
104  
-    # TODO: This is a guess. Make sure this is correct.
105  
-    sql = "LIMIT %s" % limit
106  
-    if offset and offset != 0:
107  
-        sql += " OFFSET %s" % offset
108  
-    return sql
109  
-
110 103
 def get_random_function_sql():
111 104
     return "RAND()"
112 105
 
1  django/db/backends/dummy/base.py
@@ -43,7 +43,6 @@ def close(self):
43 43
 dictfetchone = complain
44 44
 dictfetchmany = complain
45 45
 dictfetchall = complain
46  
-get_limit_offset_sql = complain
47 46
 get_random_function_sql = complain
48 47
 get_pk_default_value = complain
49 48
 get_max_name_length = ignore
13  django/db/backends/mysql/base.py
@@ -77,6 +77,13 @@ def drop_foreignkey_sql(self):
77 77
     def fulltext_search_sql(self, field_name):
78 78
         return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name
79 79
 
  80
+    def limit_offset_sql(self, limit, offset=None):
  81
+        # 'LIMIT 20,40'
  82
+        sql = "LIMIT "
  83
+        if offset and offset != 0:
  84
+            sql += "%s," % offset
  85
+        return sql + str(limit)
  86
+
80 87
 class DatabaseWrapper(BaseDatabaseWrapper):
81 88
     ops = DatabaseOperations()
82 89
 
@@ -155,12 +162,6 @@ def quote_name(name):
155 162
 dictfetchmany = util.dictfetchmany
156 163
 dictfetchall  = util.dictfetchall
157 164
 
158  
-def get_limit_offset_sql(limit, offset=None):
159  
-    sql = "LIMIT "
160  
-    if offset and offset != 0:
161  
-        sql += "%s," % offset
162  
-    return sql + str(limit)
163  
-
164 165
 def get_random_function_sql():
165 166
     return "RAND()"
166 167
 
13  django/db/backends/mysql_old/base.py
@@ -87,6 +87,13 @@ def drop_foreignkey_sql(self):
87 87
     def fulltext_search_sql(self, field_name):
88 88
         return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name
89 89
 
  90
+    def limit_offset_sql(self, limit, offset=None):
  91
+        # 'LIMIT 20,40'
  92
+        sql = "LIMIT "
  93
+        if offset and offset != 0:
  94
+            sql += "%s," % offset
  95
+        return sql + str(limit)
  96
+
90 97
 class DatabaseWrapper(BaseDatabaseWrapper):
91 98
     ops = DatabaseOperations()
92 99
 
@@ -174,12 +181,6 @@ def quote_name(name):
174 181
 dictfetchmany = util.dictfetchmany
175 182
 dictfetchall  = util.dictfetchall
176 183
 
177  
-def get_limit_offset_sql(limit, offset=None):
178  
-    sql = "LIMIT "
179  
-    if offset and offset != 0:
180  
-        sql += "%s," % offset
181  
-    return sql + str(limit)
182  
-
183 184
 def get_random_function_sql():
184 185
     return "RAND()"
185 186
 
10  django/db/backends/oracle/base.py
@@ -62,6 +62,11 @@ def last_insert_id(self, cursor, table_name, pk_name):
62 62
         cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name)
63 63
         return cursor.fetchone()[0]
64 64
 
  65
+    def limit_offset_sql(self, limit, offset=None):
  66
+        # Limits and offset are too complicated to be handled here.
  67
+        # Instead, they are handled in django/db/backends/oracle/query.py.
  68
+        return ""
  69
+
65 70
 class DatabaseWrapper(BaseDatabaseWrapper):
66 71
     ops = DatabaseOperations()
67 72
 
@@ -178,11 +183,6 @@ def get_field_cast_sql(db_type):
178 183
     else:
179 184
         return "%s%s"
180 185
 
181  
-def get_limit_offset_sql(limit, offset=None):
182  
-    # Limits and offset are too complicated to be handled here.
183  
-    # Instead, they are handled in django/db/backends/oracle/query.py.
184  
-    return ""
185  
-
186 186
 def get_random_function_sql():
187 187
     return "DBMS_RANDOM.RANDOM"
188 188
 
6  django/db/backends/postgresql/base.py
@@ -131,12 +131,6 @@ def dictfetchall(cursor):
131 131
     "Returns all rows from a cursor as a dict"
132 132
     return cursor.dictfetchall()
133 133
 
134  
-def get_limit_offset_sql(limit, offset=None):
135  
-    sql = "LIMIT %s" % limit
136  
-    if offset and offset != 0:
137  
-        sql += " OFFSET %s" % offset
138  
-    return sql
139  
-
140 134
 def get_random_function_sql():
141 135
     return "RANDOM()"
142 136
 
6  django/db/backends/postgresql_psycopg2/base.py
@@ -85,12 +85,6 @@ def quote_name(name):
85 85
 dictfetchmany = util.dictfetchmany
86 86
 dictfetchall = util.dictfetchall
87 87
 
88  
-def get_limit_offset_sql(limit, offset=None):
89  
-    sql = "LIMIT %s" % limit
90  
-    if offset and offset != 0:
91  
-        sql += " OFFSET %s" % offset
92  
-    return sql
93  
-
94 88
 def get_random_function_sql():
95 89
     return "RANDOM()"
96 90
 
6  django/db/backends/sqlite3/base.py
@@ -115,12 +115,6 @@ def _sqlite_extract(lookup_type, dt):
115 115
         return None
116 116
     return str(getattr(dt, lookup_type))
117 117
 
118  
-def get_limit_offset_sql(limit, offset=None):
119  
-    sql = "LIMIT %s" % limit
120  
-    if offset and offset != 0:
121  
-        sql += " OFFSET %s" % offset
122  
-    return sql
123  
-
124 118
 def get_random_function_sql():
125 119
     return "RANDOM()"
126 120
 
2  django/db/models/query.py
@@ -555,7 +555,7 @@ def _get_sql_clause(self):
555 555
 
556 556
         # LIMIT and OFFSET clauses
557 557
         if self._limit is not None:
558  
-            sql.append("%s " % backend.get_limit_offset_sql(self._limit, self._offset))
  558
+            sql.append("%s " % connection.ops.limit_offset_sql(self._limit, self._offset))
559 559
         else:
560 560
             assert self._offset is None, "'offset' is not allowed without 'limit'"
561 561
 

0 notes on commit d3e69c3

Please sign in to comment.
Something went wrong with that request. Please try again.