Subject Re: Atomic Execution
Author Alexander V.Nevsky
--- In firebird-support@yahoogroups.com, Juan Pedro López Sáez
<jpls@a...> wrote:
> Hello all,
>
> Is this SQL statement atomically executed?
>
> IF (EXISTS (SELECT C_STATE
> FROM SETUP_PUSH_PROMOTION
> WHERE ((K_PROMOTION =:PROMOTION)
> AND (C_STATE = 'PENDIENTE'))
> )
> )
> THEN UPDATE PROMOTIONS SET C_STATE = 'ACTIVO'
> WHERE K_PROMOTION = :PROMOTION;
> ELSE UPDATE PROMOTIONS SET C_STATE = 'INACTIVO'
> WHERE K_PROMOTION = :PROMOTION;
>
> It will be part of a Stored Procedure, but I suppose this has
nothing to
> do with atomic execution.
>
> Is there any rule to know whether a SQL statement is atomic or not?
>

Juan, firstly this is not SQL statement but PSQL statement
constructed from three SQL statements - Select and two Updates.
Secondly, what do you mean "atomic"? SQL statements are atomic in the
sense they are entirely successfull or entirely not. If condition of
update statement cause update of 2 records and updating one server
will encounter exception, no one record will be updated. In this sense
entirely SP execution is atomic too since call is SQL statement - in
case of any exception all changes made by SP will be undone (if there
is not explicit exceptions handling code within this SP). If you mean
- will result of Select is still valid when you perform Update - no,
data can be changed between this statements execution.

Best regards,
Alexander.