Oleg Broytmann <[EMAIL PROTECTED]> writes: > Hello. A simplified version of your program
I should have written it myself instead of just copy & paste parts of the code. Sorry. > ---------- > from datetime import datetime > > class Usuario(SQLObject): > name = StringCol(default=None) > > class TipoFerramenta(SQLObject): > descricao = UnicodeCol(default=None) > > # Auditing > incluidoPor = ForeignKey('Usuario', default=None, cascade=False) > incluidoEm = DateTimeCol(default=datetime.now) > alteradoPor = ForeignKey('Usuario', default=None, cascade=False) > alteradoEm = DateTimeCol(default=datetime.now) > > > Usuario.createTable() > usuario = Usuario() > > > TipoFerramenta.createTable() > > tipo_ferramenta = TipoFerramenta() > > tipo_ferramenta.set( > descricao = 'descricao', > alteradoPor = usuario, > ) > ---------- > > really runs two UPDATEs, but they are two different updates: > > 1/Query : UPDATE tipo_ferramenta SET alterado_por_id = (1) WHERE id = (1) > 1/QueryR : UPDATE tipo_ferramenta SET alterado_por_id = (1) WHERE id = (1) > 1/COMMIT : auto > 1/Query : UPDATE tipo_ferramenta SET descricao = ('descricao') WHERE id = > (1) > 1/QueryR : UPDATE tipo_ferramenta SET descricao = ('descricao') WHERE id = > (1) > 1/COMMIT : auto > > The first one updates foreign key. Shouldn't both be updated in the same command since I used a ".set()" instead of updating each attribute separately? I'd expect it to run one command like UPDATE tipo_ferramenta SET descricao = ('descricao'), alterado_por_id = (1) WHERE id = (1) (which comes first -- descricao or alterado_por_id -- is irrelevant...) If I had more FKs on this '.set()', would there be more UPDATEs or they'd be grouped and I'll always end up with only one for FKs and one for the other values? I have two concerns here... One is that I have triggers that act on UPDATE on some tables with several FKs and they change data (do some calculations) when they're run. Some of these triggers trigger events on other tables. So, one UPDATE can make the DB work for some time, running them multiple times would be a problem -- I might get wrong results or stop some processing because some flag has been set on the first update... -- besides it would demand resources that are excessive. If I needed to guarantee that only one update was run, should I use sqlbuilder instead? Grouping all changes would also make SQL Object more performing on updates... > PS. I hope you understand the difference between > alteradoEm = DateTimeCol(default=datetime.now) > and > alteradoEm = DateTimeCol(default=datetime.now()) Yes ;-) Thanks. One will compute the time at the class instantiation -- i.e. when I insert a record -- and the other at class declaration (i.e. when I start the program). There's a reason -- project rules... -- for it to be now() and not now. Thanks for seeing that, though. -- Jorge Godoy <[EMAIL PROTECTED]> ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss