Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

boulder-oracle-sprint: Fixed #3164 in branch since it made basic unit…

… tests

fail.


git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4227 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f4aa4933226a78d04cdbfda9119e64212a80e5b7 1 parent 93d83df
Boulder Sprinters authored
42 django/db/backends/oracle/query.py
View
@@ -1,46 +1,9 @@
import datetime
from django.db import backend, connection
-# TODO: Why the frack can't I just import get_cached_row?
-#from django.db.models.query import get_cached_row
-from django.db.models.query import handle_legacy_orderlist, orderfield2column
from django.utils.datastructures import SortedDict
import cx_Oracle as Database
-def get_cached_row(klass, row, index_start):
- "Helper function that recursively returns an object with cache filled"
- index_end = index_start + len(klass._meta.fields)
- obj = klass(*row[index_start:index_end])
- for f in klass._meta.fields:
- if f.rel and not f.null:
- rel_obj, index_end = get_cached_row(f.rel.to, row, index_end)
- setattr(obj, f.get_cache_name(), rel_obj)
- return obj, index_end
-
-
-def fill_table_cache(opts, select, tables, where, old_prefix, cache_tables_seen):
- """
- Helper function that recursively populates the select, tables and where (in
- place) for select_related queries.
- """
- from django.db.models.fields import AutoField
- qn = backend.quote_name
- for f in opts.fields:
- if f.rel and not f.null:
- db_table = f.rel.to._meta.db_table
- if db_table not in cache_tables_seen:
- tables.append(qn(db_table))
- else: # The table was already seen, so give it a table alias.
- new_prefix = '%s%s' % (db_table, len(cache_tables_seen))
- tables.append('%s %s' % (qn(db_table), qn(new_prefix)))
- db_table = new_prefix
- cache_tables_seen.append(db_table)
- where.append('%s.%s = %s.%s' % \
- (qn(old_prefix), qn(f.column), qn(db_table), qn(f.rel.get_related_field().column)))
- select.extend(['%s.%s' % (backend.quote_name(db_table), backend.quote_name(f2.column)) for f2 in f.rel.to._meta.fields if not isinstance(f2, AutoField)])
- fill_table_cache(f.rel.to._meta, select, tables, where, db_table, cache_tables_seen)
-
-
def get_query_set_class(DefaultQuerySet):
"Create a custom QuerySet class for Oracle."
@@ -49,6 +12,8 @@ class OracleQuerySet(DefaultQuerySet):
def iterator(self):
"Performs the SELECT database lookup of this QuerySet."
+ from django.db.models.query import get_cached_row
+
# self._select is a dictionary, and dictionaries' key order is
# undefined, so we convert it to a list of tuples.
extra_select = self._select.items()
@@ -97,6 +62,9 @@ def resolve_cols(row):
yield obj
def _get_sql_clause(self):
+ from django.db.models.query import fill_table_cache, \
+ handle_legacy_orderlist, orderfield2column
+
opts = self.model._meta
# Construct the fundamental parts of the query: SELECT X FROM Y WHERE Z.
2  tests/modeltests/basic/models.py
View
@@ -9,6 +9,8 @@
class Article(models.Model):
headline = models.CharField(maxlength=100, default='Default headline')
pub_date = models.DateTimeField()
+ class Meta:
+ ordering = ('pub_date',)
def __str__(self):
return self.headline
Please sign in to comment.
Something went wrong with that request. Please try again.