Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored get_random_function_sql() to DatabaseOperations.random_fun…

…ction_sql(). Refs #5106

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5962 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c44fb66551bf2f628648440ebc2010ad1135d9ac 1 parent aaf8760
@adrianholovaty adrianholovaty authored
View
6 django/db/backends/__init__.py
@@ -133,3 +133,9 @@ def pk_default_value(self):
the field should use its default value.
"""
return 'DEFAULT'
+
+ def random_function_sql(self):
+ """
+ Returns a SQL expression that returns a random value.
+ """
+ return 'RANDOM()'
View
6 django/db/backends/ado_mssql/base.py
@@ -67,6 +67,9 @@ def last_insert_id(self, cursor, table_name, pk_name):
cursor.execute("SELECT %s FROM %s WHERE %s = @@IDENTITY" % (pk_name, table_name, pk_name))
return cursor.fetchone()[0]
+ def random_function_sql(self):
+ return 'RAND()'
+
class DatabaseWrapper(BaseDatabaseWrapper):
ops = DatabaseOperations()
@@ -100,9 +103,6 @@ def quote_name(name):
dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall
-def get_random_function_sql():
- return "RAND()"
-
def get_start_transaction_sql():
return "BEGIN;"
View
1  django/db/backends/dummy/base.py
@@ -43,7 +43,6 @@ def close(self):
dictfetchone = complain
dictfetchmany = complain
dictfetchall = complain
-get_random_function_sql = complain
get_start_transaction_sql = complain
get_sql_flush = complain
get_sql_sequence_reset = complain
View
6 django/db/backends/mysql/base.py
@@ -84,6 +84,9 @@ def limit_offset_sql(self, limit, offset=None):
sql += "%s," % offset
return sql + str(limit)
+ def random_function_sql(self):
+ return 'RAND()'
+
class DatabaseWrapper(BaseDatabaseWrapper):
ops = DatabaseOperations()
@@ -162,9 +165,6 @@ def quote_name(name):
dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall
-def get_random_function_sql():
- return "RAND()"
-
def get_start_transaction_sql():
return "BEGIN;"
View
6 django/db/backends/mysql_old/base.py
@@ -94,6 +94,9 @@ def limit_offset_sql(self, limit, offset=None):
sql += "%s," % offset
return sql + str(limit)
+ def random_function_sql(self):
+ return 'RAND()'
+
class DatabaseWrapper(BaseDatabaseWrapper):
ops = DatabaseOperations()
@@ -181,9 +184,6 @@ def quote_name(name):
dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall
-def get_random_function_sql():
- return "RAND()"
-
def get_start_transaction_sql():
return "BEGIN;"
View
8 django/db/backends/oracle/base.py
@@ -70,6 +70,9 @@ def limit_offset_sql(self, limit, offset=None):
def max_name_length(self):
return 30
+ def random_function_sql(self):
+ return "DBMS_RANDOM.RANDOM"
+
class DatabaseWrapper(BaseDatabaseWrapper):
ops = DatabaseOperations()
@@ -186,9 +189,6 @@ def get_field_cast_sql(db_type):
else:
return "%s%s"
-def get_random_function_sql():
- return "DBMS_RANDOM.RANDOM"
-
def get_start_transaction_sql():
return None
@@ -380,7 +380,7 @@ def _get_sql_clause(self, get_full_query=False):
ordering_to_use = opts.ordering
for f in handle_legacy_orderlist(ordering_to_use):
if f == '?': # Special case.
- order_by.append(backend.get_random_function_sql())
+ order_by.append(DatabaseOperations().random_function_sql())
else:
if f.startswith('-'):
col_name = f[1:]
View
3  django/db/backends/postgresql/base.py
@@ -131,9 +131,6 @@ def dictfetchall(cursor):
"Returns all rows from a cursor as a dict"
return cursor.dictfetchall()
-def get_random_function_sql():
- return "RANDOM()"
-
def get_start_transaction_sql():
return "BEGIN;"
View
3  django/db/backends/postgresql_psycopg2/base.py
@@ -85,9 +85,6 @@ def quote_name(name):
dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall
-def get_random_function_sql():
- return "RANDOM()"
-
def get_start_transaction_sql():
return "BEGIN;"
View
3  django/db/backends/sqlite3/base.py
@@ -118,9 +118,6 @@ def _sqlite_extract(lookup_type, dt):
return None
return str(getattr(dt, lookup_type))
-def get_random_function_sql():
- return "RANDOM()"
-
def get_start_transaction_sql():
return "BEGIN;"
View
4 django/db/models/query.py
@@ -71,7 +71,7 @@ def orderlist2sql(order_list, opts, prefix=''):
if f.startswith('-'):
output.append('%s%s DESC' % (prefix, backend.quote_name(orderfield2column(f[1:], opts))))
elif f == '?':
- output.append(backend.get_random_function_sql())
+ output.append(connection.ops.random_function_sql())
else:
output.append('%s%s ASC' % (prefix, backend.quote_name(orderfield2column(f, opts))))
return ', '.join(output)
@@ -531,7 +531,7 @@ def _get_sql_clause(self):
ordering_to_use = opts.ordering
for f in handle_legacy_orderlist(ordering_to_use):
if f == '?': # Special case.
- order_by.append(backend.get_random_function_sql())
+ order_by.append(connection.ops.random_function_sql())
else:
if f.startswith('-'):
col_name = f[1:]
Please sign in to comment.
Something went wrong with that request. Please try again.