Re: [sqlalchemy] Sqlalchemy+sqlite3 autoload problem

2011-04-07 Thread Michael Bayer

On Apr 7, 2011, at 9:35 AM, Massi wrote:

> Hi everyone, I'm writing a script using sqlalchemy 0.66 and sqlite3.
> I'm encountering a problem trying to create and load a table from two
> different engines.
> Here is an example script showing the problem:
> 
> from sqlalchemy import *
> 
> engine1 = create_engine("sqlite:///test.db", echo=False)
> metadata1 = MetaData(engine1)
> 
> try :
>table = Table("user", metadata1, autoload=True)
>table.drop()
> except :
>print "Not found"
> 
> engine2 = create_engine("sqlite:///test.db", echo=False)
> metadata2 = MetaData(engine2)
> table = Table("user", metadata2,
>Column('id', Integer, primary_key=True),
>Column('name', String),
>Column('password', String), sqlite_autoincrement=True)
> table.create()
> 
> metadata1 = MetaData(engine1)
> print Table("user", metadata2, autoload=True)
> print Table("user", metadata1, autoload=True)
> 
> As you can see, I create the table 'user' from engine2 and then I try
> to load it both from engine1 and engine2. The try-except part do some
> clean up and it is aimed only to make the script repeatable.
> If you run the code you'll see that the first print statement is
> executed correctly, while the second one raises a NoSuchTableError
> exception. It seems to be connected with some flushing issue, but I
> don't know what I am doing wrong. Any suggestion?
> Thanks in advance.

its been observed that SQLite doesn't refresh the pragma information regarding 
tables once a connection is made.  So switch to NullPool or create the engine 
after tables are created.




> 
> -- 
> 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 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Sqlalchemy+sqlite3 autoload problem

2011-04-07 Thread Massi
Hi everyone, I'm writing a script using sqlalchemy 0.66 and sqlite3.
I'm encountering a problem trying to create and load a table from two
different engines.
Here is an example script showing the problem:

from sqlalchemy import *

engine1 = create_engine("sqlite:///test.db", echo=False)
metadata1 = MetaData(engine1)

try :
table = Table("user", metadata1, autoload=True)
table.drop()
except :
print "Not found"

engine2 = create_engine("sqlite:///test.db", echo=False)
metadata2 = MetaData(engine2)
table = Table("user", metadata2,
Column('id', Integer, primary_key=True),
Column('name', String),
Column('password', String), sqlite_autoincrement=True)
table.create()

metadata1 = MetaData(engine1)
print Table("user", metadata2, autoload=True)
print Table("user", metadata1, autoload=True)

As you can see, I create the table 'user' from engine2 and then I try
to load it both from engine1 and engine2. The try-except part do some
clean up and it is aimed only to make the script repeatable.
If you run the code you'll see that the first print statement is
executed correctly, while the second one raises a NoSuchTableError
exception. It seems to be connected with some flushing issue, but I
don't know what I am doing wrong. Any suggestion?
Thanks in advance.

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.