1
0
mirror of https://github.com/django/django.git synced 2025-07-05 18:29:11 +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:
Boulder Sprinters 2006-12-18 17:36:01 +00:00
parent 93d83df611
commit f4aa493322
2 changed files with 7 additions and 37 deletions

View File

@ -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 @@ def get_query_set_class(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 get_query_set_class(DefaultQuerySet):
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.

View File

@ -9,6 +9,8 @@ from django.db import models
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