[sqlalchemy] Re: using limit w/ distinct on ORACLE (revise bug #536)
MSSQL uses the same type of row_number() technique, so an update that works with both would be great, if possible. Just so I'm clear on this, the plan is to leave the row_number() usage, but to auto-wrap queries using DISTINCT, is that right? Thx, Rick --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: post-populate extension (2)
Also be aware that the API to populate_instance() has changed (ironically, the very thing that I was worrying about in the thread) Update this: def populate_instance(self, mapper, selectcontext, row, instance, identitykey, isnew): if isnew: mapper.populate_instance(selectcontext, instance, row, identitykey, isnew) instance.onload() return None return EXT_PASS to this: def populate_instance(self, mapper, selectcontext, row, instance, **kwargs): if kwargs.get('isnew') and hasattr(instance, 'onload'): mapper.populate_instance(selectcontext, instance, row, **kwargs) instance.onload() return None return EXT_CONTINUE On Tue, Mar 25, 2008 at 12:57 PM, Michael Bayer [EMAIL PROTECTED] wrote: we have a new hook that will be coming soon called something like __reconstitute__(), which will be called on instances after they've been created and had their initial population from the result row. Note that eagerly-loaded collections might not be fully loaded at this stage. at the moment the populate_instance() hook is what works in the current version of 0.4. On Mar 25, 2008, at 7:05 AM, Nebur wrote: I'm going to post-populate an instance, and there's a thread which is exactly about my question but fairly old: http://groups.google.de/group/sqlalchemy/browse_thread/thread/7467f8e9d86b1749/ Is there a post_populate hook in the current SA 0.4.x, or is Ricks way (using populate_instance) still the best ? Ruben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Attribute error
On Mar 26, 2008, at 1:34 PM, pyplexed wrote: Hi all, I'm a complete newcomer to SA, and I've tried to adapt an example I found on-line to look a bit more like the problem I'm trying to solve. If I save an object to my session, and then flush it, I'm getting an error which Google can't help me with: AttributeError: 'MetaData' object has no attribute 'contextual_connect' I saw a post that said an attribute error can happen if the Metadata class name is mistakenly bound to an instance. I don't think that's the case in my script. I wondered if anyone here would be able to take a quick look at my (no doubt lousy) code and let me know what I'm doing wrong? The code is here: http://pubcat.org/alchemyTest.py sessionmaker needs to bind to the Engine, not the MetaData (this might be something we want to detect, its an understandable mistake): Session = sessionmaker(bind=engine, autoflush=True, transactional=False) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: using limit w/ distinct on ORACLE (revise bug #536)
If we want to do it across the board for MS-SQL, we can. But I'm not as confident in its usage as using a LIMIT keyword supplied by the database. It would take a lot of testing to ensure it works in all cases. Agreed, but there's no version of MSSQL that supports either the LIMIT or OFFSET keyword. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Spaces in Column Names (MSSQL)
can you try my test script with an MS-SQL database and see what you get ? Works with no errors, column names quoted with square brackets. Here's the echo output: 2008-03-26 15:11:41,342 INFO sqlalchemy.engine.base.Engine.0x..d4 CREATE TABLE [some table] ( [primary col] INTEGER NOT NULL IDENTITY(1,1), [the data] VARCHAR(50), PRIMARY KEY ([primary col]) ) 2008-03-26 15:11:41,343 INFO sqlalchemy.engine.base.Engine.0x..d4 {} 2008-03-26 15:11:42,139 INFO sqlalchemy.engine.base.Engine.0x..d4 COMMIT 2008-03-26 15:11:42,397 INFO sqlalchemy.engine.base.Engine.0x..d4 BEGIN 2008-03-26 15:11:42,408 INFO sqlalchemy.engine.base.Engine.0x..d4 INSERT INTO [some table] ([the data]) VALUES (%(data)s) 2008-03-26 15:11:42,408 INFO sqlalchemy.engine.base.Engine.0x..d4 {'data': 'some data'} 2008-03-26 15:11:42,459 INFO sqlalchemy.engine.base.Engine.0x..d4 COMMIT 2008-03-26 15:11:42,472 INFO sqlalchemy.engine.base.Engine.0x..d4 SELECT TOP 2 [some table].[primary col] AS [some table_primary col], [some table].[the data] AS [some table_the data] FROM [some table] WHERE [some table].[primary col] = %(some table_primary col_1)s ORDER BY [some table].[primary col] 2008-03-26 15:11:42,473 INFO sqlalchemy.engine.base.Engine.0x..d4 {'some table_primary col_1': 1} --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] listing a table's relationships
hello friends, is there a way to query a table object of all the relationships it's involved with? both onoe2many, many2one, many2many etc. thanks in advance, alex --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Session based query issuing outer join for two mapped tables
On Mar 26, 11:46 pm, Crispin Wellington [EMAIL PROTECTED] wrote: select * from countries left join country_synonyms; Here are my attempts and their results: Session.query(Country).join(CountrySynonym).all() InvalidRequestError: Mapper 'Mapper|Country|countries' has no property 'class 'helloworld.model.CountrySynonym'' Session.query(Country,CountrySynonym).join(CountrySynonym).all() InvalidRequestError: Mapper 'Mapper|Country|countries' has no property 'class 'helloworld.model.CountrySynonym'' Session.query(Country).join(CountrySynonym.country_id).all() AttributeError: 'ColumnProperty' object has no attribute '_is_self_referential' And so on... query.join() only joins on relations that you set up between mappers. so if you set up your mappers like: mapper(Country, countries, properties={ 'synonyms':relation(CountrySynonym) }) mapper(CountrySynonym, country_synonyms) then your join would just be: query(Country).join('synonyms') if you want to join tables together where you haven't told your mappers about their relationship (or you want to join in some other way besides whats configured), then you use the Table objects again, but you can still use them with Query via select_from() query(Country).select_from(countries.join(country_synonyms))... With a regular inner join like you're doing, theres also just setting it up in the WHERE criterion: query(Country).filter(Country.id==CountrySynonym.country_id) All the docs use a Table() based approach like sql.execute(countries.join(country_synonyms)... but I want to use the Mapped objects as that's what I'm using everywhere else. I've found the docs on sqlalchemy to focus on the Table() and engine based interfaces, but the docs focusing on objects and sessions leave a lot of guessing. Plenty of docs on the subject in the ORM tutorial. For examples of query.join(), see: http://www.sqlalchemy.org/docs/04/ormtutorial.html#datamapping_joins other important ORM chapters are Mapper Configuration and Using the Session. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---