Re: [sqlalchemy] Storing and Retrieving BLOB in SqlAlchemy

2013-02-27 Thread dalia
Hi Mauricio, Werner, Michael, Thank you for your replies. I understand storing the files in file system might be an easier option, but that would be my last option. If I can make it work with the database, I've got good reasons to go with it. I'm not trying to store an exisitng physical file

Re: [sqlalchemy] Storing and Retrieving BLOB in SqlAlchemy

2013-02-27 Thread Simon King
On Tue, Feb 26, 2013 at 2:44 PM, dalia dalia@gmail.com wrote: Hi, My intention is - to store .xls, .doc and .pdf files (with images in them) to store in a Oracle database and retrieve them. I'm using SQLAlchemy declarative code. The problem is, the data gets stored in the database but

Re: [sqlalchemy] Storing and Retrieving BLOB in SqlAlchemy

2013-02-27 Thread dalia
Thanks a lot Simon. I am using Pylons, but response.body actually worked. I can get my xls file alright now. Thanks for all your help! On Wednesday, February 27, 2013 11:40:22 AM UTC, Simon King wrote: On Tue, Feb 26, 2013 at 2:44 PM, dalia dali...@gmail.com javascript: wrote: Hi,

[sqlalchemy] [Q] SA 0.7.9 - missing from when using union_all and joinedload_all

2013-02-27 Thread Ladislav Lenart
Hello. Suppose I have the following mapped classes, A and B, that have two distinct M:N relationships, AB1 and AB2. If A.x is null, only relations in AB1 apply. If it is not null, only relations in AB2 apply. A also has 1:N relationship to C (one A can have more Cs). Finally, A is infact a joined

Re: [sqlalchemy] Better approach to filtering a relationship collection than using contains_eager()?

2013-02-27 Thread Michael Bayer
I'm not yet digging into your problem, but one remark would be that there's two levels to deal with here. One is figuring out exactly what SQL you want, independent of SQLAlchemy. It's not clear here if you've gotten that part yet. The next part is getting parts of that SQL to route into your

Re: [sqlalchemy] [Q] SA 0.7.9 - missing from when using union_all and joinedload_all

2013-02-27 Thread Michael Bayer
On Feb 27, 2013, at 12:21 PM, Ladislav Lenart lenart...@volny.cz wrote: Hello. Suppose I have the following mapped classes, A and B, that have two distinct M:N relationships, AB1 and AB2. If A.x is null, only relations in AB1 apply. If it is not null, only relations in AB2 apply. A also

Re: [sqlalchemy] Better approach to filtering a relationship collection than using contains_eager()?

2013-02-27 Thread Rob Crowell
Sure! Here's the query I am attempting to replicate: SELECT people.id AS person_id, people.name, towns.id AS town_id, towns.name FROM people INNER JOIN visited_destinations ON visited_destinations.person_id = people.id INNER JOIN towns ON towns.id = visited_destinations.town_id WHERE towns.name

Re: [sqlalchemy] Better approach to filtering a relationship collection than using contains_eager()?

2013-02-27 Thread Michael Bayer
oh. I saw you talking about at least one and exists and thought you had a more complex query.contains_eager() doesn't impact what's queried, only how results are used with the resulting objects, and is usually used with join(), just like this: session.query(Person).\

Re: [sqlalchemy] Better approach to filtering a relationship collection than using contains_eager()?

2013-02-27 Thread Rob Crowell
Ah okay, so you do recommend the contains_eager approach. I guess this is exactly the use-case it is designed for? I always get a little scared when I try using advanced features of SQLAlchemy :) One last question. The query here seems to take advantage of the fact that our table joins on

Re: [sqlalchemy] Better approach to filtering a relationship collection than using contains_eager()?

2013-02-27 Thread Michael Bayer
On Feb 27, 2013, at 2:40 PM, Rob Crowell rob.crow...@moat.com wrote: Ah okay, so you do recommend the contains_eager approach. I guess this is exactly the use-case it is designed for? I always get a little scared when I try using advanced features of SQLAlchemy :) One last question.

Re: [sqlalchemy] [Q] SA 0.7.9 - missing from when using union_all and joinedload_all

2013-02-27 Thread Ladislav Lenart
Hello. Thank you for your prompt answer. I will try to create a working example that demonstrates the issue. Though it will take me a couple of days, maybe weeks (my regular work followed by a vacation). I have another problem. I rephrased the SQL, because postgres's planner had issues with

Re: [sqlalchemy] [Q] SA 0.7.9 - missing from when using union_all and joinedload_all

2013-02-27 Thread Michael Bayer
On Feb 27, 2013, at 3:12 PM, Ladislav Lenart lenart...@volny.cz wrote: Hello. Thank you for your prompt answer. I will try to create a working example that demonstrates the issue. Though it will take me a couple of days, maybe weeks (my regular work followed by a vacation). I have

Re: [sqlalchemy] Better approach to filtering a relationship collection than using contains_eager()?

2013-02-27 Thread Rob Crowell
Oh cool! I was getting incorrect results putting VisitedDestinations.town in my contains_eager() call as you suggested, maybe I am doing something wrong: session = Session() visited_alias = aliased(Town) wishlist_alias = aliased(Town) q = session.query(Person) q =

[sqlalchemy] AbstractConcreteBase: When can I query it?

2013-02-27 Thread Derek Litz
Python 2.7.3 (default, Jan 4 2013, 14:06:23) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin Type help, copyright, credits or license for more information. import sqlalchemy print sqlalchemy.__version__ 0.8.0b2 Below is the code I was able to use to reproduce a

Re: [sqlalchemy] AbstractConcreteBase: When can I query it?

2013-02-27 Thread Michael Bayer
AbstractConcreteAbstraction doesn't know that it's mapped until other mappers configure themselves. In the absence of such an event, call sqlalchemy.orm.configure_mappers() when all subclasses of AbstractConcreteAbstraction have been declared to force this process to occur. On Feb 27, 2013,

Re: [sqlalchemy] AbstractConcreteBase: When can I query it?

2013-02-27 Thread Derek Litz
Thanks again Michael. A note in the http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/declarative.html#using-the-concrete-helpers section would be great! On Wednesday, February 27, 2013 6:25:24 PM UTC-6, Michael Bayer wrote: AbstractConcreteAbstraction doesn't know that it's mapped until

[sqlalchemy] Is querying a relationship on an AbstractBaseClass possible?

2013-02-27 Thread Derek Litz
Having fun with AbstractBaseClasses tonight :) ... Anyways am I missing something here as well? I tried playing with querying the AbstractBaseClass and filtering on sub classes but that just produced a query that did not execute. from sqlalchemy.engine import Engine from sqlalchemy import

Re: [sqlalchemy] Is querying a relationship on an AbstractBaseClass possible?

2013-02-27 Thread Michael Bayer
just features that weren't anticipated (I never use concrete inheritance). here's what will work for now. class AbstractConcreteAbstraction(AbstractConcreteBase, sqlite): __table_args__ = (UniqueConstraint('derpa', 'derp'),) id = Column(Integer, primary_key=True) derpa =

Re: [sqlalchemy] Is querying a relationship on an AbstractBaseClass possible?

2013-02-27 Thread Michael Bayer
simpler, just stick the relationship on ACA: session = Session(engine) print session.query(ConcreteConcreteAbstraction).filter( ConcreteConcreteAbstraction.something.has(id=1)).all() AbstractConcreteAbstraction.something = relationship(Something) print

Re: [sqlalchemy] [Q] SA 0.7.9 - missing from when using union_all and joinedload_all

2013-02-27 Thread Michael Bayer
OK, I've reconstructed mappings which correspond directly to your Query as given, and it produces the identical SQL. I've inserted a bunch of rows into all the tables so that a polymorphic result comes back, so that we can in fact verify that the ORM reads the client_id column correctly. Your