1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

boulder-oracle-sprint: Fixed #3820. See #3835 too, as this is a more

correct fix for the same issue (CursorDebugWrapper not iterable).


git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4843 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Boulder Sprinters 2007-03-28 22:20:22 +00:00
parent 1f3fc7bc9f
commit 9649bfd4f9
3 changed files with 21 additions and 18 deletions

View File

@ -45,7 +45,7 @@ class DatabaseWrapper(local):
self.connection = Database.connect(conn_string, **self.options) self.connection = Database.connect(conn_string, **self.options)
cursor = FormatStylePlaceholderCursor(self.connection) cursor = FormatStylePlaceholderCursor(self.connection)
# default arraysize of 1 is highly sub-optimal # default arraysize of 1 is highly sub-optimal
cursor.arraysize = 256 cursor.arraysize = 100
# set oracle date to ansi date format # set oracle date to ansi date format
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'") cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'")
cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'")
@ -233,7 +233,7 @@ def get_query_set_class(DefaultQuerySet):
"Create a custom QuerySet class for Oracle." "Create a custom QuerySet class for Oracle."
from django.db import backend, connection from django.db import backend, connection
from django.db.models.query import EmptyResultSet from django.db.models.query import EmptyResultSet, GET_ITERATOR_CHUNK_SIZE
class OracleQuerySet(DefaultQuerySet): class OracleQuerySet(DefaultQuerySet):
@ -285,15 +285,21 @@ def get_query_set_class(DefaultQuerySet):
else: else:
yield field yield field
for unresolved_row in cursor: while 1:
row = list(resolve_cols(unresolved_row)) rows = cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)
if fill_cache: if not rows:
obj, index_end = get_cached_row(self.model, row, 0) raise StopIteration
else: for row in rows:
obj = self.model(*row[:index_end]) row = list(resolve_cols(row))
for i, k in enumerate(extra_select): if fill_cache:
setattr(obj, k[0], row[index_end+i]) obj, index_end = get_cached_row(klass=self.model, row=row,
yield obj index_start=0, max_depth=self._max_related_depth)
else:
obj = self.model(*row[:index_end])
for i, k in enumerate(extra_select):
setattr(obj, k[0], row[index_end+i])
yield obj
def _get_sql_clause(self, get_full_query=False): def _get_sql_clause(self, get_full_query=False):
from django.db.models.query import fill_table_cache, \ from django.db.models.query import fill_table_cache, \

View File

@ -6,13 +6,13 @@ foreign_key_re = re.compile(r"\sCONSTRAINT `[^`]*` FOREIGN KEY \(`([^`]*)`\) REF
def get_table_list(cursor): def get_table_list(cursor):
"Returns a list of table names in the current database." "Returns a list of table names in the current database."
cursor.execute("SELECT TABLE_NAME FROM USER_TABLES") cursor.execute("SELECT TABLE_NAME FROM USER_TABLES")
return [row[0].upper() for row in cursor] return [row[0].upper() for row in cursor.fetchall()]
def get_table_description(cursor, table_name): def get_table_description(cursor, table_name):
"Returns a description of the table, with the DB-API cursor.description interface." "Returns a description of the table, with the DB-API cursor.description interface."
cursor.execute("SELECT * FROM %s WHERE ROWNUM < 2" % quote_name(table_name)) cursor.execute("SELECT * FROM %s WHERE ROWNUM < 2" % quote_name(table_name))
return cursor.description return cursor.description
def _name_to_index(cursor, table_name): def _name_to_index(cursor, table_name):
""" """
Returns a dictionary of {field_name: field_index} for the given table. Returns a dictionary of {field_name: field_index} for the given table.
@ -24,7 +24,7 @@ def get_relations(cursor, table_name):
""" """
Returns a dictionary of {field_index: (field_index_other_table, other_table)} Returns a dictionary of {field_index: (field_index_other_table, other_table)}
representing all relationships to the given table. Indexes are 0-based. representing all relationships to the given table. Indexes are 0-based.
""" """
cursor.execute(""" cursor.execute("""
SELECT ta.column_id - 1, tb.table_name, tb.column_id - 1 SELECT ta.column_id - 1, tb.table_name, tb.column_id - 1
FROM user_constraints, USER_CONS_COLUMNS ca, USER_CONS_COLUMNS cb, FROM user_constraints, USER_CONS_COLUMNS ca, USER_CONS_COLUMNS cb,
@ -83,7 +83,7 @@ WHERE allcols.column_name = primarycols.column_name (+) AND
# Here, we skip any indexes across multiple fields. # Here, we skip any indexes across multiple fields.
indexes[row[0]] = {'primary_key': row[1], 'unique': row[2]} indexes[row[0]] = {'primary_key': row[1], 'unique': row[2]}
return indexes return indexes
# Maps type codes to Django Field types. # Maps type codes to Django Field types.
DATA_TYPES_REVERSE = { DATA_TYPES_REVERSE = {

View File

@ -33,9 +33,6 @@ class CursorDebugWrapper(object):
'time': "%.3f" % (stop - start), 'time': "%.3f" % (stop - start),
}) })
def __iter__(self):
return self.cursor.__iter__()
def __getattr__(self, attr): def __getattr__(self, attr):
if self.__dict__.has_key(attr): if self.__dict__.has_key(attr):
return self.__dict__[attr] return self.__dict__[attr]