diff options
| author | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2006-11-04 23:54:12 +0000 |
|---|---|---|
| committer | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2006-11-04 23:54:12 +0000 |
| commit | 8b1f56d06be5bc94b43d429924bb497022ecafcb (patch) | |
| tree | 4bbaf398395b81ae5dd826e8ee6e03ceab0b5a92 | |
| parent | f412ebde1c147b43ed6df51ebe5bf15fdf46cd06 (diff) | |
Specialized iterator() so that it can resolve CLOBs. Also avoids the unnecessary usage of fetchmany(), buffering is handled nicely in the Oracle client itself.
Note this code is not yet tested, we are dependent on Matt Boersma's forthcoming commit.
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4007 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/backends/oracle/query.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/django/db/backends/oracle/query.py b/django/db/backends/oracle/query.py index b66a6268ef..34f8f1055b 100644 --- a/django/db/backends/oracle/query.py +++ b/django/db/backends/oracle/query.py @@ -1,9 +1,55 @@ +# NOTE: still dependent on other code that Matt Boersma is working on, not yet tested!!! - Jim Baker + +from django.db import backend, connection +import cx_Oracle as Database + + def get_query_set_class(DefaultQuerySet): """ Create a custom QuerySet class for Oracle. """ class OracleQuerySet(DefaultQuerySet): - pass + def iterator(self): + "Performs the SELECT database lookup of this QuerySet." + + # 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() + + cursor = connection.cursor() + + full_query = None + select, sql, params, full_query = self._get_sql_clause() + + if not full_query: + cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params) + else: + cursor.execute(full_query, params) + + fill_cache = self._select_related + index_end = len(self.model._meta.fields) + + # so here's the logic; + # 1. retrieve each row in turn + # 2. convert CLOBs + + def resolve_lobs(row): + for field in row: + if isinstance(field, Database.LOB): + yield str(field) + else: + yield field + + for unresolved_row in cursor: + row = list(resolve_lobs(unresolved_row)) + if fill_cache: + obj, index_end = get_cached_row(self.model, row, 0) + else: + obj = self.model(*row[:index_end]) + for i, k in enumerate(extra_select): + setattr(obj, k[0], row[index_end+i]) + yield obj + - return OracleQuerySet
\ No newline at end of file + return OracleQuerySet |
