交易的方式是正确的吗?

时间:2018-06-05 14:36:28

标签: mysql

确保没有人可以在运行时修改表格,并且您无法为现有日期添加新配额。

 delimiter $$
    create procedure QUOTA_DATES(in v_dateEntrada date, in v_dateSalida date, in v_rooms int, in v_price decimal(8,2), in v_hotel int(1))
BEGIN

    DECLARE v_fecha date;

    set v_fecha = v_dateEntrada;

    start transaction;
    select * from QUOTA for update;
    l_datos : loop

        if ((select COUNT(*) from QUOTA WHERE DATE = v_fecha AND ROOMS = v_rooms 
                AND PRICE = v_price AND  HOTEL = v_hotel) = 0 ) THEN

        INSERT INTO QUOTA(DATE, ROOMS, PRICE, HOTEL) VALUES(v_fecha, v_rooms, v_price, v_hotel);

        set v_fecha = adddate(v_fecha, interval 1 day);

        ELSE 

            SELECT concat('ERROR') AS ERROR;
            rollback;
            leave l_datos;

        END IF;



        if (v_fecha =  v_dateSalida) then
            COMMIT;
            leave l_datos;
        end if;

    end loop l_datos;


END;
$$

delimiter ;

0 个答案:

没有答案