]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fixed bug where tables with schema name werent getting indexed in metadata correctly
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 6 Jun 2006 16:38:30 +0000 (16:38 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 6 Jun 2006 16:38:30 +0000 (16:38 +0000)
CHANGES
lib/sqlalchemy/databases/information_schema.py
lib/sqlalchemy/schema.py
test/engine/reflection.py

diff --git a/CHANGES b/CHANGES
index 9d200b8a0599febaf0fbb40efc01f802e698b3da..6e4dfbd07c3513b9224fe9d56d4f8755551eb904 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,8 @@
 "set" not available/ordering is needed.
 - "foreignkey" argument to relation() can also be a list.  fixed
 auto-foreignkey detection [ticket:151]
+- fixed bug where tables with schema names werent getting indexed in
+the MetaData object properly
 
 0.2.2
 - big improvements to polymorphic inheritance behavior, enabling it
index 3dc4a337b718229c358df1957da802394fbd300c..08236f7991d1771687c9d274582e7161f3fc3f6f 100644 (file)
@@ -56,15 +56,15 @@ pg_key_constraints = schema.Table("key_column_usage", ischema,
     Column("constraint_name", String),
     schema="information_schema")
 
-mysql_key_constraints = schema.Table("key_column_usage", ischema,
-    Column("table_schema", String),
-    Column("table_name", String),
-    Column("column_name", String),
-    Column("constraint_name", String),
-    Column("referenced_table_schema", String),
-    Column("referenced_table_name", String),
-    Column("referenced_column_name", String),
-    schema="information_schema")
+#mysql_key_constraints = schema.Table("key_column_usage", ischema,
+#    Column("table_schema", String),
+#    Column("table_name", String),
+#    Column("column_name", String),
+#    Column("constraint_name", String),
+#    Column("referenced_table_schema", String),
+#    Column("referenced_table_name", String),
+#    Column("referenced_column_name", String),
+#    schema="information_schema")
 
 key_constraints = pg_key_constraints
 
index 31b3259902c58845500065507fbe9cd63706acf1..368cb2460f2ee0f18d07076fa499482befbc47fd 100644 (file)
@@ -156,10 +156,7 @@ class Table(SchemaItem, sql.TableClause):
        , ',\n')
     
     def __str__(self):
-        if self.schema is None:
-            return self.name
-        else:
-            return self.schema + "." + self.name
+        return _get_table_key(self.name, self.schema)
         
     def reload_values(self, *args):
         """clears out the columns and other properties of this Table, and reloads them from the 
@@ -184,7 +181,7 @@ class Table(SchemaItem, sql.TableClause):
         self.indexes[index.name] = index
         
     def _set_parent(self, metadata):
-        metadata.tables[self.name] = self
+        metadata.tables[_get_table_key(self.name, self.schema)] = self
         self._metadata = metadata
     def accept_schema_visitor(self, visitor): 
         """traverses the given visitor across the Column objects inside this Table,
index bb0fd95898088ec4e9714a97a8f7ae9380aee622..49f69fdb561466c1ab02485c84f182f06f330ecb 100644 (file)
@@ -1,13 +1,12 @@
 
 import sqlalchemy.ansisql as ansisql
-import sqlalchemy.databases.postgres as postgres
 
 from sqlalchemy import *
-from sqlalchemy.exceptions import *
+from sqlalchemy.exceptions import NoSuchTableError
 
 from testbase import PersistTest
 import testbase
-import unittest, re
+import unittest, re, StringIO
 
 class ReflectionTest(PersistTest):
     def testbasic(self):
@@ -221,8 +220,32 @@ class CreateDropTest(PersistTest):
         metadata.drop_all(engine=testbase.db)
         self.assertEqual( testbase.db.has_table('items'), False )                
 
-
-            
+class SchemaTest(PersistTest):
+    # this test should really be in the sql tests somewhere, not engine
+    def testiteration(self):
+        metadata = MetaData()
+        table1 = Table('table1', metadata, 
+            Column('col1', Integer, primary_key=True),
+            schema='someschema')
+        table2 = Table('table2', metadata, 
+            Column('col1', Integer, primary_key=True),
+            Column('col2', Integer, ForeignKey('someschema.table1.col1')),
+            schema='someschema')
+        # insure this doesnt crash
+        print [t for t in metadata.table_iterator()]
+        buf = StringIO.StringIO()
+        def foo(s, p):
+            buf.write(s)
+        gen = testbase.db.dialect.schemagenerator(testbase.db.engine, foo)
+        table1.accept_schema_visitor(gen)
+        table2.accept_schema_visitor(gen)
+        buf = buf.getvalue()
+        assert buf.index("CREATE TABLE someschema.table1") > -1
+        assert buf.index("CREATE TABLE someschema.table2") > -1
+         
+        
+        
+        
 if __name__ == "__main__":
     testbase.main()