[web2py] Re: update_or_insert on an existing record returns None

2021-10-05 Thread Noobie
send code to analyze bro On Friday, September 24, 2021 at 2:48:44 PM UTC+5:30 Ramos wrote: > Why update_or_insert on an existing record returns None ?? > If the record does not exist it returns the created record id but if > updating an existing record i get None. > > Regards > António > -- Re

[web2py] Re: update_or_insert on an existing record returns None

2021-10-02 Thread Dave S
On Friday, September 24, 2021 at 2:18:44 AM UTC-7 Ramos wrote: > Why update_or_insert on an existing record returns None ?? > If the record does not exist it returns the created record id but if > updating an existing record i get None. > > Regards > António > Possibly so you can tell it was a

Re: [web2py] Re: update_or_insert doesn't always return the corresponding row id

2018-08-08 Thread 'Matthew J Watts' via web2py-users
Hi Manuele Thanks for your feedback, i've got it sorted now Anthony kindly helped me with the code. I'm still adding some things. But i'll upload the final code once i'm done! On Wed, Aug 8, 2018 at 9:46 AM, Manuele Pesenti wrote: > or just let you be inspired from the update_or_insert method i

Re: [web2py] Re: update_or_insert doesn't always return the corresponding row id

2018-08-08 Thread Manuele Pesenti
or just let you be inspired from the update_or_insert method itself: https://github.com/web2py/pydal/blob/70929a6dc03e6296c34944d2d232f257b78337d7/pydal/objects.py#L822 something like the following lines maybe will fit your needs: def update_or_insert(self, _key=DEFAULT, **values):     if _

[web2py] Re: update_or_insert doesn't always return the corresponding row id

2018-08-01 Thread Anthony
On Wednesday, August 1, 2018 at 6:46:09 AM UTC-4, Matthew J Watts wrote: > > Hi all > > I'm having the same problem, i'm trying to return an ID after an > 'update_or_insert', but I need the ID whether it inserts or updates to add > as a forign key to a related table. > Yes, the workaround is sim

[web2py] Re: update_or_insert doesn't always return the corresponding row id

2018-08-01 Thread 'Matthew J Watts' via web2py-users
Hi all I'm having the same problem, i'm trying to return an ID after an 'update_or_insert', but I need the ID whether it inserts or updates to add as a forign key to a related table. Does anyone have a work around, someone mentioned that you could just 'db(condition).select(table.id) after th

[web2py] Re: update_or_insert -- I end up with duplicates

2017-10-08 Thread pbreit
I'm surprised this would be a problem unless you have a very high traffic service or there's something else going on with your code. If it really is a problem, another option you could consider is a new column with enforced uniqueness that stores some sort of mashup of the two fields ( as simpl

[web2py] Re: update_or_insert -- I end up with duplicates

2017-10-04 Thread Anthony
update_or_insert first selects the record (if it exists) and then does the create/update. I suppose when two requests come in very close to each other, the second request is checking for the record before the first request has had a chance to commit the insert. I'm not sure I would call that a

Re: [web2py] Re: update_or_insert question...

2017-08-11 Thread António Ramos
I just failed my exam :) Thank you Anthony 2017-08-10 20:25 GMT+01:00 Anthony : > > > 2017-08-10 18:06 GMT+01:00 António Ramos : >> >>> better explanation >>> >>> first execution >>> id=db.entities.update_or_insert( ((db.entities.type==5) & >>> (db.entities.entity=="xaaa")),entity="xaaa",type=5)

[web2py] Re: update_or_insert question...

2017-08-10 Thread Anthony
2017-08-10 18:06 GMT+01:00 António Ramos : > >> better explanation >> >> first execution >> id=db.entities.update_or_insert( ((db.entities.type==5) & >> (db.entities.entity=="xaaa")),entity="xaaa",type=5) >> >> record inserted >> >> >> id=db.entities.update_or_insert( ((db.entities.type==5) &

[web2py] Re: update_or_insert question...

2017-08-10 Thread António Ramos
the tried again id=db.entities.update_or_insert( ((db.entities.type==5) & (db.entities.entity=="xaaa")),entity="othertext",type=5) and record inserted and not updated why? 2017-08-10 18:06 GMT+01:00 António Ramos : > better explanation > > first execution > id=db.entities.update_or_insert(

[web2py] Re: update_or_insert question...

2017-08-10 Thread António Ramos
better explanation first execution id=db.entities.update_or_insert( ((db.entities.type==5) & (db.entities.entity=="xaaa")),entity="xaaa",type=5) record inserted id=db.entities.update_or_insert( ((db.entities.type==5) & (db.entities.entity=="xaaa")),entity="othertext",type=5) No record inserted

[web2py] Re: update_or_insert from dictionary?

2017-07-07 Thread admin
I'll need to try this with a simpler table and dictionary next week. The table and dictionary I'm working with now has about 50 fields, and the insert and update methods are working fine with that. I wrapped it all in a try/except/else statement with db.rollback() and db.commit() to help with

[web2py] Re: update_or_insert from dictionary?

2017-07-07 Thread Anthony
On Friday, July 7, 2017 at 7:57:57 PM UTC-4, ad...@swcacloud.com wrote: > > Sorry about that, my code is in flux right now as I'm working through it. > > > Here are two methods that are working: > > db[table_name].insert(**r) > > db(db[table_name]._id == current_id).update(**r) > > > These methods

[web2py] Re: update_or_insert from dictionary?

2017-07-07 Thread admin
Sorry about that, my code is in flux right now as I'm working through it. Here are two methods that are working: db[table_name].insert(**r) db(db[table_name]._id == current_id).update(**r) These methods aren't working: db[table_name].update_or_insert(**r) db[table_name].update_or_insert(db[

[web2py] Re: update_or_insert from dictionary?

2017-07-07 Thread Anthony
Can't help if we don't see some code. On Friday, July 7, 2017 at 5:23:55 PM UTC-4, ad...@swcacloud.com wrote: > > Thanks for the quick reply. I'm not having any luck with > update_or_insert, but insert and update work fine individually. I'm using > keyed tables, so that may be why. > > > > On

[web2py] Re: update_or_insert from dictionary?

2017-07-07 Thread admin
Thanks for the quick reply. I'm not having any luck with update_or_insert, but insert and update work fine individually. I'm using keyed tables, so that may be why. On Friday, July 7, 2017 at 11:40:55 AM UTC-7, Anthony wrote: > > On Friday, July 7, 2017 at 2:27:52 PM UTC-4, ad...@swcacloud.c

[web2py] Re: update_or_insert from dictionary?

2017-07-07 Thread Anthony
On Friday, July 7, 2017 at 2:27:52 PM UTC-4, ad...@swcacloud.com wrote: > > > We can insert and update from a dictionary, but its not possible to do the > same with "update_or_insert"? Is there a simple way to achieve that, or > would it require changes to that dal function? > > > http://www.web

[web2py] Re: update_or_insert only returns id if created not updated

2017-04-19 Thread Anthony
On Wednesday, April 19, 2017 at 2:01:22 PM UTC-4, Paolo Valleri wrote: > Actually I don't know if pydal is supposed to be backward compatible. Yes, it is. It is part of web2py and makes the same promise of backward compatibility. Anthony -- Resources: - http://web2py.com - http://web2py.com/bo

[web2py] Re: update_or_insert only returns id if created not updated

2017-04-19 Thread Paolo Valleri
Actually I don't know if pydal is supposed to be backward compatible. On Wednesday, April 19, 2017 at 1:04:45 AM UTC+2, Anthony wrote: > > On Tuesday, April 18, 2017 at 3:33:31 PM UTC-4, Paolo Valleri wrote: >> >> It should work. Try to open an issue on https://github.com/web2py/pydal >> or a pul

[web2py] Re: update_or_insert only returns id if created not updated

2017-04-18 Thread Anthony
On Tuesday, April 18, 2017 at 3:33:31 PM UTC-4, Paolo Valleri wrote: > > It should work. Try to open an issue on https://github.com/web2py/pydal > or a pull request with the necessary change > it could be something like, > > new_id = record[self._id.name] > We can't do that, as it would break b

[web2py] Re: update_or_insert only returns id if created not updated

2017-04-18 Thread Paolo Valleri
It should work. Try to open an issue on https://github.com/web2py/pydal or a pull request with the necessary change it could be something like, new_id = record[self._id.name] Paolo On Tuesday, April 18, 2017 at 12:58:22 PM UTC+2, Ramos wrote: > > why? > > https://github.com/web2py/pydal/blob/

[web2py] Re: update_or_insert only returns id if created not updated

2017-04-18 Thread Anthony
I think the reason is so you can determine whether an insert was done or not (otherwise there would be no way to distinguish). Anyway, it's a fairly simple function, so if you need the id of updated records, just write your own version. Anthony On Tuesday, April 18, 2017 at 6:58:22 AM UTC-4, R

Re: [web2py] Re: update_or_insert does not return id of record ?!

2016-10-26 Thread Anthony
On Wednesday, October 26, 2016 at 4:07:45 AM UTC-4, Ramos wrote: > > but there were no record to update. it should have created a record. > as i said i created a rruid field in an existing table and the first time > i run the update_or_insert the rruid field of all the records were empty. > Here'

Re: [web2py] Re: update_or_insert does not return id of record ?!

2016-10-26 Thread António Ramos
but there were no record to update. it should have created a record. as i said i created a rruid field in an existing table and the first time i run the update_or_insert the rruid field of all the records were empty. Anyway i solved without update_or_insert... 2016-10-26 5:23 GMT+01:00 Anthony :

Re: [web2py] Re: update_or_insert does not return id of record ?!

2016-10-25 Thread Anthony
On Tuesday, October 25, 2016 at 5:12:39 PM UTC-4, Ramos wrote: > > Yes i added a new field to an existing table. > So all of them became empty in that field. > i then executed > than i have another app that calls a controller in this app and passes > some data in request.vars > the controller in

Re: [web2py] Re: update_or_insert does not return id of record ?!

2016-10-25 Thread António Ramos
Yes i added a new field to an existing table. So all of them became empty in that field. i then executed than i have another app that calls a controller in this app and passes some data in request.vars the controller in this app then does this id=db.empresa.update_or_insert(db.empresa.ruuid==reques

Re: [web2py] Re: update_or_insert does not return id of record ?!

2016-10-25 Thread Dave S
On Tuesday, October 25, 2016 at 2:27:35 AM UTC-7, Ramos wrote: > > Strange thing happened > > I created another field called ruuid in table empresa then this code: > > uuid=request.vars.uuid > entity=request.vars.entity > > id=db.empresa.update_or_insert(db.empresa.ruuid==request.vars.ruuid,empre

Re: [web2py] Re: update_or_insert does not return id of record ?!

2016-10-25 Thread António Ramos
Strange thing happened I created another field called ruuid in table empresa then this code: uuid=request.vars.uuid entity=request.vars.entity id=db.empresa.update_or_insert(db.empresa.ruuid==request.vars.ruuid,empresa=entity,tipo='tr',ruuid=request.vars.uuid) instead of creating another record

[web2py] Re: update_or_insert does not return id of record ?!

2016-10-24 Thread Anthony
It returns the id if a record is inserted, but not if updated (this allows you to distinguish between the two cases). Anthony On Monday, October 24, 2016 at 9:05:56 AM UTC-4, Ramos wrote: > > hello i noticed that > db.mytable.update_or_insert(...) > does not return the id of the record updated

[web2py] Re: update_or_insert and keyed tables

2016-10-11 Thread Massimo Di Pierro
please open a github issue to pydal. This is an easy fix. On Thursday, 6 October 2016 06:10:37 UTC-5, Val K wrote: > > it seems, that *update_or_insert* doesn't work with keyed tables, > because it uses *update_record* method ... It's a pity. > > -- Resources: - http://web2py.com - http://web

[web2py] Re: update_or_insert and composite key

2016-07-11 Thread Anthony
If you submit an issue, be sure to submit it on the pydal repository, not the web2py framework repository. On Monday, July 11, 2016 at 9:02:02 AM UTC-4, Anthony wrote: > > As noted in the documentation >

[web2py] Re: update_or_insert and composite key

2016-07-11 Thread Anthony
As noted in the documentation , the .update_record method is not available on rows of keyed tables, so you will therefore also not be able to use the built-in .update_or_insert metho

[web2py] Re: update_or_insert

2016-05-02 Thread Limedrop
It looks like update_or_insert() will always do two database hits and, as you say, even then doesn't give you the id of the existing record. It goes something like this (pseudo code for clarity): record = db.table.select() if record: update_record() else: insert record() So it's a simpl

[web2py] Re: update_or_insert - Calculation when updating

2015-11-22 Thread RedBeard
Thank you very much for the clear answer Anthony - I am just working my way though it! On Tuesday, 17 November 2015 16:45:42 UTC, Anthony wrote: > > def index(): >> form = SQLFORM(db.tr_items) >> if form.process().accepted: >> item_in_out = form.vars.item >> amount_in_out

[web2py] Re: update_or_insert - Calculation when updating

2015-11-18 Thread Dave S
On Tuesday, November 17, 2015 at 8:02:25 AM UTC-8, Anthony wrote: > Python does allow increment assignments, though it is "+=" rather than > "=+". > YRDLSH > Perhaps you meant that it cannot be used when passing function arguments, > as in this case (i.e., you can't do myfunc(arg+=some_

[web2py] Re: update_or_insert - Calculation when updating

2015-11-17 Thread Anthony
> > def index(): > form = SQLFORM(db.tr_items) > if form.process().accepted: > item_in_out = form.vars.item > amount_in_out = form.vars.amount > row = db.products_summary(product=item_in_out) > if row==None: > db.products_summary.insert(product=i

[web2py] Re: update_or_insert - Calculation when updating

2015-11-17 Thread Anthony
> Error message #3 >> >> No error message - this overwrites cumulative amount to the amount >> entered by the user, no memory. >> > > Python doesn't have the increment assignment operator, so number 3 is > being taken as > > cumulative_amount = NULL + form.vars.amount > > Python does allow incr

[web2py] Re: update_or_insert - Calculation when updating

2015-11-17 Thread RedBeard
I think I have it: Do you think this is the best way of doing this?? Many thanks again!! Controller: def index(): form = SQLFORM(db.tr_items) if form.process().accepted: item_in_out = form.vars.item amount_in_out = form.vars.amount row = db.products_summary(produ

[web2py] Re: update_or_insert - Calculation when updating

2015-11-17 Thread RedBeard
Hey dps, Thanks for your reply. It is definitely getting closer, you're right, the reference was a good idea, I hadn't put it in because if a tr_items, item doesn't exist in product I wanted it to be added. I now have: Model: db.define_table('products_summary', Field('product

[web2py] Re: update_or_insert - Calculation when updating

2015-11-16 Thread Dave S
On Sunday, November 15, 2015 at 11:58:01 AM UTC-8, RedBeard wrote: > > Hi, > > Hi. See below (inline) > I have only just started learning python and web2py so please bear with me. > > When a user inserts an item and amount in tr_items, I am trying to have > the system check whether the item

[web2py] Re: update_or_insert error

2014-12-02 Thread T.R.Rajkumar
Thanks Niphlod, I did as you said and it is working nicely. Thank you once again for pointing the mistake. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --

[web2py] Re: update_or_insert error

2014-12-02 Thread Niphlod
On Tuesday, December 2, 2014 6:19:23 PM UTC+1, Nico de Groot wrote: > > The function _update_or_insert(... returns the sql that is generated. @nico: unfortunately there isn't (it's a two-step phase that isn't resolved to a single SQL statement) however, it made me spot the actual error in th

[web2py] Re: update_or_insert error

2014-12-02 Thread Nico de Groot
The function _update_or_insert(... returns the sql that is generated. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because yo

[web2py] Re: update_or_insert error

2014-12-01 Thread T.R.Rajkumar
In the error page I find the following in the arguments. *File F:\trr\web2py\web2py\gluon\dal.py in update_or_insert at line 9380* code arguments variables Function argument list (self=, _key=, **values={'agt_no': '10001', 'jcod': 'TR001', 'line_no': 1, 'loc_of_work': 'test', 'm_breadth': '

[web2py] Re: update_or_insert

2014-11-03 Thread Anthony
On Saturday, November 1, 2014 3:31:38 PM UTC-4, Luis Ramos wrote: > > Anthony, thanks for your response, the only inconvenience that I see is > that the 'update_date' Field will be updated if there's a change in the > whole Row, instead of a particular Cell. How can we specify to update if a > p

[web2py] Re: update_or_insert

2014-11-03 Thread Dave S
On Saturday, November 1, 2014 12:31:38 PM UTC-7, Luis Ramos wrote: > > Anthony, thanks for your response, the only inconvenience that I see is > that the 'update_date' Field will be updated if there's a change in the > whole Row, instead of a particular Cell. How can we specify to update if a

[web2py] Re: update_or_insert

2014-11-01 Thread Luis Ramos
Anthony, thanks for your response, the only inconvenience that I see is that the 'update_date' Field will be updated if there's a change in the whole Row, instead of a particular Cell. How can we specify to update if a particular Cell changed? On Friday, October 31, 2014 10:24:15 PM UTC-4, Anth

[web2py] Re: update_or_insert

2014-10-31 Thread Anthony
Does this work: db.define_table('dogs', ..., Field('creation_date', 'datetime', default=now), Field('update_date', 'datetime', default=None, update=now)) Then in your update_or_insert, don't explicitly specify either of those fields and let the default/update attr

[web2py] Re: update_or_insert - handling record created/modified timestamps

2014-07-15 Thread Massimo Di Pierro
Just put request.now = request.utcnow before you define your models (including auth). On Tuesday, 15 July 2014 04:32:57 UTC-5, Leonel Câmara wrote: > > If you use auth.signature pay attention that it uses request.now as the > default for the timestamps which uses the timezone of wherever

[web2py] Re: update_or_insert - handling record created/modified timestamps

2014-07-15 Thread Leonel Câmara
If you use auth.signature pay attention that it uses request.now as the default for the timestamps which uses the timezone of wherever it is running. In my opinion time should always saved in the DB in UTC for sanity's sake and future proofing. Seriously request.now is retarded. -- Resources:

[web2py] Re: update_or_insert - handling record created/modified timestamps

2014-07-12 Thread Massimo Di Pierro
Mind web2py offers all of this out of the box: db.define_table('stuff',Field('name'), auth.signature) auth.signature adds created_on, created_by, modified_on, modified_by and is_active. These fields can be used by auth for full auditing if enabled by auth.enable_record_versioning(db) Any

[web2py] Re: update_or_insert with Expressions

2013-08-30 Thread Massimo Di Pierro
This is not supported. Please open a ticket. We can this feature On Friday, 30 August 2013 07:11:29 UTC-5, frasse wrote: > > Hi > I like to use following update_or_insert example with > "db.myproperty.quantity > + 1" as you see in example > > db.myproperty.update_or_insert( > (db.myp

[web2py] Re: update_or_insert doesn't always return the corresponding row id

2013-05-21 Thread Anthony
.update_or_insert() does in fact do an initial query to retrieve the first record that matches, so presumably it could just return the id of that record rather than returning None. The problem, though, is that you would then have no way of knowing whether it had done an update or an insert. A b

[web2py] Re: update_or_insert doesn't always return the corresponding row id

2013-05-21 Thread Robin Manoli
I mean before doing the update, how does web2py know if there is a record to update? I mean to get the id from there. Den tisdagen den 21:e maj 2013 kl. 17:04:40 UTC+2 skrev Niphlod: > > > > Il giorno martedì 21 maggio 2013 16:42:46 UTC+2, Robin Manoli ha scritto: >> >> is it really another query

[web2py] Re: update_or_insert doesn't always return the corresponding row id

2013-05-21 Thread Niphlod
Il giorno martedì 21 maggio 2013 16:42:46 UTC+2, Robin Manoli ha scritto: > > is it really another query? isn't there already a query to see if there is > a post to update? come up with a SQL syntax that returns the PK of updated records and we'll try it. I'm pretty sure there isn't any but I

[web2py] Re: update_or_insert doesn't always return the corresponding row id

2013-05-21 Thread Robin Manoli
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 i

[web2py] Re: .update_or_insert not optimized!!

2013-01-29 Thread Christian Espinoza
Hi all, I'm wondering about if .update_or_insert was enhanced or not yet? Thanks in advance. Christian. El jueves, 3 de mayo de 2012 09:46:46 UTC-4, Anthony escribió: > > You're manual version updates only two fields, whereas update_or_insert >>> updates six fields -- maybe that's the difference

[web2py] Re: update_or_insert doesn't always return the corresponding row id

2012-10-23 Thread Adi
that's how i do it now... just thought I could save that trip in case update ids were known :) thanks for responding Niphlod. On Tuesday, October 23, 2012 4:25:38 AM UTC-4, Niphlod wrote: > > that would require another query (no thanks!). No database on an update > gives you back the ids of the

[web2py] Re: update_or_insert doesn't always return the corresponding row id

2012-10-23 Thread 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 2

[web2py] Re: update_or_insert doesn't always return the corresponding row id

2012-10-22 Thread Adi
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, 201

Re: [web2py] Re: `update_or_insert()` is always inserting?

2012-07-31 Thread Alec Taylor
Thanks, that did the trick. On Wed, Aug 1, 2012 at 1:21 AM, Cliff Kachinske wrote: > You need the other form of update_or_insert:. This is covered in the > manual. I always encourage people to Read The Fine Manual (RTFM) to gain a > good understanding what's going on. > > > db.person.update_or

[web2py] Re: `update_or_insert()` is always inserting?

2012-07-31 Thread Massimo Di Pierro
What you have is correct in the sense that you want to do something that update_or_insert cannot do. As I look at it I realize update_or_insert is a little useless as implemented. I just changed it in trunk. Get the latest trunk and try this: db.foo.update_or_insert({'user_id':1},haz='a') thi

[web2py] Re: `update_or_insert()` is always inserting?

2012-07-31 Thread Cliff Kachinske
You need the other form of update_or_insert:. This is covered in the manual. I always encourage people to Read The Fine Manual (RTFM) to gain a good understanding what's going on. db.person.update_or_insert(db.person.name=='John', name='John',birthplace='Chicago') or db.foo.update_or_inse

[web2py] Re: .update_or_insert not optimized!!

2012-05-03 Thread Anthony
> > You're manual version updates only two fields, whereas update_or_insert >> updates six fields -- maybe that's the difference. >> >> Anthony >> > > Yes, but I want to insert a new record with six fields, but update only > two if the record exists. How to do that with .update_or_insert? > Lo

[web2py] Re: .update_or_insert not optimized!!

2012-05-03 Thread puercoespin
> You're manual version updates only two fields, whereas update_or_insert > updates six fields -- maybe that's the difference. > > Anthony > Yes, but I want to insert a new record with six fields, but update only two if the record exists. How to do that with .update_or_insert?

[web2py] Re: .update_or_insert not optimized!!

2012-05-02 Thread Anthony
> > if row: > > row.update_record(Precio=float(Precio),Fecha_Actualizacion=Fecha_Actualizacion) > > > db.G95.update_or_insert(db.G95.LongitudLatitud==LongitudLatitud, > LongitudLatitud=LongitudLatitud,Latitud=float(Latitud),Longitu