On Oct 18, 2010, at 12:41 PM, Russell Warren wrote:
>
> #sess2 will add a new user (jack), but we'll roll it back in the end
> sess2 = Session()
> jack = User('jack')
> jack.addresses = [Address(email_address='[email protected]'),
> Address(email_address='[email protected]')]
> sess2.add(jack)
> sess2.flush() #no commit
so above, issue #1, SQLite doesn't support foreign key constraints by default.
They are accepted syntactically, but do nothing. Consult the sqlite
documentation (SQLite itself, not SQLAlchemy) for information on a fairly
recent feature that enables them to enforce the constraints.
> #sess3 will create an address linked to jack (before he gets rolled
> back)
> sess3 = Session()
> addr3 = Address("[email protected]", jack_id) #but this id will be rolled
> back
> # adding to jack in another session succeeds even though jack is not
> commited...
> sess3.add(addr3)
> sess3.commit()
>
> #Now rollback sess2, which should get rid of jack... but doesn't??
> sess2.rollback()
>
> print Session().query(User).all()
issue #2, I've tried to emphasize this as much as possible in the
documentation, the SQLite dialect uses *one connection* for the thread, by
default. This default is being changed in 0.7 (so in 0.7, the common issue
will become "database is locked" issues, whereby I'll probably have to tell
people to switch back to SingletonThreadPool.... ).
The "one connection per thread" default is discussed at the following locations:
http://www.sqlalchemy.org/docs/dialects/sqlite.html?highlight=sqlite#threading-behavior
http://www.sqlalchemy.org/docs/core/pooling.html?highlight=singleton#connection-pool-configuration
http://www.sqlalchemy.org/docs/core/pooling.html#sqlalchemy.pool.SingletonThreadPool
and exactly what you are doing is mentioned at:
http://www.sqlalchemy.org/trac/wiki/FAQ#IamusingmultipleconnectionswithaSQLitedatabasetypicallytotesttransactionoperationandmytestprogramisnotworking
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
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.