Hi all
Can you please let me know what is the difference between "for update' and "selectforupdate" ?.
Please give me more shed on this.
Thanks!
*This post is locked for comments
Hi all
Can you please let me know what is the difference between "for update' and "selectforupdate" ?.
Please give me more shed on this.
Thanks!
*This post is locked for comments
No, you still didn't get that selectForUpdate() says whether the record should be selected from database for update, therefore it must be called before the select. This makes a hige difference in case of pessimistic locking. And if you want to set a value, you must provide one (e.g. use selectForUpdate(true) instead of just selectForUpdate()).
You also didn't get my point about find(). find() methods have a parameter which is passed to selectForUpdate() before select, therefore you should call something like Table1::find("id1", true) if you want to select a record for update. Calling selectForUpdate() after that has absolutely no effect whatsoever.
There is no specific criteria, usually when we select buffer using find method then we do
table. selectForupdate();
e.g.
table1 = Table1::find();
table1.selectforupdate();
if you wrote simple select statement then you can do it as combined statement
select forupdate table1
look at this similar thread
Thanks Martin
You can mark a buffer for update and then do a select:
myTable.selectForUpdate(true); select myTable;
Or you can combine the same thing into a single statement:
select forUpdate myTable;
We usually use the shorter variant, but sometimes you need something else, e.g. if you want to select for update conditionally:
myTable.selectForUpdate(_update); select myTable;
You can see the last case in find() methods, for instance.
No Sukrut
I am not telling that I want to use both statement in one statement.
I know both are different statements and we can use it only 1at a time.
My question is when to select which statement ? Is there any specific criteria?
Please give me more shed on this.
Thanks!
If you specify while select forupdate then you don't have to specify again in the loop like table.selectForupdate() as you are already selecting it forupdate in a while statement.
Thanks Hossein
You mentioned the difference between update() and do update () but I wants to know the exact difference between
while select forupdate <Table name>
where condition...
{
<Table.update() OR Table.doUpdate();>
}
And
table.selectforupdate(true);
Is't both are same statement?
Please give me more shed on this.
Thanks!
Hi,
In update() values stored in buffer then update the record with reference to RecID & doupdate() can directly update the record with out cheking the condisions and all.
if we want to select particular record with some conditons....then we use update() method.but In some situation we didn't need to chek the condition,in that situation we use DoUpdate().
In fact,
The doUpdate table method updates the current record with the contents of the buffer. This method also updates the appropriate system fields.
The doUpdate method should be used when the update method on the table is to be bypassed. Suppose you have overridden the update method of the table but sometime there is a situation when you don't want the code written in the overridden update method to be executed and at the same time want any selected record of that table to be updated. In such situation you should call the table.doupdate() method instead of table.update() method.
Thanks Hossein
My question is
1. ttsbegin;
while select forupdate <Table name>
where condition...
{
<Table.update() OR Table.doUpdate();>
}
ttscommit;
2. table.selectforupdate(true)
Both are same ?
please give me more shed on this.
Thanks!
Hi,
You can use SQL statements, either interactively or within source code, to access and retrieve data that is stored in the database. You use the following statements for data manipulation:
select – Select the data to modify.
insert – Add one or more new records to a table.
update – Modify data in existing table records.
delete – Remove existing records from a table.
Before any data can be changed, you must use a select statement to select the data to update. The select forUpdate command selects records for update only. The insert, update, and delete statements perform operations on one record at a time. The array insert, insert_recordset, RecordInsertList, and update_recordset statements perform operations on multiple records at the same time.
Regards Hossein
André Arnaud de Cal...
292,516
Super User 2025 Season 1
Martin Dráb
231,409
Most Valuable Professional
nmaenpaa
101,156