]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added table.exists()
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 19 Jul 2006 22:20:49 +0000 (22:20 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 19 Jul 2006 22:20:49 +0000 (22:20 +0000)
CHANGES
lib/sqlalchemy/schema.py
test/engine/reflection.py

diff --git a/CHANGES b/CHANGES
index 564eef21fd65e421dd55473b9af94e67f9dddb66..d6e2e84631b105df9642f9c7124909d24f80a730 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -44,7 +44,8 @@ aware of their "inherited" status if so.
 relationships to an inheriting mapper (which is also self-referential)
 - reduced bind param size in query._get to appease the picky oracle 
 [ticket:244]
-- added 'checkfirst' argument to table.create()/table.drop()
+- added 'checkfirst' argument to table.create()/table.drop(), as 
+well as table.exists() [ticket:234]
 
 0.2.5
 - fixed endless loop bug in select_by(), if the traversal hit
index 8fce1665d86ae8488a36821a4789f3612cc61661..6b44cda2980597532d16a52414d47baf3112a858 100644 (file)
@@ -236,6 +236,16 @@ class Table(SchemaItem, sql.TableClause):
         this does not issue a SQL DROP statement."""
         key = _get_table_key(self.name, self.schema)
         del self.metadata.tables[key]
+        
+    def exists(self, engine=None):
+        if engine is None and self.metadata.is_bound():
+            engine = self.engine
+
+        def do(conn):
+            e = conn.engine
+            return e.dialect.has_table(conn, self.name)
+        return engine.run_callable(do)
+
     def create(self, connectable=None, checkfirst=False):
         if connectable is not None:
             connectable.create(self, checkfirst=checkfirst)
index 64a645d0f967328ad15a2c2713aa772785280439..582920b304d20d30d897e5a8870568e12f4db9fe 100644 (file)
@@ -162,10 +162,13 @@ class ReflectionTest(PersistTest):
             Column('col1', Integer, primary_key=True),
             Column('col2', String(40)))
         try:
+            assert not table.exists()
             table.create()
+            assert table.exists()
             table.create(checkfirst=True)
             table.drop()
             table.drop(checkfirst=True)
+            assert not table.exists()
             table.create(checkfirst=True)
             table.drop()
         finally: