RE: [PHP-ES] Transacciones OT: MSSQL
| From: | Eduardo Daniel Pizzi | Date: | Fri, 31 Oct 2003 14:28:45 +0000 |
| Subject: | RE: [PHP-ES] Transacciones OT: MSSQL | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-42124@lists.php.net to get a copy of this message | ||
Esta un poco desbolado pero ya me voy. Por ahi te da una idea...
No lo use en PHP pero...
BEGIN TRANSACTION
insert...
update...
update...
update...
delete...
IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
END
ELSE
BEGIN
COMMIT TRANSACTION
END
GO
!-------------------------------------------------------
En este ejemplo le agrego @@ROWCOUNT por si me da error en algun where.
Error porque no existe un registro...
Por ahi te aporta algo mas.
!-------------------------------------------------------
Ejemplo ultimo
declare
@SQL as varchar(255),
@EXPEDIENTE as int,
@NOMANALISTA as varchar(20),
@AREA as int,
@GRUPO as varchar(20),
@HORAENT as datetime,
@Upd1 AS INT,
@Ups2 AS INT
set @EXPEDIENTE = 6674
set @NOMANALISTA = 'BONOMO'
set @AREA = 2
set @GRUPO = 'GERENTE'
BEGIN TRANSACTION
/* 2) Asigno al expediente el nuevo user actual a quien girar. */
/* (Si es al ANALISTA: ) */
Update expedien set useractual=@NOMANALISTA, areactual=@AREA,
groupactual=@GRUPO Where numero=@EXPEDIENTE
SELECT @Upd1 = @@ROWCOUNT
/* 4) Arreglo la SALIDA (anteúltimo registro) */
Declare @fecha as DateTime
SET @fecha = (Select top 1 HORAENT from movement where numero= @EXPEDIENTE
and ultimo=2 order by fecent desc)
SET @HORAENT = (Select Convert(datetime,@fecha,121))
Update movement set usersal=@NOMANALISTA, gruposal=@GRUPO, areasal=@AREA
Where HORAENT=@HORAENT and numero=@EXPEDIENTE
SELECT @Upd2 = @@ROWCOUNT
/* 5) Arreglo la ENTRADA (último registro) */
Update movement set userent=@NOMANALISTA, grupoent=@GRUPO, areasal=@AREA
Where ultimo=1 and numero=@EXPEDIENTE
IF @@ROWCOUNT = 0 OR @upd1 = 0 OR @Upd2 = 0 or @@ERROR<>0
-- IF @@ERROR<>0 /* Sobre rangos y codigo */
-- IF @@ROWCOUNT = 0 /* SerÃa del ultimo solamente */
ROLLBACK TRANSACTION
ELSE
COMMIT TRANSACTION
!-------------------------------------------------------
-=<< Eduardo Daniel Pizzi >>=-
Postal: Parque Leloir - Castelar - Bs.As. - Argentina.
Mail: sistemas@DesarrollosInteractivos.com -
http://www.DesarrollosInteractivos.com