From 165065a948e961d9eb2b790023063c2c2f4882c3 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 31 Aug 2006 23:55:42 +0000 Subject: [PATCH] quoting more or less working with oracle --- CHANGES | 2 +- lib/sqlalchemy/ansisql.py | 5 ++++- lib/sqlalchemy/databases/oracle.py | 16 +++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 71457ed2cb..d0cd189409 100644 --- a/CHANGES +++ b/CHANGES @@ -45,7 +45,7 @@ uppercase identifiers. quoting is also applied automatically in all cases to identifiers that are known to be reserved words or contain other non-standard characters. various database dialects can override all of this behavior, but currently they are all using the default behavior. tested with postgres, mysql, -sqlite. needs more testing with firebird, oracle, ms-sql. part of the ongoing +sqlite, oracle. needs more testing with firebird, ms-sql. part of the ongoing work with [ticket:155] - unit tests updated to run without any pysqlite installed; pool test uses a mock DBAPI diff --git a/lib/sqlalchemy/ansisql.py b/lib/sqlalchemy/ansisql.py index bd367918c5..f810b0d03f 100644 --- a/lib/sqlalchemy/ansisql.py +++ b/lib/sqlalchemy/ansisql.py @@ -832,7 +832,10 @@ class ANSIIdentifierPreparer(schema.SchemaVisitor): return self.__prepare_table(column.table, **kwargs) + "." + self.__strings.get(column, column.name) else: return self.__strings.get(column, column.name) - + + def should_quote(self, object): + return object.quote or self._requires_quotes(object.name, object.case_sensitive) + def format_sequence(self, sequence): return self.__prepare_sequence(sequence) diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index f5d7f52d5c..5f574338b7 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -186,8 +186,12 @@ class OracleDialect(ansisql.ANSIDialect): return bool( cursor.fetchone() is not None ) def reflecttable(self, connection, table): - # TODO: determine how oracle puts case sensitive names in data dictionary - c = connection.execute ("select distinct OWNER from ALL_TAB_COLUMNS where TABLE_NAME = :table_name", {'table_name':name.upper()}) + preparer = self.identifier_preparer + if not preparer.should_quote(table): + name = table.name.upper() + else: + name = table.name + c = connection.execute ("select distinct OWNER from ALL_TAB_COLUMNS where TABLE_NAME = :table_name", {'table_name':name}) rows = c.fetchall() if not rows : raise exceptions.NoSuchTableError(table.name) @@ -203,7 +207,7 @@ class OracleDialect(ansisql.ANSIDialect): else: raise exceptions.AssertionError("There are multiple tables with name %s in the schema, you must specifie owner"%table.name) - c = connection.execute ("select COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, DATA_DEFAULT from ALL_TAB_COLUMNS where TABLE_NAME = :table_name and OWNER = :owner", {'table_name':table.name.upper(), 'owner':owner}) + c = connection.execute ("select COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, DATA_DEFAULT from ALL_TAB_COLUMNS where TABLE_NAME = :table_name and OWNER = :owner", {'table_name':name, 'owner':owner}) while True: row = c.fetchone() @@ -234,8 +238,10 @@ class OracleDialect(ansisql.ANSIDialect): colargs = [] if default is not None: colargs.append(schema.PassiveDefault(sql.text(default))) - - name = name.lower() + + # if name comes back as all upper, assume its case folded + if (name.upper() == name): + name = name.lower() table.append_item (schema.Column(name, coltype, nullable=nullable, *colargs)) -- 2.47.2