[sqlalchemy] Any way to determine whether the url exists or not?

2008-04-30 Thread Olli Wang
Hi, I'm trying to determine whether the url's database exists or not, but didn't find any approach. I created a sqlite engine: engine = create_engine('sqlite:///test.sqlite') And tried to connect it: engine.connect() But it just created the database file if not existed. So is there any way to

[sqlalchemy] Re: Any way to determine whether the url exists or not?

2008-04-30 Thread Kyle Schaffrick
On Wed, 30 Apr 2008 03:34:16 -0700 (PDT) Olli Wang [EMAIL PROTECTED] wrote: Hi, I'm trying to determine whether the url's database exists or not, but didn't find any approach. I created a sqlite engine: engine = create_engine('sqlite:///test.sqlite') And tried to connect it:

[sqlalchemy] Re: Any way to determine whether the url exists or not?

2008-04-30 Thread az
there's no generic way AFAIK. u could switch on the dbtype part of dburl, and do different things accordingly. see sqlalchemy/engine/url.py / make_url() or see dbcook.usage.sa_engine_defs.py for similar approach: http://dbcook.svn.sourceforge.net/viewvc/dbcook/trunk/dbcook/usage/ On Wednesday

[sqlalchemy] branch:user_defined_state questions

2008-04-30 Thread az
- replacing __init__(...) - i see that some effort is taken to keep the original signature. But the result wont be debuggable IMO. cant it be some_init(*a,**kw) doing whatever( *a,**kw) and/or calling original_init(*a,**kw) ? whats inside is not changing as sequence/logic anyway...

[sqlalchemy] Re: is MapperExtension.after_update() called before the UPDATE is issued to the DB?

2008-04-30 Thread Michael Bayer
On Apr 29, 2008, at 5:55 PM, David Bonner wrote: Hi, I'm trying to write a mapper extension that notifies a daemon about changes made to the DB that it needs to care about. But it looks like after_update() is actually getting called before the UPDATE is sent to the db. Not knowing a

[sqlalchemy] Re: subquery and inheritance

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 1:48 AM, kris wrote: If I add a simple correlate feature to Query in 0.5, you can use the raw Table object to bypass the ORM meaning of Dataset and Base. the query above is not quite complete but I can get an approximation like this: Is this functionality available

[sqlalchemy] Re: branch:user_defined_state questions

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 8:50 AM, [EMAIL PROTECTED] wrote: - replacing __init__(...) - i see that some effort is taken to keep the original signature. But the result wont be debuggable IMO. cant it be some_init(*a,**kw) doing whatever( *a,**kw) and/or calling original_init(*a,**kw) ?

[sqlalchemy] Re: is MapperExtension.after_update() called before the UPDATE is issued to the DB?

2008-04-30 Thread Rick Morrison
then queried the db *directly using sql*. It looks like the change hasn't made it to the DB yet Also possible is that you're using a an MVCC DB such as Postgres or Oracle, and you're looking at an old, pre-update version of the data, as your direct SQL would be in a separate transaction

[sqlalchemy] Re: branch:user_defined_state questions

2008-04-30 Thread jason kirtland
Michael Bayer wrote: On Apr 30, 2008, at 8:50 AM, [EMAIL PROTECTED] wrote: - replacing __init__(...) - i see that some effort is taken to keep the original signature. But the result wont be debuggable IMO. cant it be some_init(*a,**kw) doing whatever( *a,**kw) and/or calling

[sqlalchemy] Re: is MapperExtension.after_update() called before the UPDATE is issued to the DB?

2008-04-30 Thread David Bonner
On Wed, Apr 30, 2008 at 10:56 AM, Rick Morrison [EMAIL PROTECTED] wrote: then queried the db directly using sql. It looks like the change hasn't made it to the DB yet Also possible is that you're using a an MVCC DB such as Postgres or Oracle, and you're looking at an old, pre-update

[sqlalchemy] Re: is MapperExtension.after_update() called before the UPDATE is issued to the DB?

2008-04-30 Thread David Bonner
On Wed, Apr 30, 2008 at 9:29 AM, Michael Bayer [EMAIL PROTECTED] wrote: after_update() is called after all UPDATE statements have been issued for that particular mapper. This includes *only* the table that is mapped by that mapper, not any other mappers. Is it possible that you are

[sqlalchemy] Re: is MapperExtension.after_update() called before the UPDATE is issued to the DB?

2008-04-30 Thread Rick Morrison
I suppose that depends on the behavior of the DB-API interface, in this case I guess that's psycopg. Anyway, I'm certainly not sure if an MVCC snapshot that's causing your problem, but it does seem like at least a possibility. The certain way is to check the update status inside the same

[sqlalchemy] Re: branch:user_defined_state questions

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 8:50 AM, [EMAIL PROTECTED] wrote: should have one more argument iterator_func, and that to be passed whatever the Visitor's .iterate is, instead of using hardcoded fine. r4607: def traverse_using(iterator, obj, visitors): visit the given expression structure using

[sqlalchemy] Re: is MapperExtension.after_update() called before the UPDATE is issued to the DB?

2008-04-30 Thread David Bonner
oops, uncommenting the pdb.set_trace(), obviously. sorry. class MyExtension (MapperExtension) : def after_update (self, mapper, connection, instance) : #pdb.set_trace() pprint.pprint(instance) return EXT_CONTINUE -- david bonner [EMAIL PROTECTED]

[sqlalchemy] Re: is MapperExtension.after_update() called before the UPDATE is issued to the DB?

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 11:22 AM, David Bonner wrote: When this code drops me into pdb, the data in instance.notes looks like the new value, but querying the db in a separate process gets me the old value. flush() always uses a transaction, so when your pdb process hits, the transaction has

[sqlalchemy] Re: is MapperExtension.after_update() called before the UPDATE is issued to the DB?

2008-04-30 Thread David Bonner
On Wed, Apr 30, 2008 at 11:30 AM, Michael Bayer [EMAIL PROTECTED] wrote: flush() always uses a transaction, so when your pdb process hits, the transaction has not been committed yet and results are not visible outside of the transaction. the transactional keyword on Session does not mean

[sqlalchemy] sequence-related question

2008-04-30 Thread Eric Lemoine
Hello I insert a new line in a table using this: campfacility = Campfacility(prop1, prop2) model.Session.save(campfacility) model.Session.commit() The campfacility id is handled by a postgres sequence. What I'd like to do is: campfacility = Campfacility(prop1, prop2) seq =

[sqlalchemy] Re: branch:user_defined_state questions

2008-04-30 Thread az
On Wednesday 30 April 2008 18:25:25 Michael Bayer wrote: On Apr 30, 2008, at 8:50 AM, [EMAIL PROTECTED] wrote: should have one more argument iterator_func, and that to be passed whatever the Visitor's .iterate is, instead of using hardcoded fine. r4607: def traverse_using(iterator,

[sqlalchemy] Re: is MapperExtension.after_update() called before the UPDATE is issued to the DB?

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 12:15 PM, David Bonner wrote: On Wed, Apr 30, 2008 at 11:30 AM, Michael Bayer [EMAIL PROTECTED] wrote: flush() always uses a transaction, so when your pdb process hits, the transaction has not been committed yet and results are not visible outside of the transaction.

[sqlalchemy] Re: branch:user_defined_state questions

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 12:26 PM, [EMAIL PROTECTED] wrote: On Wednesday 30 April 2008 18:25:25 Michael Bayer wrote: On Apr 30, 2008, at 8:50 AM, [EMAIL PROTECTED] wrote: should have one more argument iterator_func, and that to be passed whatever the Visitor's .iterate is, instead of using

[sqlalchemy] Re: is MapperExtension.after_update() called before the UPDATE is issued to the DB?

2008-04-30 Thread David Bonner
On Wed, Apr 30, 2008 at 2:50 PM, Michael Bayer [EMAIL PROTECTED] wrote: if you want pre/post flush activities theres a SessionExtension which hooks into Session for that. You can set it up with the sessionmaker() function so that its always plugged in. thanks, i'll look into that. and

[sqlalchemy] Re: sequence-related question

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 12:56 PM, Eric Lemoine wrote: thread 1 thread 2 execute(seq) - nextid = n execute(seq) - nextid = n model.Session.save(campfacility) model.Session.save(campfacility) - BUG, nextid isn't correct whats correct here,

[sqlalchemy] Re: branch:user_defined_state questions

2008-04-30 Thread az
i have some obj.pre_save() hook-method that is called just before session.save_or_update( obj), to do last-point validations and/or setup of timestamp-like fields. There's an idea/ need to replace that with mapper_extension.before_insert() but i'm not sure if these are going to be

[sqlalchemy] Re: sequence-related question

2008-04-30 Thread Eric Lemoine
On Wed, Apr 30, 2008 at 9:02 PM, Michael Bayer [EMAIL PROTECTED] wrote: On Apr 30, 2008, at 12:56 PM, Eric Lemoine wrote: thread 1 thread 2 execute(seq) - nextid = n execute(seq) - nextid = n

[sqlalchemy] Re: sequence-related question

2008-04-30 Thread Eric Lemoine
On Wed, Apr 30, 2008 at 9:02 PM, Michael Bayer [EMAIL PROTECTED] wrote: On Apr 30, 2008, at 12:56 PM, Eric Lemoine wrote: thread 1 thread 2 execute(seq) - nextid = n execute(seq) - nextid = n

[sqlalchemy] Re: sequence-related question

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 3:23 PM, Eric Lemoine wrote: Yes, the sequence is my table's PK. What I want to know is the PK value of the line I'm going to insert (or I've just inserted). So I guess this is indeed INSERT RETURNING. if you pre-execute the sequence, the number you get back from it is

[sqlalchemy] Re: sequence-related question

2008-04-30 Thread Eric Lemoine
On Wed, Apr 30, 2008 at 9:23 PM, Eric Lemoine [EMAIL PROTECTED] wrote: On Wed, Apr 30, 2008 at 9:02 PM, Michael Bayer [EMAIL PROTECTED] wrote: On Apr 30, 2008, at 12:56 PM, Eric Lemoine wrote: thread 1 thread 2

[sqlalchemy] Aliasing automatic joins with relation.any()

2008-04-30 Thread Yannick Gingras
Hi, I have two classes, Item and ItemId where one Item can have multiple ItemIds accessible from its ref_ids relation. I can do: Item.query().filter(not_(Item.ref_ids.any(ref_id = OP-10-47000))) if I want all the items except the ones with an ItemId with ref_id set to OP-10-47000 and I can

[sqlalchemy] Re: sequence-related question

2008-04-30 Thread Eric Lemoine
On Wed, Apr 30, 2008 at 9:44 PM, Michael Bayer [EMAIL PROTECTED] wrote: On Apr 30, 2008, at 3:23 PM, Eric Lemoine wrote: Yes, the sequence is my table's PK. What I want to know is the PK value of the line I'm going to insert (or I've just inserted). So I guess this is indeed

[sqlalchemy] Re: sequence-related question

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 3:45 PM, Eric Lemoine wrote: With psycopg2, I know people using this: sql = INSERT INTO \%s\ (%s) VALUES (%s) % (self.table, columns, values) cursor = db.cursor() cursor.execute(str(sql), values) cursor.execute(SELECT currval('%s'); % sequence_name) id =

[sqlalchemy] Re: branch:user_defined_state questions

2008-04-30 Thread az
fine. r4607: def traverse_using(iterator, obj, visitors): visit the given expression structure using the given iterator of objects. yeah, i how i get the ClauseVisitor to use that... The idea was for the ClauseVisitor's traverse to use ClauseVisitor's iterate (or _iterate),

[sqlalchemy] Re: Aliasing automatic joins with relation.any()

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 3:51 PM, Yannick Gingras wrote: Hi, I have two classes, Item and ItemId where one Item can have multiple ItemIds accessible from its ref_ids relation. I can do: Item.query().filter(not_(Item.ref_ids.any(ref_id = OP-10-47000))) if I want all the items except the

[sqlalchemy] Re: Aliasing automatic joins with relation.any()

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 4:20 PM, Michael Bayer wrote: Although, I think it may be wise here if SQLA set the correlate value on the expression returned by any() to prevent these errors from occuring at all. Below is a patch that does it. It needs a little bit of tweaking to work with

[sqlalchemy] Session.merge vs. mapper extensions

2008-04-30 Thread Rick Morrison
I just started using session.merge, and I noticed that on session.flush(), the before_update mapper extension for the objects that have been merged into the session are not called. These are new instances, not previously persisted. Is there something I need to do to trigger this, or eesss a bug?

[sqlalchemy] Re: Session.merge vs. mapper extensions

2008-04-30 Thread Michael Bayer
On Apr 30, 2008, at 10:47 PM, Rick Morrison wrote: I just started using session.merge, and I noticed that on session.flush(), the before_update mapper extension for the objects that have been merged into the session are not called. These are new instances, not previously persisted.

[sqlalchemy] Re: Session.merge vs. mapper extensions

2008-04-30 Thread Rick Morrison
right, sorry, before_insert On Wed, Apr 30, 2008 at 11:18 PM, Michael Bayer [EMAIL PROTECTED] wrote: On Apr 30, 2008, at 10:47 PM, Rick Morrison wrote: I just started using session.merge, and I noticed that on session.flush(), the before_update mapper extension for the objects that

[sqlalchemy] Re: Session.merge vs. mapper extensions

2008-04-30 Thread Rick Morrison
is not being called. as you call tell, I'm having trouble with the keyboard tonight. first message was a typo, --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email