 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Alessandro Guest
|
Posted: Mon Mar 28, 2005 12:02 pm Post subject: OnUpdateData datasetprovider |
|
|
Hi.
I use Delphi 7 / DataSnap / SocketdConnection / MS SQL 2000 / Corelabs
dbExpress driver
I try put all bussiness logic in my midle tier.
I have a case, that i have verify a value field in a table before update.
Depending on the value i update data or return message erro to user.
I do this in onUpdateData evento because all execute in this event is sent
to database in one transaction.
the code is:
------
SQLDataSet1.CommandText := 'select STATUS from Req where Req.Number =
'+DataSet.FieldByName('Number').AsString;
SQLDataSet1.Open;
if SQLDataSet1.FieldByName('STATUS').AsString = 'R' then (***)
raise Exceptiopn.create('message erro')
---- end event
MY QUESTION IS: AS I GUARANTEE THAT BETWEEN CHECK THE VALUE AND THE COMAND
IS EXECUTE IN DATABASE OTHER USER DONT CHANGE THIS FIELD?
Thanks
Alessandro
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Mon Mar 28, 2005 4:59 pm Post subject: Re: OnUpdateData datasetprovider |
|
|
Alessandro wrote:
| Quote: | the code is:
SQLDataSet1.CommandText := 'select STATUS from Req where Req.Number =
'+DataSet.FieldByName('Number').AsString;
SQLDataSet1.Open;
if SQLDataSet1.FieldByName('STATUS').AsString = 'R' then (***)
raise Exceptiopn.create('message erro')
MY QUESTION IS: AS I GUARANTEE THAT BETWEEN CHECK THE VALUE AND THE
COMAND IS EXECUTE IN DATABASE OTHER USER DONT CHANGE THIS FIELD?
|
Do you mean in the case where Status is not 'R' and you proceed with the
update? If so, then no there is no guarantee - another user could indeed
update that record between your Select and Update statements - unless you
place a lock on that record as part of the Select statement.
If the status is the only value that needs to be checked to allow the update
then you could change the logic to simply go ahead with the update and
include that check in the Where clause:
Update Req set
<field assignments>
where Req.Number = <value>
and Status <> 'R'
After executing this update, check the RowsAffected property of the dataset,
if not 1 then someone else has updated that record and your update failed.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"The purpose of morality is to teach you, not to suffer and die, but to
enjoy yourself and live." - Ayn Rand
|
|
| Back to top |
|
 |
Charles Adriano - Brazil Guest
|
Posted: Mon Mar 28, 2005 11:23 pm Post subject: Re: OnUpdateData datasetprovider |
|
|
hi alessandro
i think, the best way, do you create a sotored procedure in then SQL server
and
execute your bussiness logic... (start transaction, update and commit) ...
for the simple fact of everything to be done in the server...
and stored procedure will be return a status value for you... (in case of
error message)
charles...
PD1 : sorry for my english...
PD2 : i recommend
Microsoft SQL Server 2000 DBA Survival Guide
Mark Spenik and Orryn Sledge
"Alessandro" <alessandrocamara (AT) hotmail (DOT) com> escribió en el mensaje
news:4247f0dc (AT) newsgroups (DOT) borland.com...
| Quote: | Hi.
I use Delphi 7 / DataSnap / SocketdConnection / MS SQL 2000 / Corelabs
dbExpress driver
I try put all bussiness logic in my midle tier.
I have a case, that i have verify a value field in a table before update.
Depending on the value i update data or return message erro to user.
I do this in onUpdateData evento because all execute in this event is sent
to database in one transaction.
the code is:
------
SQLDataSet1.CommandText := 'select STATUS from Req where Req.Number =
'+DataSet.FieldByName('Number').AsString;
SQLDataSet1.Open;
if SQLDataSet1.FieldByName('STATUS').AsString = 'R' then (***)
raise Exceptiopn.create('message erro')
---- end event
MY QUESTION IS: AS I GUARANTEE THAT BETWEEN CHECK THE VALUE AND THE COMAND
IS EXECUTE IN DATABASE OTHER USER DONT CHANGE THIS FIELD?
Thanks
Alessandro
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|