From e168ef63a9a1306232b4a3c87d6264f2263c9e15 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 31 Aug 2006 23:13:14 +0000 Subject: [PATCH] some tweaks to oracle casing... --- lib/sqlalchemy/ansisql.py | 4 ++-- lib/sqlalchemy/databases/oracle.py | 7 +++--- test/sql/quote.py | 34 +++++++++++++++--------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/sqlalchemy/ansisql.py b/lib/sqlalchemy/ansisql.py index d5b31c8aac..bd367918c5 100644 --- a/lib/sqlalchemy/ansisql.py +++ b/lib/sqlalchemy/ansisql.py @@ -556,7 +556,7 @@ class ANSICompiler(sql.Compiled): # case one: no parameters in the statement, no parameters in the # compiled params - just return binds for all the table columns if self.parameters is None and stmt.parameters is None: - return [(c, sql.bindparam(c.name, type=c.type)) for c in stmt.table.columns] + return [(c, sql.bindparam(c.key, type=c.type)) for c in stmt.table.columns] # if we have statement parameters - set defaults in the # compiled params @@ -589,7 +589,7 @@ class ANSICompiler(sql.Compiled): if d.has_key(c): value = d[c] if sql._is_literal(value): - value = sql.bindparam(c.name, value, type=c.type) + value = sql.bindparam(c.key, value, type=c.type) values.append((c, value)) return values diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index 0fa7216c61..f5d7f52d5c 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -186,7 +186,8 @@ class OracleDialect(ansisql.ANSIDialect): return bool( cursor.fetchone() is not None ) def reflecttable(self, connection, table): - c = connection.execute ("select distinct OWNER from ALL_TAB_COLUMNS where TABLE_NAME = :table_name", {'table_name':table.name.upper()}) + # 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()}) rows = c.fetchall() if not rows : raise exceptions.NoSuchTableError(table.name) @@ -397,7 +398,7 @@ class OracleCompiler(ansisql.ANSICompiler): class OracleSchemaGenerator(ansisql.ANSISchemaGenerator): def get_column_specification(self, column, **kwargs): - colspec = column.name + colspec = self.preparer.format_column(column) colspec += " " + column.type.engine_impl(self.engine).get_col_spec() default = self.get_column_default_string(column) if default is not None: @@ -409,7 +410,7 @@ class OracleSchemaGenerator(ansisql.ANSISchemaGenerator): def visit_sequence(self, sequence): if not self.engine.dialect.has_sequence(self.connection, sequence.name): - self.append("CREATE SEQUENCE %s" % sequence.name) + self.append("CREATE SEQUENCE %s" % self.preparer.format_sequence(sequence)) self.execute() class OracleSchemaDropper(ansisql.ANSISchemaDropper): diff --git a/test/sql/quote.py b/test/sql/quote.py index 02a501003e..2d5132fb0b 100644 --- a/test/sql/quote.py +++ b/test/sql/quote.py @@ -13,10 +13,10 @@ class QuoteTest(PersistTest): Column('lowercase', Integer, primary_key=True), Column('UPPERCASE', Integer), Column('MixedCase', Integer), - Column('ASC', Integer)) + Column('ASC', Integer, key='a123')) table2 = Table('WorstCase2', metadata, - Column('desc', Integer, primary_key=True), - Column('Union', Integer), + Column('desc', Integer, primary_key=True, key='d123'), + Column('Union', Integer, key='u123'), Column('MixedCase', Integer)) table1.create() table2.create() @@ -30,12 +30,12 @@ class QuoteTest(PersistTest): table2.drop() def testbasic(self): - table1.insert().execute({'lowercase':1,'UPPERCASE':2,'MixedCase':3,'ASC':4}, - {'lowercase':2,'UPPERCASE':2,'MixedCase':3,'ASC':4}, - {'lowercase':4,'UPPERCASE':3,'MixedCase':2,'ASC':1}) - table2.insert().execute({'desc':1,'Union':2,'MixedCase':3}, - {'desc':2,'Union':2,'MixedCase':3}, - {'desc':4,'Union':3,'MixedCase':2}) + table1.insert().execute({'lowercase':1,'UPPERCASE':2,'MixedCase':3,'a123':4}, + {'lowercase':2,'UPPERCASE':2,'MixedCase':3,'a123':4}, + {'lowercase':4,'UPPERCASE':3,'MixedCase':2,'a123':1}) + table2.insert().execute({'d123':1,'u123':2,'MixedCase':3}, + {'d123':2,'u123':2,'MixedCase':3}, + {'d123':4,'u123':3,'MixedCase':2}) res1 = select([table1.c.lowercase, table1.c.UPPERCASE, table1.c.MixedCase, table1.c.ASC]).execute().fetchall() print res1 @@ -51,18 +51,18 @@ class QuoteTest(PersistTest): assert t2.c.has_key('MixedCase') def testlabels(self): - table1.insert().execute({'lowercase':1,'UPPERCASE':2,'MixedCase':3,'ASC':4}, - {'lowercase':2,'UPPERCASE':2,'MixedCase':3,'ASC':4}, - {'lowercase':4,'UPPERCASE':3,'MixedCase':2,'ASC':1}) - table2.insert().execute({'desc':1,'Union':2,'MixedCase':3}, - {'desc':2,'Union':2,'MixedCase':3}, - {'desc':4,'Union':3,'MixedCase':2}) + table1.insert().execute({'lowercase':1,'UPPERCASE':2,'MixedCase':3,'a123':4}, + {'lowercase':2,'UPPERCASE':2,'MixedCase':3,'a123':4}, + {'lowercase':4,'UPPERCASE':3,'MixedCase':2,'a123':1}) + table2.insert().execute({'d123':1,'u123':2,'MixedCase':3}, + {'d123':2,'u123':2,'MixedCase':3}, + {'d123':4,'u123':3,'MixedCase':2}) - res1 = select([table1.c.lowercase, table1.c.UPPERCASE, table1.c.MixedCase, table1.c.ASC], use_labels=True).execute().fetchall() + res1 = select([table1.c.lowercase, table1.c.UPPERCASE, table1.c.MixedCase, table1.c.a123], use_labels=True).execute().fetchall() print res1 assert(res1==[(1,2,3,4),(2,2,3,4),(4,3,2,1)]) - res2 = select([table2.c.desc, table2.c.Union, table2.c.MixedCase], use_labels=True).execute().fetchall() + res2 = select([table2.c.d123, table2.c.u123, table2.c.MixedCase], use_labels=True).execute().fetchall() print res2 assert(res2==[(1,2,3),(2,2,3),(4,3,2)]) -- 2.47.2