[sqlalchemy] Mapping and updating tables with no primary key

2007-08-10 Thread Andy Hird
Hi all. Possibly a real basic question but one I seem to have gone round in circles with and failed to find an answer for so far. I have an (Oracle) db with some tables similar to this. I'll create a simple in-memory sqlite db just to illustrate. from sqlalchemy import * db =

[sqlalchemy] Re: NULLS FIRST/LAST support?

2007-08-10 Thread Oleg Deribas
Hello, Michael Bayer said the following on 09.08.2007 22:53: OK just to double check, the syntax looks like: SELECT * FROM sometable ORDER BY foo NULLS FIRST SELECT * FROM sometable ORDER BY foo DESC NULLS LAST Yes. ? i.e. is DESC/ASC before the NULLS part ? or doesn't matter ? It

[sqlalchemy] Re: NULLS FIRST/LAST support?

2007-08-10 Thread Michael Bayer
OK ive added ticket #723 for this, it will go into 0.4xx. On Aug 10, 2007, at 5:13 AM, Oleg Deribas wrote: Hello, Michael Bayer said the following on 09.08.2007 22:53: OK just to double check, the syntax looks like: SELECT * FROM sometable ORDER BY foo NULLS FIRST SELECT * FROM

[sqlalchemy] Re: new session docs !

2007-08-10 Thread Michael Bayer
On Aug 10, 2007, at 5:18 AM, Alexandre CONRAD wrote: It sounds to me that the session is global and needs to be cleared everytime. Which I think is wrong (or SessionContext works differently). I think a *new* session should be created and attached to every new request. The session is

[sqlalchemy] Re: Mapping and updating tables with no primary key

2007-08-10 Thread Michael Bayer
On Aug 10, 2007, at 3:18 AM, Andy Hird wrote: because it's trying to execute the sql: UPDATE account_stuff SET credit=? because I assume account_stuff has no primary key (updates to account_ids specify a where clause). How can I get the above to work? I assume the join in the mapper

[sqlalchemy] Re: Unit of work and optimistic locking

2007-08-10 Thread Grzegorz Adam Hankiewicz
Michael Bayer wrote: SQLAlchemy has always supported this feature using the version_id_col keyword argument to mapper(), which is described at: http://www.sqlalchemy.org/docs/04/ sqlalchemy_orm.html#docstrings_sqlalchemy.orm_modfunc_mapper Argh, just a little bit too far in the

[sqlalchemy] Re: Problem with subquery

2007-08-10 Thread Mike Orr
Er, where is it you're not supposed to use .c? The code in MikeB's example seems to have .c in every possible location. How do you access a column without .c? On 8/10/07, Jeronimo [EMAIL PROTECTED] wrote: Excelent ! It works perfectly !! Thank you very much Michael. I was going crazy trying

[sqlalchemy] Re: Unit of work and optimistic locking

2007-08-10 Thread Michael Bayer
On Aug 10, 2007, at 8:32 AM, Grzegorz Adam Hankiewicz wrote: Is there any documentation about this or do sqlalchemy applications deal with concurrent writes in another way? If the unit of work tracked those internal version numbers the flushing would fail and an exception raised, but

[sqlalchemy] Re: Unit of work and optimistic locking

2007-08-10 Thread Michael Bayer
On Aug 10, 1:04 pm, Grzegorz Adam Hankiewicz [EMAIL PROTECTED] wrote: Cool. In the unit test you provide the version_id_col parameter is specified manually. Does SQLAlchemy do automatic reflection on the table and use a version_id column if it already exists, without having to specify it on

[sqlalchemy] Re: new session docs !

2007-08-10 Thread Mike Orr
On 8/10/07, Alexandre CONRAD [EMAIL PROTECTED] wrote: Okay Mike, about scoped_session(), I think I got it right this time. I was trying to get inspired from SAContext, how it's beeing wrapped around with Pylons. Since SAContext has not yet upgraded to SA 0.4, maybe I was just getting

[sqlalchemy] Re: How to dynamically create where-clauses

2007-08-10 Thread Christoph Haas
On Fri, Aug 10, 2007 at 02:51:51PM +0200, Hermann Himmelbauer wrote: My web-application, that is in front of SQLAlchemy has various input-fields, which should act as a where-clause (with like()), a query looks e.g. like this:

[sqlalchemy] Re: Problem with subquery

2007-08-10 Thread Jeronimo
Excelent ! It works perfectly !! Thank you very much Michael. I was going crazy trying to figure how to move subquery to the from clause. On Aug 9, 8:06 pm, Michael Bayer [EMAIL PROTECTED] wrote: OK sorry, i didn't look carefully enough. when you use a scalar subquery, you shouldn't access

[sqlalchemy] Re: Using SA to move data between databases

2007-08-10 Thread sdobrev
On Thursday 09 August 2007 13:04:44 Paul Johnston wrote: Hi, A little update; Also, in the same direction, complete copy of some database seems to consist of (at least) 3 stages: 1 recreate/remove the old one if it exists 2 copy structure 3 copy data 3 is your copy loop, which

[sqlalchemy] Re: Using SA to move data between databases

2007-08-10 Thread Paul Johnston
Hi, wouldn't this be working equivalent? it also copes with empty tables.. Yep, I like yours better. Thanks! i'm Wondering if all the unicode strings (at least table/column names) should be converted back into plain strings as they have been before autoload reflecting them from database.

[sqlalchemy] Re: new session docs !

2007-08-10 Thread Alexandre CONRAD
Okay Mike, about scoped_session(), I think I got it right this time. I was trying to get inspired from SAContext, how it's beeing wrapped around with Pylons. Since SAContext has not yet upgraded to SA 0.4, maybe I was just getting inspired from some different mechanism. Or SAContext it doing

[sqlalchemy] Re: Using SA to move data between databases

2007-08-10 Thread sdobrev
On Thursday 09 August 2007 13:04:44 Paul Johnston wrote: Hi, A little update; this code handles the case where columns have a key attribute: model = __import__(sys.argv[1]) if sys.argv[2] == 'copy': seng = create_engine(sys.argv[3]) deng = create_engine(sys.argv[4]) for tbl

[sqlalchemy] Re: Using SA to move data between databases

2007-08-10 Thread Paul Johnston
Hi, 1 recreate/remove the old one if it exists how about 1? it also does depend badly on db-dialect. Personally, I'd do this step manually. Not sure I quite trust a script that has the potential to drop database btw: why is the 'text_as_varchar=1' considered only if it is in url (see

[sqlalchemy] Unit of work and optimistic locking

2007-08-10 Thread Grzegorz Adam Hankiewicz
Hi. I've been reading the documentation on the unit of work at http://www.sqlalchemy.org/docs/04/sqlalchemy_orm_session.html and I wonder how this can be merged with what I've seen called as optimistic locking. By optimistic locking I understand the possibility of tracking if two users

[sqlalchemy] How to dynamically create where-clauses

2007-08-10 Thread Hermann Himmelbauer
Hi, My web-application, that is in front of SQLAlchemy has various input-fields, which should act as a where-clause (with like()), a query looks e.g. like this: session.query(MyObj).filter(table1.c.input1.like(inputfield_1+'%'),

[sqlalchemy] Re: How to dynamically create where-clauses

2007-08-10 Thread Dave Marsh
I haven't tried it with your specific example, but I'm pretty sure the theory should work just the same. The first thing you need to do is create a list of the clause objects. The other thing you'll need is a way to associate the input names with the column names (either make them the same or

[sqlalchemy] Re: Problem with subquery

2007-08-10 Thread Michael Bayer
On Aug 10, 1:56 pm, Mike Orr [EMAIL PROTECTED] wrote: Er, where is it you're not supposed to use .c? The code in MikeB's example seems to have .c in every possible location. How do you access a column without .c? ive clarified this in 0.4's behavior. lets take a query like this:

[sqlalchemy] Re: Using SA to move data between databases

2007-08-10 Thread sdobrev
btw: why is the 'text_as_varchar=1' considered only if it is in url (see mssql.py create_connect_args()) and not if it is in the connect_args argument to create_engine()? Fair question, and the short answer is because that's all I needed. We did have a discussion about unifying

[sqlalchemy] Re: Using SA to move data between databases

2007-08-10 Thread sdobrev
i'm Wondering if all the unicode strings (at least table/column names) should be converted back into plain strings as they have been before autoload reflecting them from database. Well, some databases do support unicode identifier names, some don't. I'd say don't do any conversion for