mirror of https://github.com/django/django.git
Refactored get_random_function_sql() to DatabaseOperations.random_function_sql(). Refs #5106
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5962 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
aaf8760227
commit
c44fb66551
|
@ -133,3 +133,9 @@ class BaseDatabaseOperations(object):
|
|||
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()'
|
||||
|
|
|
@ -67,6 +67,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||
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 @@ dictfetchone = util.dictfetchone
|
|||
dictfetchmany = util.dictfetchmany
|
||||
dictfetchall = util.dictfetchall
|
||||
|
||||
def get_random_function_sql():
|
||||
return "RAND()"
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return "BEGIN;"
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ quote_name = complain
|
|||
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
|
||||
|
|
|
@ -84,6 +84,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||
sql += "%s," % offset
|
||||
return sql + str(limit)
|
||||
|
||||
def random_function_sql(self):
|
||||
return 'RAND()'
|
||||
|
||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
ops = DatabaseOperations()
|
||||
|
||||
|
@ -162,9 +165,6 @@ dictfetchone = util.dictfetchone
|
|||
dictfetchmany = util.dictfetchmany
|
||||
dictfetchall = util.dictfetchall
|
||||
|
||||
def get_random_function_sql():
|
||||
return "RAND()"
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return "BEGIN;"
|
||||
|
||||
|
|
|
@ -94,6 +94,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||
sql += "%s," % offset
|
||||
return sql + str(limit)
|
||||
|
||||
def random_function_sql(self):
|
||||
return 'RAND()'
|
||||
|
||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
ops = DatabaseOperations()
|
||||
|
||||
|
@ -181,9 +184,6 @@ dictfetchone = util.dictfetchone
|
|||
dictfetchmany = util.dictfetchmany
|
||||
dictfetchall = util.dictfetchall
|
||||
|
||||
def get_random_function_sql():
|
||||
return "RAND()"
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return "BEGIN;"
|
||||
|
||||
|
|
|
@ -70,6 +70,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||
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_query_set_class(DefaultQuerySet):
|
|||
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:]
|
||||
|
|
|
@ -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;"
|
||||
|
||||
|
|
|
@ -85,9 +85,6 @@ dictfetchone = util.dictfetchone
|
|||
dictfetchmany = util.dictfetchmany
|
||||
dictfetchall = util.dictfetchall
|
||||
|
||||
def get_random_function_sql():
|
||||
return "RANDOM()"
|
||||
|
||||
def get_start_transaction_sql():
|
||||
return "BEGIN;"
|
||||
|
||||
|
|
|
@ -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;"
|
||||
|
||||
|
|
|
@ -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 @@ class _QuerySet(object):
|
|||
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:]
|
||||
|
|
Loading…
Reference in New Issue