Official Content

While the Save method takes into account the current mode of the variable based on the business component to which it is applied, the Insert and Update methods don't take it into account to determine if an addition or an update has to be performed in the database. The Insert and Update methods directly perform the operations indicated by their names.

In addition, the Update method does not require the use of the Load method, as opposed to the Save method when it is used to update the database. This is advantageous because the Load method produces an access to the database and it can be avoided.

So, the first code is more performant than the second, even though the result of both of them is the same:

1) 

&Customer=new()   //in this case the new operator can be omitted, but if several customers are updated, it must be used
&Customer.CustomerId = 8    
&Customer.CustomerEmail = !'marybrown@gmail.com'
If &Customer.Update()
   commit
else
   rollback
endif   

 

2) 

&Customer.Load(8)
&Customer.CustomerEmail = !'marybrown@gmail.com'
&Customer.Save()
if &Customer.Success()
  commit
else
  rollback
endif

 

Note: If the above codes are inside a loop, by using the Load() method, you don't need to use the New operator (because the variable is reloaded every time regardless if you are using the Save or the Update method). On the other hand, if you decide to assign the primary key attribute(s) value(s), you have to precede that assignment with the New operator.




Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant