]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
quoting more or less working with oracle
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 31 Aug 2006 23:55:42 +0000 (23:55 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 31 Aug 2006 23:55:42 +0000 (23:55 +0000)
CHANGES
lib/sqlalchemy/ansisql.py
lib/sqlalchemy/databases/oracle.py

diff --git a/CHANGES b/CHANGES
index 71457ed2cb2f6203bcef8250b9f0780583707937..d0cd189409b536eab6f197b451be1efa1b264559 100644 (file)
--- 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
index bd367918c5a8d13865da3342fc47a67f8fe8043f..f810b0d03f3206dc1cd571804e78d5cfdc6cc5c7 100644 (file)
@@ -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)
         
index f5d7f52d5c03b4912e6f473a0f17350fc7f47e93..5f574338b7052229c8d4e1502f5c5e2063f8b327 100644 (file)
@@ -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))