Andy Davidoff wrote:
> On Oct 11, 1:29 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
>> On Oct 11, 2008, at 12:49 PM, AndyDavidoffwrote:
>>> This fixes the first part of this problem, but unfortunately the `show
>>> create table` is performed in the connection, not the session in which
>>> the temporary table was created.  MySQL doesn't expose temporary
>>> tables between sessions, so the `show create table` raises a MySQL
>>> exception due to a non-existent table.
>> you can reflect any table on a specific connection using  
>> autoload_with=<someconnection>.  if by "Session" you mean ORM session,  
>> get the current connection using session.connection().
> 
> Thanks, but MySQL's temporary tables are invisible to connection
> objects; the reflection would need to occur via queries issued in the
> actual Session (ORM session) in which the tables were created.  I
> doubt this'll be easy to elegantly hack into SQLA, though.

No hacking needed, it works just as Mike described.

from sqlalchemy import *
from sqlalchemy.orm import create_session

session = create_session()
session.bind = create_engine('mysql:///test')

session.begin()

session.execute('CREATE TEMPORARY TABLE foo (x INT)')
session.execute('INSERT INTO foo VALUES (1)')

m = MetaData()
tt = Table('foo', m, autoload=True, autoload_with=session.connection())
print session.execute(tt.select()).fetchall()

session.commit()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to