diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-02-05 23:31:14 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-02-05 23:31:14 +0000 |
commit | 5320a47a14177e48a993e5333851888252a2d691 (patch) | |
tree | dc77157209df191a9c0975e37f275fe579e9d724 /test/dialect/sqlite.py | |
parent | 28af2439d983f767a5709cc64a61bc061681a35f (diff) | |
download | sqlalchemy-5320a47a14177e48a993e5333851888252a2d691.tar.gz |
- Enabled schema support on SQLite, added the temporary table namespace to table name reflection
- TODO: add sqlite to the standard alternate schema tests. a little tricky, because unlike CREATE SCHEMA, an ATTACH DATABASE won't survive a pool dispose...
Diffstat (limited to 'test/dialect/sqlite.py')
-rw-r--r-- | test/dialect/sqlite.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/dialect/sqlite.py b/test/dialect/sqlite.py index 5041cca89..70658330f 100644 --- a/test/dialect/sqlite.py +++ b/test/dialect/sqlite.py @@ -155,6 +155,67 @@ class DialectTest(AssertMixin): testing.db.execute("drop table django_content_type") + def test_attached_as_schema(self): + cx = testing.db.connect() + try: + cx.execute('ATTACH DATABASE ":memory:" AS alt_schema') + dialect = cx.dialect + assert dialect.table_names(cx, 'alt_schema') == [] + + meta = MetaData(cx) + Table('created', meta, Column('id', Integer), + schema='alt_schema') + alt_master = Table('sqlite_master', meta, autoload=True, + schema='alt_schema') + meta.create_all(cx) + + self.assertEquals(dialect.table_names(cx, 'alt_schema'), + ['created']) + assert len(alt_master.c) > 0 + + meta.clear() + reflected = Table('created', meta, autoload=True, + schema='alt_schema') + assert len(reflected.c) == 1 + + cx.execute(reflected.insert(), dict(id=1)) + r = cx.execute(reflected.select()).fetchall() + assert list(r) == [(1,)] + + cx.execute(reflected.update(), dict(id=2)) + r = cx.execute(reflected.select()).fetchall() + assert list(r) == [(2,)] + + cx.execute(reflected.delete(reflected.c.id==2)) + r = cx.execute(reflected.select()).fetchall() + assert list(r) == [] + + # note that sqlite_master is cleared, above + meta.drop_all() + + assert dialect.table_names(cx, 'alt_schema') == [] + finally: + cx.execute('DETACH DATABASE alt_schema') + + @testing.exclude('sqlite', '<', (2, 6)) + def test_temp_table_reflection(self): + cx = testing.db.connect() + try: + cx.execute('CREATE TEMPORARY TABLE tempy (id INT)') + + assert 'tempy' in cx.dialect.table_names(cx, None) + + meta = MetaData(cx) + tempy = Table('tempy', meta, autoload=True) + assert len(tempy.c) == 1 + meta.drop_all() + except: + try: + cx.execute('DROP TABLE tempy') + except exceptions.DBAPIError: + pass + raise + class InsertTest(AssertMixin): """Tests inserts and autoincrement.""" |