is it really another query? isn't there already a query to see if there is a post to update?
it's quite strange that an id is only returned if a new row is inserted, it is not very logical. even if this function is not to be changed, how about the possibility to add, when you really need the id: db.update_or_insert(condition, values).id()? Den tisdagen den 23:e oktober 2012 kl. 10:25:38 UTC+2 skrev Niphlod: > > that would require another query (no thanks!). No database on an update > gives you back the ids of the records you updated, just the number of rows. > > Suppose you did db.update_or_insert(condition, values) > > If you are in the need just db(condition).select(table.id) after that. > > On Tuesday, October 23, 2012 3:15:44 AM UTC+2, Adi wrote: >> >> Stumbled upon the same thing. >> >> Understood that possibly results could have more ids when key is >> different from primary key, e.g (name=='john'), but would it be possible to >> return an additional parameter with update id(s), if they are known? >> >> return newid, updateids >> >> >> On Friday, December 30, 2011 12:31:37 PM UTC-5, olivier wrote: >>> >>> The "insert" method returns the id of the inserted row. >>> The "update_or_insert" method returns the id of the inserted row, but >>> returns None in case of an update... >>> >>> Why is it so? >>> >>> I have a case in which I want to update_or_insert and then further >>> update the corresponding row (to track the status of a long running >>> process). >>> I would rather have the method to always output the id of the updated/ >>> inserted row... >>> Or is there any use-case you would like to discriminate between the >>> fact you inserted or update a row? >>> >>> What do you think? >>> >>> -Olivier >>> >>> >>> From dal.py (I added the proposed modification) >>> =========== >>> >>> def update_or_insert(self, key=DEFAULT, **values): >>> if key==DEFAULT: >>> record = self(**values) >>> else: >>> record = self(key) >>> if record: >>> record.update_record(**values) >>> newid = None #------> why not record['id'] ???? >>> else: >>> newid = self.insert(**values) >>> return newid >> >> -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

