mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19:20 +00:00
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
This commit is contained in:
parent
93d83df611
commit
f4aa493322
@ -1,46 +1,9 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from django.db import backend, connection
|
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
|
from django.utils.datastructures import SortedDict
|
||||||
import cx_Oracle as Database
|
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):
|
def get_query_set_class(DefaultQuerySet):
|
||||||
"Create a custom QuerySet class for Oracle."
|
"Create a custom QuerySet class for Oracle."
|
||||||
|
|
||||||
@ -49,6 +12,8 @@ def get_query_set_class(DefaultQuerySet):
|
|||||||
def iterator(self):
|
def iterator(self):
|
||||||
"Performs the SELECT database lookup of this QuerySet."
|
"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
|
# self._select is a dictionary, and dictionaries' key order is
|
||||||
# undefined, so we convert it to a list of tuples.
|
# undefined, so we convert it to a list of tuples.
|
||||||
extra_select = self._select.items()
|
extra_select = self._select.items()
|
||||||
@ -97,6 +62,9 @@ def get_query_set_class(DefaultQuerySet):
|
|||||||
yield obj
|
yield obj
|
||||||
|
|
||||||
def _get_sql_clause(self):
|
def _get_sql_clause(self):
|
||||||
|
from django.db.models.query import fill_table_cache, \
|
||||||
|
handle_legacy_orderlist, orderfield2column
|
||||||
|
|
||||||
opts = self.model._meta
|
opts = self.model._meta
|
||||||
|
|
||||||
# Construct the fundamental parts of the query: SELECT X FROM Y WHERE Z.
|
# Construct the fundamental parts of the query: SELECT X FROM Y WHERE Z.
|
||||||
|
@ -9,6 +9,8 @@ from django.db import models
|
|||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
headline = models.CharField(maxlength=100, default='Default headline')
|
headline = models.CharField(maxlength=100, default='Default headline')
|
||||||
pub_date = models.DateTimeField()
|
pub_date = models.DateTimeField()
|
||||||
|
class Meta:
|
||||||
|
ordering = ('pub_date',)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.headline
|
return self.headline
|
||||||
|
Loading…
x
Reference in New Issue
Block a user