[sqlalchemy] Re: 2 questions

2007-11-13 Thread svilen

clarification for this below; i have non-ORM updates happening inside 
ORM transaction (in after_insert() etc). How to make them use the 
parent transaction? i have a connection there.

  and, why atomic updates also have with commit after them? or is
  this sqlite-specific?
 
  every CRUD operation requires a commit.  DBAPI is always inside
  of a transaction.

 mmm i mean i have bunch of inserts and updates without a commit,
 and then several atomic updates come with their own commits. and
 then one more commit at the end.
 e.g.
 * SA: INFO BEGIN
 * SA: INFO UPDATE SequenceCounter SET curNum=? WHERE
 SequenceCounter.db_id = ?
 * SA: INFO [2, 8]
 * SA: INFO INSERT INTO Nalichnost (kolvo_kym, cena, obj_id,
 data_godnost, sklad_id, disabled, time_valid, kolvo_ot, stoka_id,
 time_trans) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
 * SA: INFO ['0', '978', None, None, 3, 0, None, '0', 1, None]
 * SA: INFO INSERT INTO Nalichnost (kolvo_kym, cena, obj_id,
 data_godnost, sklad_id, disabled, time_valid, kolvo_ot, stoka_id,
 time_trans) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
 * SA: INFO ['0', '94', None, None, 3, 0, None, '0', 1, None]
 ...
 * SA: INFO INSERT INTO DocItem (kolichestvo, data_godnost,
 sk_ot_id, number, sk_kym_id, opisanie, cena, stoka_id, doc_id)
 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
 * SA: INFO ['702', None, None, 3, 5, None, '668', 1, 2]
 * SA: INFO INSERT INTO DocItem (kolichestvo, data_godnost,
 sk_ot_id, number, sk_kym_id, opisanie, cena, stoka_id, doc_id)
 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
 * SA: INFO ['422', None, None, 4, 6, None, '17', 1, 2]

 * SA: INFO UPDATE Nalichnost SET
 kolvo_ot=(coalesce(Nalichnost.kolvo_ot, ?) + ?) WHERE
 Nalichnost.db_id = ?
 * SA: INFO [0, 643, 4]
 * SA: INFO COMMIT
 * SA: INFO UPDATE Nalichnost SET
 kolvo_kym=(coalesce(Nalichnost.kolvo_kym, ?) + ?) WHERE
 Nalichnost.db_id = ?
 * SA: INFO [0, 643, None]
 * SA: INFO COMMIT
 * SA: INFO UPDATE Nalichnost SET
 kolvo_ot=(coalesce(Nalichnost.kolvo_ot, ?) + ?) WHERE
 Nalichnost.db_id = ?
 * SA: INFO [0, 702, 5]
 * SA: INFO COMMIT
 * SA: INFO UPDATE Nalichnost SET
 kolvo_kym=(coalesce(Nalichnost.kolvo_kym, ?) + ?) WHERE
 Nalichnost.db_id = ?
 * SA: INFO [0, 702, None]
 * SA: INFO COMMIT
 * SA: INFO UPDATE Nalichnost SET
 kolvo_ot=(coalesce(Nalichnost.kolvo_ot, ?) + ?) WHERE
 Nalichnost.db_id = ?
 * SA: INFO [0, 9, 3]
 * SA: INFO COMMIT
 * SA: INFO COMMIT



 


--~--~-~--~~~---~--~~
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: 2 questions

2007-11-13 Thread Rick Morrison
i have non-ORM updates happening inside
ORM transaction (in after_insert() etc). How to make them use the
parent transaction? i have a connection there.

You can pass in the Session and use Session.execute() to reuse the session
connection.

--~--~-~--~~~---~--~~
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: 2 questions

2007-11-13 Thread Rick Morrison
in the after_*() there are (mapper, connection, instance) arguments -
but there's no session. Any way to get to that? mapext.get_session()
does not look like one

http://www.sqlalchemy.org/docs/04/sqlalchemy_orm.html#docstrings_sqlalchemy.orm_modfunc_object_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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: 2 questions

2007-11-13 Thread svilen

On Monday 12 November 2007 23:11:25 Michael Bayer wrote:
 On Nov 12, 2007, at 2:07 PM, [EMAIL PROTECTED] wrote:
  hi
  1st one:  i am saving some object; the mapperExtension of the
  object fires additional atomic updates of other things elsewhere
  (aggregator).
  These things has to be expired/refreshed... if i only knew them.
  For certain cases, the object knows exactly which are these
  target things. How (when) is best to expire these instances, i.e.
  assure that nexttime they are used they will be re-fetched?
  a) in the mapperext - this would be before the flush?
  b) later, after flush, marking them somehow ?

 the public way to mark an instance as expired is
 session.expire(instance).  if you wanted to do this inside the
 mapper extension, i think its OK as long as you do the expire
 *after* the object has been inserted/updated (i.e. in
 after_insert() or after_update()).
lets say A points to B and A.price is accumulated in the B, and that B 
needs be expired.
i've done expire in the A.mapExt.after_insert(). 
but A trouble comes when creating both A and B: they are not not yet 
persistent and the expire() (as well as the refresh() hits this:
session.refresh( g)
  File sqlalchemy/orm/session.py, line 725, in refresh
if self.query(obj.__class__)._get(obj._instance_key, reload=True) 
is None:
AttributeError: _instance_key

i'm not sure if i am doing proper thing at all.
Something like i need intermediate flush() to get B in the database 
first; then the insert of A will update that B and expire it 
eventualy.
i.e. i need to have the B record in the DB in order to have the 
aggregation /update working; else i am updating nothing...

--~--~-~--~~~---~--~~
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: 2 questions

2007-11-13 Thread Michael Bayer


On Nov 13, 2007, at 2:00 PM, svilen wrote:


 i'm not sure if i am doing proper thing at all.
 Something like i need intermediate flush() to get B in the database
 first; then the insert of A will update that B and expire it
 eventualy.
 i.e. i need to have the B record in the DB in order to have the
 aggregation /update working; else i am updating nothing...


OK, look into SessionExtension; you can use it for post-flush hooks. 
  

--~--~-~--~~~---~--~~
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: 2 questions

2007-11-12 Thread Michael Bayer


On Nov 12, 2007, at 2:07 PM, [EMAIL PROTECTED] wrote:


 hi
 1st one:  i am saving some object; the mapperExtension of the object
 fires additional atomic updates of other things elsewhere  
 (aggregator).
 These things has to be expired/refreshed... if i only knew them.
 For certain cases, the object knows exactly which are these target
 things. How (when) is best to expire these instances, i.e. assure that
 nexttime they are used they will be re-fetched?
 a) in the mapperext - this would be before the flush?
 b) later, after flush, marking them somehow ?

the public way to mark an instance as expired is  
session.expire(instance).  if you wanted to do this inside the mapper  
extension, i think its OK as long as you do the expire *after* the  
object has been inserted/updated (i.e. in after_insert() or  
after_update()).

We also have the capability to mark any group of attributes as  
expired. however I havent gotten around to building a nice public API  
for that, though i can show you the non-public way if you want to play  
with it.  This API is used by the mapper after it saves your instance  
to mark attribues which require a post-fetch.

What I'd like to do, and this has been frustrating me a bit, is to  
bring the expire the whole instance, expire a group of attributes,  
reload a group of attributes, and reload an instance under one  
implementation umbrella - right now theres some repetition in there  
among Mapper, Query._get() and DeferredColumnLoader.  I've sort of  
wanted to address the whole thing at once.



 and, why atomic updates also have with commit after them? or is this
 sqlite-specific?

every CRUD operation requires a commit.  DBAPI is always inside of a  
transaction.



 2nd one: how to compare with a Decimal? i.e. tableA.c.column ==  
 Decimal('7')
 ah forget,  i found that, passing asdecimal =True to column's  
 Numeric()
 definition.

 btw, the precision/length arguments of Numeric seems misplaced??
 isnt format 10.2 meaning length 10 precision 2?
 or the meaning of length and precision is different here?

i think someone posted a ticket to change our terminology to  
precision/scale.  ive *no* idea how the word length got in there,  
it was probably me very early on but I cant find any document anywhere  
that might have suggested to me that its called length.



--~--~-~--~~~---~--~~
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: 2 questions

2007-11-12 Thread sdobrev


 hi
 1st one:  i am saving some object; the mapperExtension of the object
 fires additional atomic updates of other things elsewhere  
 (aggregator).
 These things has to be expired/refreshed... if i only knew them.
 For certain cases, the object knows exactly which are these target
 things. How (when) is best to expire these instances, i.e. assure that
 nexttime they are used they will be re-fetched?
 a) in the mapperext - this would be before the flush?
 b) later, after flush, marking them somehow ?
 

 the public way to mark an instance as expired is  
 session.expire(instance).  if you wanted to do this inside the mapper  
 extension, i think its OK as long as you do the expire *after* the  
 object has been inserted/updated (i.e. in after_insert() or  
 after_update()).
   
in the after_*() there are (mapper, connection, instance) arguments - 
but there's no session. Any way to get to that? mapext.get_session() 
does not look like one


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---