On Jul 5, 2006, at 12:59 PM, Barry Warsaw wrote: > > /usr/local/mailman/lists/[EMAIL PROTECTED]/members.db > > so my url is: > > sqlite:////usr/local/mailman/lists/[EMAIL PROTECTED]/members.db > > (note the 4 slashes -- I've read some of this list's archives) > > However, the members.db always ends up in /usr/local/mailman/ > members.db, which is the pwd that I'm running my tests in. I've > verified that it always creates members.db in the cwd. Is it the '@' > in the url that's screwing things up? >
very likely since @ is part of the regexp used to parse out the [EMAIL PROTECTED] you might want to play with sqlalchemy.engine.url.URL directly to see whats going on . we're doing rfc1738 for these so perhaps url escaping would be the solution for this (would have to build support for that into URL). > The next problem I'm having is how to organize the mapper and > metadata for my application. What I want is a separate db file per > mailing list, so I had thought that each mlist would get its own > bound metadata, and I would define the Table in terms of that mlist- > specific metadata. Then I'd create the table and a mapper between my > application class and the table. However, as soon as I create the > mapper I get this exception: > > ArgumentError: Class '<class 'Mailman.SAMemberships.Member'>' already > has a primary mapper defined. Use is_primary=True to assign a new > primary mapper to the class, or use non_primary=True to create a non > primary Mapper > > But I don't think I want non-primary mappers here. I'm not sure what > to do because the table passed to mapper() is bound to a metadata > that is bound to the mlist-specific url. I'm not quite sure how to > arrange things so that I have a session/metadata per mlist. entity_name can be used to create multiple primary mappers for the same class, however thats for a fixed set of persistence schemes for a particular class; its not really meant to be for N persistence schemes. similarly for Table, the Table object represents the "concept" of a certain table but it no longer represents the "connection to Table X in database Y"; that was aptly pointed out as being too rigid in 0.1. if you have a particular Table metadata that is identical across many databases, you should work with a single Table/MetaData object and decouple the engine from it. this can be accomplished either by using straight MetaData combined with create_session(bind_to=engine) to create sessions specific to the database file youre working with (and straight SQL executed via passing ClauseElement objects to Engine/Connection execute()), or alternatively you can use DynamicMetaData and switch the underlying engine to the appropriate DB file (thread-locally of course) as needed. > > Is there a way to create the table only if it doesn't yet exist, or > to query whether the table exists? Currently I have to wrap my > table.create() call in a try/except to throw away the > OperationalError that gets thrown when I try to create the table that > already exists. try metadata.create_all() you can also call engine.dialect.has_table(tablename) as well. (Table should probably get an exists() function for this too). > > Finally (although I reserve the right to ask more questions later :), > there seems to be a problem with the way I want to do transactions. > For example, let's say I have a Members class and I create a new > Member instance, then call session.save(new_member). Until I flush > the session I can't issue a query that will return me that same > Member instance. That makes sense. However when I add a new member, > that is not my transaction boundary, so I don't want those changes > written permanently to the database. I'm hoping that nested > transactions will do the trick, IOW, create a transaction at my > natural boundary, flush the session to write a subtransaction, then > at my natural boundary, commit the outer transaction to permanently > write the data to the database. I haven't actually gotten far enough > to see if this will work with a SQLite backend, but perhaps you can > provide some insight here. > sure whenever you flush(), the changes get written to the DB within the scope of whatever transaction is in progress. you can then query and get things back, all before anything is literally committed to the database. Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users