[sqlalchemy] filtered or computed version of an existing relation?

2009-06-18 Thread AF
OK, next question. Well... two related questions. :) 1) In general, inside an object's method def, where I am doing arbitrary calculations, how can I get access to the session the object is bound to in order to run other queries? 2) More specifically, I want to make a filtered and computed

[sqlalchemy] Re: Two enhancement proposals for orm.Query

2009-06-18 Thread Adrian von Bidder
On Wednesday 17 June 2009 19.08:10 klaus wrote: ... whether a query will yield any result ... The best approximation seems to be query.first() is not None which can select a lot of columns. I often see query.count() 0 which can become quite expensive on a DBMS like PostgreSQL.

[sqlalchemy] safe (or paranoid) deletion

2009-06-18 Thread Alberto Granzotto
Hi, I'm using sqlalchemy 0.4.8 and I'm looking for a safe deletion extension (if exists one). With safe deletion I mean to mark a record as deleted, not to physically delete it, for example there is an extension for RoR called acts as paranoid[1]. This extension add a deleted_at field to the

[sqlalchemy] SA 0.4 with SQLServer and PyODBC Unicode data into nvarchar column

2009-06-18 Thread cristiroma
Hello, I have a question regarding SQLAlchemy(0.4) with PyODBC, SQLServer 2008. I want to insert Unicode data and query values should be prefixed with 'N' like INSERT INTO test VALUES(N'Сърцето и черният й дроб'). Is this possible with SA 0.4? The main problem with SQL Server is that needs

[sqlalchemy] Re: relation error?

2009-06-18 Thread Michael Bayer
On Jun 18, 2009, at 1:58 AM, allen.fowler wrote: you can, you can use a validator that rejects all changes, or if you're brave you can create a custom __setattribute__ method that brokers all attribute setter access. the former is in the SQLA mapping docs the latter is part of

[sqlalchemy] Re: safe (or paranoid) deletion

2009-06-18 Thread Michael Bayer
On Jun 18, 2009, at 6:03 AM, Alberto Granzotto wrote: Hi, I'm using sqlalchemy 0.4.8 and I'm looking for a safe deletion extension (if exists one). With safe deletion I mean to mark a record as deleted, not to physically delete it, for example there is an extension for RoR called acts as

[sqlalchemy] Re: session flush

2009-06-18 Thread Michael Bayer
On Jun 18, 2009, at 1:02 AM, Michael Mileusnich wrote: I know I have asked this before but I would like some clarification. If I do something like : i = query(table).all for instance in i: thread_class(i.ID) thread_class.start() del thread_class and do an additional query in the

[sqlalchemy] Re: filtered or computed version of an existing relation?

2009-06-18 Thread Michael Bayer
On Jun 18, 2009, at 2:27 AM, AF wrote: OK, next question. Well... two related questions. :) 1) In general, inside an object's method def, where I am doing arbitrary calculations, how can I get access to the session the object is bound to in order to run other queries?

[sqlalchemy] Re: SA 0.4 with SQLServer and PyODBC Unicode data into nvarchar column

2009-06-18 Thread Michael Bayer
PyODBC accepts unicode strings (and by that I mean Python unicode, u'some string') directly on most platforms. No N character is needed (unless PyODBC or the odbc driver does this behind the scenes). Our MSSQL dialect does detect certain builds where this is not possible and instead

[sqlalchemy] Optimizing joined entity loads

2009-06-18 Thread Daniel
Hi list! It's been a long time since I've posted here. SA is still the best Python ORM; thanks for all your hard work Mike! Now, the question. I've got a set of related entities: Order (has items) Item (has attributes) Attribute I am working on optimizing the loading and have run into a

[sqlalchemy] Re: SA 0.4 with SQLServer and PyODBC Unicode data into nvarchar column

2009-06-18 Thread phrrn...@googlemail.com
You should put this into your .freetds.conf file to ensure that FreeTDS will tell iconv to do the right thing (my understanding is that all unicode data is encoded to UCS-2 by FreeTDS) tds version = 8.0 client charset = UTF-8 SQL Alchemy create_engine has an encoding kwarg:

[sqlalchemy] Re: Optimizing joined entity loads

2009-06-18 Thread Michael Bayer
On Jun 18, 2009, at 11:09 AM, Daniel wrote: Hi list! It's been a long time since I've posted here. SA is still the best Python ORM; thanks for all your hard work Mike! Now, the question. I've got a set of related entities: Order (has items) Item (has attributes) Attribute I am

[sqlalchemy] Re: SA 0.4 with SQLServer and PyODBC Unicode data into nvarchar column

2009-06-18 Thread Cristian Romanescu
Well, out of the box it didn't work, I pasted a sample code here: http://pastebin.com/m104b32e0 (note that strings are bulgarian characters not #1040 as put by pastebin. My FreeTDS/ODBC are: --- freetds.conf [Observations_TDS] host = 10.0.0.50 port = 1433 tds

[sqlalchemy] Re: safe (or paranoid) deletion

2009-06-18 Thread Alberto Granzotto
On 18 Giu, 15:38, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 18, 2009, at 6:03 AM, Alberto Granzotto wrote: Hi, I'm using sqlalchemy 0.4.8 and I'm looking for a safe deletion extension (if exists one). With safe deletion I mean to mark a record as deleted, not to

[sqlalchemy] Re: SA 0.4 with SQLServer and PyODBC Unicode data into nvarchar column

2009-06-18 Thread Cristian Romanescu
The wirdest thing is that if I write: ob = Test2('just a test') session.save(ob) session.commit() 2009-06-18 17:08:15,251 INFO sqlalchemy.engine.base.Engine.0x..74 INSERT INTO test2 (comment) VALUES (?) 2009-06-18 17:08:15,251 INFO sqlalchemy.engine.base.Engine.0x..74 ['just a test'] 2009-06-18

[sqlalchemy] Re: safe (or paranoid) deletion

2009-06-18 Thread Michael Bayer
On Jun 18, 2009, at 1:47 PM, Alberto Granzotto wrote: On 18 Giu, 15:38, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 18, 2009, at 6:03 AM, Alberto Granzotto wrote: Hi, I'm using sqlalchemy 0.4.8 and I'm looking for a safe deletion extension (if exists one). With safe

[sqlalchemy] Re: Optimizing joined entity loads

2009-06-18 Thread millerdev
I dont really understand the case here. My first example wasn't very good. In an attempt to keep it simple I actually made it too simple. Here's another example: Order (has items) Item (has attributes, has tags) Attribute Tag If I set both Item.attributes and Item.tags to eager-load, then my

[sqlalchemy] Re: Optimizing joined entity loads

2009-06-18 Thread millerdev
Clarification: If I set both Item.attributes and Item.tags to eager-load, then my result set size is the product of len(attributes) * len(tags), which is where the result set becomes HUGE. I jumped right from the eager-load to the completely non-optimized (no eager loading) scenario: This

[sqlalchemy] Re: Optimizing joined entity loads

2009-06-18 Thread Michael Bayer
On Jun 18, 2009, at 2:19 PM, millerdev wrote: This would be done by the loader strategy (probably a variant of LazyLoader), which would issue a single query. The result of that query would be used to populate the attributes collection of each item on the order. hey Daniel - Good to have

[sqlalchemy] Re: Optimizing joined entity loads

2009-06-18 Thread millerdev
So this is some variant of, i have a bunch of objects and I'd like to   ... snip lots of reasons why this should not be a standard feature Yeah, I understand what I'm asking for here, and I would never expect this kind of optimization to kick in by default. Instead, it would only be used in

[sqlalchemy] preview an update?

2009-06-18 Thread Catherine Devlin
I'm building a complex ETL tool with SQLAlchemy that will sometimes need to let the user preview a changed record - not actually carry out the update, just find out which fields would be changed, and to what values. I'm having trouble figuring out a good way to do it. Is there a way to get a

[sqlalchemy] Re: preview an update?

2009-06-18 Thread Michael Bayer
On Jun 18, 2009, at 4:27 PM, Catherine Devlin wrote: I'm building a complex ETL tool with SQLAlchemy that will sometimes need to let the user preview a changed record - not actually carry out the update, just find out which fields would be changed, and to what values. I'm having trouble