Commits

Mike Bayer committed 9879c8a

quoting more or less working with oracle

  • Participants
  • Parent commits 0a60103

Comments (0)

Files changed (3)

 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

File lib/sqlalchemy/ansisql.py

             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)
         

File lib/sqlalchemy/databases/oracle.py

         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)
                 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()
             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))